List of usage examples for com.squareup.okhttp Response body
ResponseBody body
To view the source code for com.squareup.okhttp Response body.
Click Source Link
From source file:com.apothesource.pillfill.service.prescription.impl.DefaultPrescriptionServiceImpl.java
License:Open Source License
@Override public Observable<AccountAggregationTaskResponse> getExtractResponse(AccountAggregationTaskResponse task) { return subscribeIoObserveImmediate(subscriber -> { OkHttpClient client = PFNetworkManager.getPinnedPFHttpClient(); String statusUrl = String.format(PFServiceEndpoints.RX_EXTRACT_STATUS_URL, task.taskId); Request req = new Request.Builder().url(statusUrl).build(); String responseStr = null; try {/*from w ww .j av a 2s. co m*/ Response res = client.newCall(req).execute(); responseStr = res.body().string(); AccountAggregationTaskResponse response = gson.fromJson(responseStr, AccountAggregationTaskResponse.class); subscriber.onNext(response); subscriber.onCompleted(); } catch (IOException e) { Timber.e(e, "Error requesting extract status from server."); subscriber.onError(e); } catch (JsonParseException e) { Timber.e(e, "Unexpected response from the server: %s", responseStr); subscriber.onError(e); } }); }
From source file:com.apothesource.pillfill.service.prescription.impl.DefaultPrescriptionServiceImpl.java
License:Open Source License
@Override public Observable<PrescriptionType> enrichPrescriptions(List<PrescriptionType> rxList) { return subscribeIoObserveImmediate(subscriber -> { try {/*from w ww . j av a 2s .com*/ OkHttpClient client = PFNetworkManager.getPinnedPFHttpClient(); Request req = new Request.Builder() .post(RequestBody.create(MediaType.parse(HTTP_CONTENT_TYPE_JSON), gson.toJson(rxList))) .url(PFServiceEndpoints.RX_ENRICH_URL).build(); Response res = client.newCall(req).execute(); List<PrescriptionType> enrichedRxList = gson.fromJson(res.body().charStream(), RX_LIST_TYPE); Observable.from(enrichedRxList).forEach(subscriber::onNext); subscriber.onCompleted(); } catch (IOException ex) { Logger.getLogger(DefaultPrescriptionServiceImpl.class.getName()).log(Level.SEVERE, null, ex); subscriber.onError(ex); } }); }
From source file:com.apothesource.pillfill.service.reminder.impl.DefaultReminderServiceImpl.java
License:Open Source License
@Override public Observable<ReminderWSResponse> updateRemindersForRx(List<Reminder> reminderList, PrescriptionType rx) { return subscribeIoObserveImmediate(subscriber -> { try {/*from w w w. j a v a 2 s . c o m*/ RequestBody reminderJson = RequestBody.create(MediaType.parse("application/json"), mGson.toJson(reminderList)); String url = String.format(PFServiceEndpoints.REMINDER_BASE_URL, rx.getUuid()); Request.Builder builder = new Request.Builder().url(url).post(reminderJson); Response response = mHttpClient.newCall(builder.build()).execute(); String responseJson = response.body().string(); ReminderWSResponse wsResponse = mGson.fromJson(responseJson, ReminderWSResponse.class); subscriber.onNext(wsResponse); subscriber.onCompleted(); } catch (IOException e) { mLog.log(Level.SEVERE, "Failed to update reminders.", e); subscriber.onError(e); } }); }
From source file:com.apothesource.pillfill.service.reminder.impl.DefaultReminderServiceImpl.java
License:Open Source License
@Override public Observable<Reminder> getRemindersForRx(PrescriptionType rx) { return subscribeIoObserveImmediate(subscriber -> { try {// w ww. j a v a 2s .co m String url = String.format(PFServiceEndpoints.REMINDER_BASE_URL, rx.getUuid()); Request.Builder builder = new Request.Builder().url(url).get(); Response response = mHttpClient.newCall(builder.build()).execute(); String responseJson = response.body().string(); ReminderWSResponse wsResponse = mGson.fromJson(responseJson, ReminderWSResponse.class); if (wsResponse.error == null) { Observable.from(wsResponse.reminders).toBlocking().forEach(subscriber::onNext); subscriber.onCompleted(); } else { subscriber.onError(new ReminderConfigurationException(wsResponse.error)); } } catch (IOException e) { mLog.log(Level.SEVERE, "Failed to update reminders.", e); subscriber.onError(e); } }); }
From source file:com.appstarter.utils.WebUtils.java
License:Apache License
public static String doHttpGet(String url) throws AppStarterException { if (BuildConfig.DEBUG) { Log.d(TAG, "doHttpGet - url: " + url); }/*from w ww . ja va2 s . c o m*/ String ret = ""; OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout try { Request request = new Request.Builder().url(new URL(url)) // .header("User-Agent", "OkHttp Headers.java") // .addHeader("Accept", "application/json; q=0.5") .build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { String debugMessage = "doHttpGet - OkHttp.Response is not successful - " + response.message() + " (" + response.code() + ")"; throw new AppStarterException(AppStarterException.ERROR_SERVER, debugMessage); } ret = response.body().string(); } catch (IOException e) { throw new AppStarterException(e, AppStarterException.ERROR_NETWORK_GET); } return ret; }
From source file:com.appstarter.utils.WebUtils.java
License:Apache License
public static String doHttpPost(String url, List<NameValuePair> params) throws AppStarterException { if (BuildConfig.DEBUG) { Log.d(TAG, "doHttpPost - url: " + debugRequest(url, params)); }/* w w w .j av a 2 s . c om*/ String ret = ""; OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(15, TimeUnit.SECONDS); // socket timeout FormEncodingBuilder builder = new FormEncodingBuilder(); for (NameValuePair nvp : params) { builder.add(nvp.getName(), nvp.getValue()); } RequestBody formBody = builder.build(); try { Request request = new Request.Builder().url(new URL(url)) // .header("User-Agent", "OkHttp Headers.java") // .addHeader("Accept", "application/json; q=0.5") .post(formBody).build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { String debugMessage = "doHttpPost - OkHttp.Response is not successful - " + response.message() + " (" + response.code() + ")"; throw new AppStarterException(AppStarterException.ERROR_SERVER, debugMessage); } ret = response.body().string(); } catch (IOException e) { throw new AppStarterException(e, AppStarterException.ERROR_NETWORK_GET); } return ret; }
From source file:com.ariadnext.idcheckio.api.AdministrationApi.java
License:Apache License
private com.squareup.okhttp.Call getHealthCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/v0/admin/health".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 w w .j a v a 2s . c o 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.AdministrationApi.java
License:Apache License
private com.squareup.okhttp.Call getUserCall(String acceptLanguage, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/v0/admin/user".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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 = { };//from w w w. j a v a2 s .c o 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[] { "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 getReportCall(String analysisRefUid, String acceptLanguage, 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 getReport(Async)"); }//w w w .j av a2s .co m // create path and map variables String localVarPath = "/v0/pdfreport/{analysisRefUid}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "analysisRefUid" + "\\}", apiClient.escapeString(analysisRefUid.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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 getResultCall(String analysisRefUid, String acceptLanguage, Boolean rectoImageCropped, Boolean faceImageCropped, Boolean signatureImageCropped, 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 getResult(Async)"); }//from w ww .j a v a 2s. c o m // create path and map variables String localVarPath = "/v0/result/{analysisRefUid}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "analysisRefUid" + "\\}", apiClient.escapeString(analysisRefUid.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (rectoImageCropped != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "rectoImageCropped", rectoImageCropped)); if (faceImageCropped != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "faceImageCropped", faceImageCropped)); if (signatureImageCropped != null) localVarQueryParams .addAll(apiClient.parameterToPairs("", "signatureImageCropped", signatureImageCropped)); 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); }