Skip to content

Commit

Permalink
Merge pull request microsoft#4 from Microsoft/host-split
Browse files Browse the repository at this point in the history
Allow host base URI as an argument.
  • Loading branch information
chsienki authored Sep 8, 2016
2 parents 085216b + 9d3c89f commit 7e006f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@
import java.util.Map;

public class EmotionServiceRestClient implements EmotionServiceClient {
private static final String serviceHost = "https://api.projectoxford.ai/emotion/v1.0";
private static final String DEFAULT_API_ROOT = "https://api.projectoxford.ai/emotion/v1.0";
private static final String FACE_RECTANGLES = "faceRectangles";
private WebServiceRequest restCall = null;
private final String apiRoot;
private final WebServiceRequest restCall;
private Gson gson = new Gson();

public EmotionServiceRestClient(String subscriptionKey) {
this(subscriptionKey, DEFAULT_API_ROOT);
}

public EmotionServiceRestClient(String subscriptionKey, String apiRoot) {
this.apiRoot = apiRoot.replaceAll("/$", "");
this.restCall = new WebServiceRequest(subscriptionKey);
}

Expand All @@ -65,7 +71,7 @@ public List<RecognizeResult> recognizeImage(String url) throws EmotionServiceExc
@Override
public List<RecognizeResult> recognizeImage(String url, FaceRectangle[] faceRectangles) throws EmotionServiceException {
Map<String, Object> params = new HashMap<>();
String path = serviceHost + "/recognize";
String path = apiRoot + "/recognize";
if (faceRectangles != null && faceRectangles.length > 0) {
params.put(FACE_RECTANGLES, getFaceRectangleStrings(faceRectangles));
}
Expand All @@ -88,7 +94,7 @@ public List<RecognizeResult> recognizeImage(InputStream stream) throws EmotionSe
@Override
public List<RecognizeResult> recognizeImage(InputStream stream, FaceRectangle[] faceRectangles) throws EmotionServiceException, IOException {
Map<String, Object> params = new HashMap<>();
String path = serviceHost + "/recognize";
String path = apiRoot + "/recognize";
if (faceRectangles != null && faceRectangles.length > 0) {
params.put(FACE_RECTANGLES, getFaceRectangleStrings(faceRectangles));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services
//
// Microsoft Cognitive Services (formerly Project Oxford) GitHub:
// https://github.com/Microsoft/Cognitive-Emotion-Android
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
package com.microsoft.projectoxford.emotion.contract;

public enum Order {
ASCENDING,DESCENDING
ASCENDING,
DESCENDING
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.Map;

import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -76,7 +77,7 @@ private Object webInvoke(String method, String url, Map<String, Object> data, St
/*Set header*/
if (contentType != null && !contentType.isEmpty()) {
request.setHeader("Content-Type", contentType);
if (contentType.toLowerCase().contains("octet-stream")) {
if (contentType.toLowerCase(Locale.ENGLISH).contains("octet-stream")) {
isStream = true;
}
} else {
Expand Down

0 comments on commit 7e006f0

Please sign in to comment.