|
12 | 12 | */ |
13 | 13 | package com.ibm.watson.personality_insights.v3; |
14 | 14 |
|
15 | | -import com.ibm.cloud.sdk.core.http.HttpHeaders; |
16 | | -import com.ibm.cloud.sdk.core.http.HttpMediaType; |
17 | 15 | import com.ibm.cloud.sdk.core.http.RequestBuilder; |
18 | 16 | import com.ibm.cloud.sdk.core.http.ServiceCall; |
19 | 17 | import com.ibm.cloud.sdk.core.service.BaseService; |
20 | 18 | import com.ibm.cloud.sdk.core.service.security.IamOptions; |
| 19 | +import com.ibm.cloud.sdk.core.util.GsonSingleton; |
21 | 20 | import com.ibm.cloud.sdk.core.util.ResponseConverterUtils; |
| 21 | +import com.ibm.cloud.sdk.core.util.Validator; |
| 22 | +import com.ibm.watson.common.SdkCommon; |
22 | 23 | import com.ibm.watson.personality_insights.v3.model.Profile; |
23 | 24 | import com.ibm.watson.personality_insights.v3.model.ProfileOptions; |
24 | | -import com.ibm.cloud.sdk.core.util.Validator; |
25 | | - |
26 | 25 | import java.io.InputStream; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.Map.Entry; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * The IBM Watson™ Personality Insights service enables applications to derive insights from social media, |
@@ -141,20 +142,26 @@ public ServiceCall<Profile> profile(ProfileOptions profileOptions) { |
141 | 142 | String[] pathSegments = { "v3/profile" }; |
142 | 143 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); |
143 | 144 | builder.query("version", versionDate); |
144 | | - builder.header("X-IBMCloud-SDK-Analytics", |
145 | | - "service_name=personality_insights;service_version=v3;operation_id=profile"); |
146 | | - if (profileOptions.contentType() != null) { |
147 | | - builder.header("Content-Type", profileOptions.contentType()); |
| 145 | + Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("personality_insights", "v3", "profile"); |
| 146 | + for (Entry<String, String> header : sdkHeaders.entrySet()) { |
| 147 | + builder.header(header.getKey(), header.getValue()); |
148 | 148 | } |
| 149 | + builder.header("Accept", "application/json"); |
149 | 150 | if (profileOptions.contentLanguage() != null) { |
150 | 151 | builder.header("Content-Language", profileOptions.contentLanguage()); |
151 | 152 | } |
152 | 153 | if (profileOptions.acceptLanguage() != null) { |
153 | 154 | builder.header("Accept-Language", profileOptions.acceptLanguage()); |
154 | 155 | } |
| 156 | + if (profileOptions.contentType() != null) { |
| 157 | + builder.header("Content-Type", profileOptions.contentType()); |
| 158 | + } |
155 | 159 | if (profileOptions.rawScores() != null) { |
156 | 160 | builder.query("raw_scores", String.valueOf(profileOptions.rawScores())); |
157 | 161 | } |
| 162 | + if (profileOptions.csvHeaders() != null) { |
| 163 | + builder.query("csv_headers", String.valueOf(profileOptions.csvHeaders())); |
| 164 | + } |
158 | 165 | if (profileOptions.consumptionPreferences() != null) { |
159 | 166 | builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences())); |
160 | 167 | } |
@@ -198,35 +205,36 @@ public ServiceCall<Profile> profile(ProfileOptions profileOptions) { |
198 | 205 | * * [Understanding a CSV profile](https://cloud.ibm.com/docs/services/personality-insights/output-csv.html). |
199 | 206 | * |
200 | 207 | * @param profileOptions the {@link ProfileOptions} containing the options for the call |
201 | | - * @param includeHeaders the boolean saying whether or not to include headers in the response |
202 | 208 | * @return a {@link ServiceCall} with a response type of {@link InputStream} |
203 | 209 | */ |
204 | | - public ServiceCall<InputStream> profileAsCsv(ProfileOptions profileOptions, boolean includeHeaders) { |
| 210 | + public ServiceCall<InputStream> profileAsCsv(ProfileOptions profileOptions) { |
205 | 211 | Validator.notNull(profileOptions, "profileOptions cannot be null"); |
206 | 212 | String[] pathSegments = { "v3/profile" }; |
207 | 213 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); |
208 | 214 | builder.query("version", versionDate); |
209 | | - builder.header("X-IBMCloud-SDK-Analytics", |
210 | | - "service_name=personality_insights;service_version=v3;operation_id=profileAsCsv"); |
211 | | - if (profileOptions.contentType() != null) { |
212 | | - builder.header("Content-Type", profileOptions.contentType()); |
| 215 | + Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("personality_insights", "v3", "profileAsCsv"); |
| 216 | + for (Entry<String, String> header : sdkHeaders.entrySet()) { |
| 217 | + builder.header(header.getKey(), header.getValue()); |
213 | 218 | } |
| 219 | + builder.header("Accept", "text/csv"); |
214 | 220 | if (profileOptions.contentLanguage() != null) { |
215 | 221 | builder.header("Content-Language", profileOptions.contentLanguage()); |
216 | 222 | } |
217 | 223 | if (profileOptions.acceptLanguage() != null) { |
218 | 224 | builder.header("Accept-Language", profileOptions.acceptLanguage()); |
219 | 225 | } |
| 226 | + if (profileOptions.contentType() != null) { |
| 227 | + builder.header("Content-Type", profileOptions.contentType()); |
| 228 | + } |
220 | 229 | if (profileOptions.rawScores() != null) { |
221 | 230 | builder.query("raw_scores", String.valueOf(profileOptions.rawScores())); |
222 | 231 | } |
| 232 | + if (profileOptions.csvHeaders() != null) { |
| 233 | + builder.query("csv_headers", String.valueOf(profileOptions.csvHeaders())); |
| 234 | + } |
223 | 235 | if (profileOptions.consumptionPreferences() != null) { |
224 | 236 | builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences())); |
225 | 237 | } |
226 | | - |
227 | | - builder.header(HttpHeaders.ACCEPT, HttpMediaType.TEXT_CSV); |
228 | | - builder.query("csv_headers", includeHeaders); |
229 | | - |
230 | 238 | builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body()); |
231 | 239 | return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream()); |
232 | 240 | } |
|
0 commit comments