Example usage for com.squareup.okhttp Response body

List of usage examples for com.squareup.okhttp Response body

Introduction

In this page you can find the example usage for com.squareup.okhttp Response body.

Prototype

ResponseBody body

To view the source code for com.squareup.okhttp Response body.

Click Source Link

Usage

From source file:com.ariadnext.idcheckio.api.AnalysisApi.java

License:Apache License

private com.squareup.okhttp.Call getTaskCall(String analysisRefUid, String acceptLanguage, Long wait,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'analysisRefUid' is set
    if (analysisRefUid == null) {
        throw new ApiException("Missing the required parameter 'analysisRefUid' when calling getTask(Async)");
    }//  www .  j a  va2s  . co  m

    // create path and map variables
    String localVarPath = "/v0/task/{analysisRefUid}".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "analysisRefUid" + "\\}", apiClient.escapeString(analysisRefUid.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (wait != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "wait", wait));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    if (acceptLanguage != null)
        localVarHeaderParams.put("Accept-Language", apiClient.parameterToString(acceptLanguage));

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "basic" };
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.AnalysisApi.java

License:Apache License

private com.squareup.okhttp.Call postImageCall(ImageRequest body, Boolean asyncMode, String acceptLanguage,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = body;

    // verify the required parameter 'body' is set
    if (body == null) {
        throw new ApiException("Missing the required parameter 'body' when calling postImage(Async)");
    }//from w w w  . ja v a2  s  . c  o  m

    // create path and map variables
    String localVarPath = "/v0/task/image".replaceAll("\\{format\\}", "json");

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (asyncMode != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "asyncMode", asyncMode));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    if (acceptLanguage != null)
        localVarHeaderParams.put("Accept-Language", apiClient.parameterToString(acceptLanguage));

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "basic" };
    return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody,
            localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.AnalysisApi.java

License:Apache License

private com.squareup.okhttp.Call postMrzCall(MrzRequest body, Boolean asyncMode, String acceptLanguage,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = body;

    // verify the required parameter 'body' is set
    if (body == null) {
        throw new ApiException("Missing the required parameter 'body' when calling postMrz(Async)");
    }//from   w w  w  .j a  v a2 s  . c  o m

    // create path and map variables
    String localVarPath = "/v0/task/mrz".replaceAll("\\{format\\}", "json");

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (asyncMode != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "asyncMode", asyncMode));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    if (acceptLanguage != null)
        localVarHeaderParams.put("Accept-Language", apiClient.parameterToString(acceptLanguage));

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "basic" };
    return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody,
            localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.SandboxApi.java

License:Apache License

private com.squareup.okhttp.Call getImageCall(String imageUid, String rawType, String face, String light,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'imageUid' is set
    if (imageUid == null) {
        throw new ApiException("Missing the required parameter 'imageUid' when calling getImage(Async)");
    }/*from   w w  w .  j  a  va 2s.  c om*/

    // create path and map variables
    String localVarPath = "/v0/sandbox/image/{imageUid}".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "imageUid" + "\\}", apiClient.escapeString(imageUid.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (rawType != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "rawType", rawType));
    if (face != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "face", face));
    if (light != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "light", light));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "*_/_*" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] {};
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.SandboxApi.java

License:Apache License

private com.squareup.okhttp.Call getImageListCall(final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // create path and map variables
    String localVarPath = "/v0/sandbox/imagelist".replaceAll("\\{format\\}", "json");

    List<Pair> localVarQueryParams = new ArrayList<Pair>();

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };//from   w  ww .  ja v  a2s . co m
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] {};
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.SandboxApi.java

License:Apache License

private com.squareup.okhttp.Call getMrzCall(String mrzUid,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'mrzUid' is set
    if (mrzUid == null) {
        throw new ApiException("Missing the required parameter 'mrzUid' when calling getMrz(Async)");
    }//w ww .j  a  v a 2  s . co  m

    // create path and map variables
    String localVarPath = "/v0/sandbox/mrz/{mrzUid}".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "mrzUid" + "\\}", apiClient.escapeString(mrzUid.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] {};
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.api.SandboxApi.java

License:Apache License

private com.squareup.okhttp.Call getMrzListCall(final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // create path and map variables
    String localVarPath = "/v0/sandbox/mrzlist".replaceAll("\\{format\\}", "json");

    List<Pair> localVarQueryParams = new ArrayList<Pair>();

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json; charset=utf-8" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };/*from ww  w  .ja  va2 s  .c  om*/
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] {};
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:com.ariadnext.idcheckio.invoker.ApiClient.java

License:Apache License

/**
 * Handle the given response, return the deserialized object when the response is successful.
 *
 * @param <T> Type/*from   ww w.  ja v a  2s  .  c o  m*/
 * @param response Response
 * @param returnType Return type
 * @throws ApiException If the response has a unsuccessful status code or
 *   fail to deserialize the response body
 * @return Type
 */
public <T> T handleResponse(Response response, Type returnType) throws ApiException {
    if (response.isSuccessful() || response.code() == 303) {
        if (returnType == null || response.code() == 204) {
            // returning null if the returnType is not defined,
            // or the status code is 204 (No Content)
            return null;
        } else {
            return deserialize(response, returnType);
        }
    } else {
        String respBody = null;
        if (response.body() != null) {
            try {
                respBody = response.body().string();
            } catch (IOException e) {
                throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap());
            }
        }
        throw new ApiException(response.message(), response.code(), response.headers().toMultimap(), respBody);
    }
}

From source file:com.asynhkm.productchecker.Checker.CheckerTask.java

@Override
protected DataProductVersion doInBackground(Void... c) {
    DataProductVersion h;//www.ja  va  2s.co m
    try {
        RequestBody body = RequestBody.create(JSON, consolidate());
        Request request = new Request.Builder().url(request_url).post(body).build();
        Response response = client.newCall(request).execute();
        String res = response.body().string();
        h = return_result(res);
    } catch (NoClassDefFoundError e) {

        h = new DataProductVersion();
        h.setRR(new ReturnResult(e.getMessage()));

    } catch (IOException e) {

        Log.d("work ERROR", e.getMessage());
        h = new DataProductVersion();
        h.setRR(new ReturnResult(e.getMessage()));

    } catch (Exception e) {

        Log.d("work ERROR", e.getMessage());
        h = new DataProductVersion();
        h.setRR(new ReturnResult(e.getMessage()));

    }
    return h;
}

From source file:com.auth0.android.lock.internal.configuration.ApplicationFetcher.java

License:Open Source License

private List<Connection> parseJSONP(Response response) throws Auth0Exception {
    try {//from w w w . j av  a 2s .  c om
        String json = response.body().string();
        final int length = JSONP_PREFIX.length();
        if (json.length() < length) {
            throw new JSONException("Invalid App Info JSONP");
        }
        json = json.substring(length);
        JSONTokener tokenizer = new JSONTokener(json);
        if (!tokenizer.more()) {
            throw tokenizer.syntaxError("Invalid App Info JSONP");
        }
        Object nextValue = tokenizer.nextValue();
        if (!(nextValue instanceof JSONObject)) {
            tokenizer.back();
            throw tokenizer.syntaxError("Invalid JSON value of App Info");
        }
        JSONObject jsonObject = (JSONObject) nextValue;
        Type applicationType = new TypeToken<List<Connection>>() {
        }.getType();
        return createGson().fromJson(jsonObject.toString(), applicationType);
    } catch (IOException | JSONException e) {
        throw new Auth0Exception("Failed to parse response to request", e);
    }
}