GeezerVison is showing github.com — refactor(core): Change constructHttpUrl methods to accept String arra… · windofthesky/java-sdk@ea69211
File treeExpand file treeCollapse file tree Open diff view settings conversation/src/main/java/com/ibm/watson/developer_cloud/conversation/v1 core/src/main/java/com/ibm/watson/developer_cloud/http discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1 language-translator/src/main/java/com/ibm/watson/developer_cloud/language_translator/v2 natural-language-classifier/src/main/java/com/ibm/watson/developer_cloud/natural_language_classifier/v1 natural-language-understanding/src/main/java/com/ibm/watson/developer_cloud/natural_language_understanding/v1 personality-insights/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v3 speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1 text-to-speech/src/main/java/com/ibm/watson/developer_cloud/text_to_speech/v1 tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3 visual-recognition/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: conversation/src/main/java/com/ibm/watson/developer_cloud/conversation/v1/Conversation.java +93-101Lines changed: 93 additions & 101 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/com/ibm/watson/developer_cloud/http/RequestBuilder.java +7-9Lines changed: 7 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,7 +84,7 @@ public static RequestBuilder put(HttpUrl url) { | 84 | 84 | * @param pathSegments the path segments for a specific API call | 85 | 85 | * @return the HttpUrl object | 86 | 86 | */ | 87 | | - public static HttpUrl constructHttpUrl(String endPoint, List<String> pathSegments) { | | 87 | + public static HttpUrl constructHttpUrl(String endPoint, String[] pathSegments) { | 88 | 88 | HttpUrl.Builder httpUrlBuilder = HttpUrl.parse(endPoint).newBuilder(); | 89 | 89 | for (String segment : pathSegments) { | 90 | 90 | httpUrlBuilder.addPathSegments(segment); | @@ -100,12 +100,12 @@ public static HttpUrl constructHttpUrl(String endPoint, List<String> pathSegment | 100 | 100 | * @param pathParameters the path parameters for a specific API call | 101 | 101 | * @return the HttpUrl object | 102 | 102 | */ | 103 | | - public static HttpUrl constructHttpUrl(String endPoint, List<String> pathSegments, List<String> pathParameters) { | | 103 | + public static HttpUrl constructHttpUrl(String endPoint, String[] pathSegments, String[] pathParameters) { | 104 | 104 | HttpUrl.Builder httpUrlBuilder = HttpUrl.parse(endPoint).newBuilder(); | 105 | | - for (int i = 0; i < pathSegments.size(); i++) { | 106 | | - httpUrlBuilder.addPathSegments(pathSegments.get(i)); | 107 | | - if (i < pathParameters.size()) { | 108 | | - httpUrlBuilder.addPathSegment(pathParameters.get(i)); | | 105 | + for (int i = 0; i < pathSegments.length; i++) { | | 106 | + httpUrlBuilder.addPathSegments(pathSegments[i]); | | 107 | + if (i < pathParameters.length) { | | 108 | + httpUrlBuilder.addPathSegment(pathParameters[i]); | 109 | 109 | } | 110 | 110 | } | 111 | 111 | return httpUrlBuilder.build(); | @@ -147,7 +147,7 @@ private RequestBuilder(HTTPMethod method, HttpUrl url) { | 147 | 147 | * @param params the parameters | 148 | 148 | * @param name the parameter name | 149 | 149 | * @param value the value to set, will be obtained via {@link String#valueOf(boolean)}. If null, only the parameter is | 150 | | - * set. It can also be a collection or array, in which case all elements are added as query parameters | | 150 | + * set. It can also be a collection or array, in which case all elements are added as query parameters | 151 | 151 | * | 152 | 152 | * @return this | 153 | 153 | */ | @@ -187,7 +187,6 @@ public Request build() { | 187 | 187 | // URL | 188 | 188 | builder.url(toUrl()); | 189 | 189 |
| 190 | | - | 191 | 190 | if (method == HTTPMethod.GET) { | 192 | 191 | Validator.isNull(body, "cannot send a RequestBody in a GET request"); | 193 | 192 | } else if (!formParams.isEmpty()) { | @@ -218,7 +217,6 @@ public Request build() { | 218 | 217 |
| 219 | 218 | /* | 220 | 219 | * (non-Javadoc) | 221 | | - * | 222 | 220 | * @see java.lang.Object#toString() | 223 | 221 | */ | 224 | 222 | @Override | |
Collapse file Copy file name to clipboardExpand all lines: discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/Discovery.java +95-114Lines changed: 95 additions & 114 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: language-translator/src/main/java/com/ibm/watson/developer_cloud/language_translator/v2/LanguageTranslator.java +10-13Lines changed: 10 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 35 | 35 | import okhttp3.MultipartBody; | 36 | 36 | import okhttp3.RequestBody; | 37 | 37 |
| 38 | | -import java.util.Arrays; | 39 | | -import java.util.List; | 40 | | - | 41 | 38 | /** | 42 | 39 | * Language Translator translates text from one language to another. The service offers multiple domain-specific models | 43 | 40 | * that you can customize based on your unique terminology and language. Use Language Translator to take news from | @@ -83,7 +80,7 @@ public LanguageTranslator(String username, String password) { | 83 | 80 | */ | 84 | 81 | public ServiceCall<TranslationResult> translate(TranslateOptions translateOptions) { | 85 | 82 | Validator.notNull(translateOptions, "translateOptions cannot be null"); | 86 | | - List<String> pathSegments = Arrays.asList("v2/translate"); | | 83 | + String[] pathSegments = { "v2/translate" }; | 87 | 84 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 88 | 85 | final JsonObject contentJson = new JsonObject(); | 89 | 86 | contentJson.add("text", GsonSingleton.getGson().toJsonTree(translateOptions.text())); | @@ -110,7 +107,7 @@ public ServiceCall<TranslationResult> translate(TranslateOptions translateOption | 110 | 107 | */ | 111 | 108 | public ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions) { | 112 | 109 | Validator.notNull(identifyOptions, "identifyOptions cannot be null"); | 113 | | - List<String> pathSegments = Arrays.asList("v2/identify"); | | 110 | + String[] pathSegments = { "v2/identify" }; | 114 | 111 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 115 | 112 | builder.bodyContent(identifyOptions.text(), "text/plain"); | 116 | 113 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IdentifiedLanguages.class)); | @@ -126,7 +123,7 @@ public ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions | 126 | 123 | */ | 127 | 124 | public ServiceCall<IdentifiedLanguages> identifyAsPlain(IdentifyOptions identifyOptions) { | 128 | 125 | Validator.notNull(identifyOptions, "identifyOptions cannot be null"); | 129 | | - List<String> pathSegments = Arrays.asList("v2/identify"); | | 126 | + String[] pathSegments = { "v2/identify" }; | 130 | 127 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 131 | 128 | builder.bodyContent(identifyOptions.text(), "text/plain"); | 132 | 129 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IdentifiedLanguages.class)); | @@ -144,7 +141,7 @@ public ServiceCall<IdentifiedLanguages> identifyAsPlain(IdentifyOptions identify | 144 | 141 | */ | 145 | 142 | public ServiceCall<IdentifiableLanguages> listIdentifiableLanguages( | 146 | 143 | ListIdentifiableLanguagesOptions listIdentifiableLanguagesOptions) { | 147 | | - List<String> pathSegments = Arrays.asList("v2/identifiable_languages"); | | 144 | + String[] pathSegments = { "v2/identifiable_languages" }; | 148 | 145 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 149 | 146 | if (listIdentifiableLanguagesOptions != null) { | 150 | 147 | } | @@ -178,7 +175,7 @@ public ServiceCall<TranslationModel> createModel(CreateModelOptions createModelO | 178 | 175 | Validator.isTrue((createModelOptions.forcedGlossary() != null) || (createModelOptions.parallelCorpus() != null) | 179 | 176 | || (createModelOptions.monolingualCorpus() != null), | 180 | 177 | "At least one of forcedGlossary, parallelCorpus, or monolingualCorpus must be supplied."); | 181 | | - List<String> pathSegments = Arrays.asList("v2/models"); | | 178 | + String[] pathSegments = { "v2/models" }; | 182 | 179 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 183 | 180 | builder.query("base_model_id", createModelOptions.baseModelId()); | 184 | 181 | if (createModelOptions.name() != null) { | @@ -218,8 +215,8 @@ public ServiceCall<TranslationModel> createModel(CreateModelOptions createModelO | 218 | 215 | */ | 219 | 216 | public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) { | 220 | 217 | Validator.notNull(deleteModelOptions, "deleteModelOptions cannot be null"); | 221 | | - List<String> pathSegments = Arrays.asList("v2/models"); | 222 | | - List<String> pathParameters = Arrays.asList(deleteModelOptions.modelId()); | | 218 | + String[] pathSegments = { "v2/models" }; | | 219 | + String[] pathParameters = { deleteModelOptions.modelId() }; | 223 | 220 | RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 224 | 221 | pathParameters)); | 225 | 222 | return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); | @@ -235,8 +232,8 @@ public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) { | 235 | 232 | */ | 236 | 233 | public ServiceCall<TranslationModel> getModel(GetModelOptions getModelOptions) { | 237 | 234 | Validator.notNull(getModelOptions, "getModelOptions cannot be null"); | 238 | | - List<String> pathSegments = Arrays.asList("v2/models"); | 239 | | - List<String> pathParameters = Arrays.asList(getModelOptions.modelId()); | | 235 | + String[] pathSegments = { "v2/models" }; | | 236 | + String[] pathParameters = { getModelOptions.modelId() }; | 240 | 237 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 241 | 238 | pathParameters)); | 242 | 239 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModel.class)); | @@ -251,7 +248,7 @@ public ServiceCall<TranslationModel> getModel(GetModelOptions getModelOptions) { | 251 | 248 | * @return a {@link ServiceCall} with a response type of {@link TranslationModels} | 252 | 249 | */ | 253 | 250 | public ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions) { | 254 | | - List<String> pathSegments = Arrays.asList("v2/models"); | | 251 | + String[] pathSegments = { "v2/models" }; | 255 | 252 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 256 | 253 | if (listModelsOptions != null) { | 257 | 254 | if (listModelsOptions.source() != null) { | |
Collapse file Copy file name to clipboardExpand all lines: natural-language-classifier/src/main/java/com/ibm/watson/developer_cloud/natural_language_classifier/v1/NaturalLanguageClassifier.java +8-11Lines changed: 8 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | import okhttp3.MultipartBody; | 31 | 31 | import okhttp3.RequestBody; | 32 | 32 |
| 33 | | -import java.util.Arrays; | 34 | | -import java.util.List; | 35 | | - | 36 | 33 | /** | 37 | 34 | * IBM Watson Natural Language Classifier uses machine learning algorithms to return the top matching predefined classes | 38 | 35 | * for short text input. You create and train a classifier to connect predefined classes to example texts so that the | @@ -80,8 +77,8 @@ public NaturalLanguageClassifier(String username, String password) { | 80 | 77 | */ | 81 | 78 | public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) { | 82 | 79 | Validator.notNull(classifyOptions, "classifyOptions cannot be null"); | 83 | | - List<String> pathSegments = Arrays.asList("v1/classifiers", "classify"); | 84 | | - List<String> pathParameters = Arrays.asList(classifyOptions.classifierId()); | | 80 | + String[] pathSegments = { "v1/classifiers", "classify" }; | | 81 | + String[] pathParameters = { classifyOptions.classifierId() }; | 85 | 82 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 86 | 83 | pathParameters)); | 87 | 84 | final JsonObject contentJson = new JsonObject(); | @@ -100,7 +97,7 @@ public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) { | 100 | 97 | */ | 101 | 98 | public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) { | 102 | 99 | Validator.notNull(createClassifierOptions, "createClassifierOptions cannot be null"); | 103 | | - List<String> pathSegments = Arrays.asList("v1/classifiers"); | | 100 | + String[] pathSegments = { "v1/classifiers" }; | 104 | 101 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 105 | 102 | MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); | 106 | 103 | multipartBuilder.setType(MultipartBody.FORM); | @@ -122,8 +119,8 @@ public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createCl | 122 | 119 | */ | 123 | 120 | public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) { | 124 | 121 | Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null"); | 125 | | - List<String> pathSegments = Arrays.asList("v1/classifiers"); | 126 | | - List<String> pathParameters = Arrays.asList(deleteClassifierOptions.classifierId()); | | 122 | + String[] pathSegments = { "v1/classifiers" }; | | 123 | + String[] pathParameters = { deleteClassifierOptions.classifierId() }; | 127 | 124 | RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 128 | 125 | pathParameters)); | 129 | 126 | return createServiceCall(builder.build(), ResponseConverterUtils.getVoid()); | @@ -139,8 +136,8 @@ public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifi | 139 | 136 | */ | 140 | 137 | public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) { | 141 | 138 | Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null"); | 142 | | - List<String> pathSegments = Arrays.asList("v1/classifiers"); | 143 | | - List<String> pathParameters = Arrays.asList(getClassifierOptions.classifierId()); | | 139 | + String[] pathSegments = { "v1/classifiers" }; | | 140 | + String[] pathParameters = { getClassifierOptions.classifierId() }; | 144 | 141 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 145 | 142 | pathParameters)); | 146 | 143 | return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class)); | @@ -155,7 +152,7 @@ public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierO | 155 | 152 | * @return a {@link ServiceCall} with a response type of {@link ClassifierList} | 156 | 153 | */ | 157 | 154 | public ServiceCall<ClassifierList> listClassifiers(ListClassifiersOptions listClassifiersOptions) { | 158 | | - List<String> pathSegments = Arrays.asList("v1/classifiers"); | | 155 | + String[] pathSegments = { "v1/classifiers" }; | 159 | 156 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 160 | 157 | if (listClassifiersOptions != null) { | 161 | 158 | } | |
Collapse file Copy file name to clipboardExpand all lines: natural-language-understanding/src/main/java/com/ibm/watson/developer_cloud/natural_language_understanding/v1/NaturalLanguageUnderstanding.java +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | import com.ibm.watson.developer_cloud.util.GsonSingleton; | 25 | 25 | import com.ibm.watson.developer_cloud.util.ResponseConverterUtils; | 26 | 26 | import com.ibm.watson.developer_cloud.util.Validator; | 27 | | -import java.util.Arrays; | 28 | | -import java.util.List; | 29 | 27 |
| 30 | 28 | /** | 31 | 29 | * Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural | @@ -120,7 +118,7 @@ public NaturalLanguageUnderstanding(String versionDate, String username, String | 120 | 118 | */ | 121 | 119 | public ServiceCall<AnalysisResults> analyze(AnalyzeOptions analyzeOptions) { | 122 | 120 | Validator.notNull(analyzeOptions, "analyzeOptions cannot be null"); | 123 | | - List<String> pathSegments = Arrays.asList("v1/analyze"); | | 121 | + String[] pathSegments = { "v1/analyze" }; | 124 | 122 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 125 | 123 | builder.query(VERSION, versionDate); | 126 | 124 | final JsonObject contentJson = new JsonObject(); | @@ -166,8 +164,8 @@ public ServiceCall<AnalysisResults> analyze(AnalyzeOptions analyzeOptions) { | 166 | 164 | */ | 167 | 165 | public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) { | 168 | 166 | Validator.notNull(deleteModelOptions, "deleteModelOptions cannot be null"); | 169 | | - List<String> pathSegments = Arrays.asList("v1/models"); | 170 | | - List<String> pathParameters = Arrays.asList(deleteModelOptions.modelId()); | | 167 | + String[] pathSegments = { "v1/models" }; | | 168 | + String[] pathParameters = { deleteModelOptions.modelId() }; | 171 | 169 | RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, | 172 | 170 | pathParameters)); | 173 | 171 | builder.query(VERSION, versionDate); | @@ -184,7 +182,7 @@ public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) { | 184 | 182 | * @return a {@link ServiceCall} with a response type of {@link ListModelsResults} | 185 | 183 | */ | 186 | 184 | public ServiceCall<ListModelsResults> listModels(ListModelsOptions listModelsOptions) { | 187 | | - List<String> pathSegments = Arrays.asList("v1/models"); | | 185 | + String[] pathSegments = { "v1/models" }; | 188 | 186 | RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 189 | 187 | builder.query(VERSION, versionDate); | 190 | 188 | if (listModelsOptions != null) { | |
Collapse file Copy file name to clipboardExpand all lines: personality-insights/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v3/PersonalityInsights.java +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | import com.ibm.watson.developer_cloud.util.ResponseConverterUtils; | 24 | 24 | import com.ibm.watson.developer_cloud.util.Validator; | 25 | 25 |
| 26 | | -import java.util.Arrays; | 27 | | -import java.util.List; | 28 | | - | 29 | 26 | /** | 30 | 27 | * ### Service Overview | 31 | 28 | * The IBM Watson Personality Insights service provides a Representational State Transfer (REST) Application Programming | @@ -112,7 +109,7 @@ public PersonalityInsights(String versionDate, String username, String password) | 112 | 109 | */ | 113 | 110 | public ServiceCall<Profile> profile(ProfileOptions profileOptions) { | 114 | 111 | Validator.notNull(profileOptions, "profileOptions cannot be null"); | 115 | | - List<String> pathSegments = Arrays.asList("v3/profile"); | | 112 | + String[] pathSegments = { "v3/profile" }; | 116 | 113 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 117 | 114 | builder.query(VERSION, versionDate); | 118 | 115 | builder.header("Content-Type", profileOptions.contentType()); | @@ -151,7 +148,7 @@ public ServiceCall<Profile> profile(ProfileOptions profileOptions) { | 151 | 148 | */ | 152 | 149 | public ServiceCall<String> getProfileAsCSV(ProfileOptions profileOptions, boolean includeHeaders) { | 153 | 150 | Validator.notNull(profileOptions, "profileOptions cannot be null"); | 154 | | - List<String> pathSegments = Arrays.asList("v3/profile"); | | 151 | + String[] pathSegments = { "v3/profile" }; | 155 | 152 | RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments)); | 156 | 153 | builder.query(VERSION, versionDate); | 157 | 154 | builder.header("Content-Type", profileOptions.contentType()); | |
|