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.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call getSessionByIdCall(String sessionId, Boolean deletedParticipants, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/sessions/{session_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "session_id" + "\\}", apiClient.escapeString(sessionId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (deletedParticipants != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "deleted_participants", deletedParticipants)); Map<String, String> localVarHeaderParams = new HashMap<String, String>(); Map<String, Object> localVarFormParams = new HashMap<String, Object>(); final String[] localVarAccepts = { "application/json" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { };//from w ww. jav a2 s . com 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call getSessionPageCall(Integer page, Integer pageSize, DateTime startTime, DateTime endTime, Boolean includeCanceled, Boolean deletedParticipants, String state, String order, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/sessions".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (page != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "page", page)); if (pageSize != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "page_size", pageSize)); if (startTime != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "start_time", startTime)); if (endTime != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "end_time", endTime)); if (includeCanceled != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "include_canceled", includeCanceled)); if (deletedParticipants != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "deleted_participants", deletedParticipants)); if (state != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "state", state)); if (order != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "order", order)); Map<String, String> localVarHeaderParams = new HashMap<String, String>(); Map<String, Object> localVarFormParams = new HashMap<String, Object>(); final String[] localVarAccepts = { "application/json" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { };/* ww w . j ava 2 s . com*/ 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call getSessionParticipantCall(String participantId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/participants/{participant_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "participant_id" + "\\}", apiClient.escapeString(participantId.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" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { };//from w w w . ja v a 2 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call getSessionParticipantsCall(String sessionId, Boolean deletedParticipants, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/sessions/{session_id}/participants".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "session_id" + "\\}", apiClient.escapeString(sessionId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (deletedParticipants != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "deleted_participants", deletedParticipants)); Map<String, String> localVarHeaderParams = new HashMap<String, String>(); Map<String, Object> localVarFormParams = new HashMap<String, Object>(); final String[] localVarAccepts = { "application/json" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { };/*from w ww . jav a 2 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call updateSessionCall(String sessionId, SessionUpdateRequest body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // create path and map variables String localVarPath = "/sessions/{session_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "session_id" + "\\}", apiClient.escapeString(sessionId.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" }; 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// w w w . j a v a2 s.c om 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.coviu.sessions.api.SessionApi.java
License:Apache License
private com.squareup.okhttp.Call updateSessionParticipantCall(String participantId, ParticipantUpdateRequest body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // create path and map variables String localVarPath = "/participants/{participant_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "participant_id" + "\\}", apiClient.escapeString(participantId.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" }; 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// w w w.j a v a 2s . c o m 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[] { "oauth2" }; return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
License:Creative Commons License
/** * Get distance information between two GPS * @param originLat/*from w ww. ja v a2s. c om*/ * @param originLon * @param destLat * @param destLon * @return */ public static String[] getDistanceInfo(double originLat, double originLon, double destLat, double destLon) { String[] infos = new String[] { "0", "0" }; String address = Constants.GOOGLE_DISTANCE_MATRIX_ADDRESS; address += originLat + "," + originLon; address += "&destinations="; address += destLat + "," + destLon; address += "&mode=driving&units=metric&language=en&key="; address += Constants.GOOGLE_DISTANCE_MATRIX_API_KEY; OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url(address).build(); Response response = null; String dist = null; try { response = client.newCall(request).execute(); dist = response.body().string(); } catch (IOException e) { return infos; } Log.d("@@@@@@", dist); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = null; try { jsonObject = (JSONObject) jsonParser.parse(dist); } catch (ParseException e) { return infos; } // status check as well JSONArray rows = (JSONArray) jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_ROWS); for (int i = 0; i < rows.size(); i++) { JSONObject obj = (JSONObject) rows.get(i); JSONArray elements = (JSONArray) obj.get(Constants.GOOGLE_DISTANCE_MATRIX_ELEMENTS); for (int j = 0; j < elements.size(); j++) { JSONObject datas = (JSONObject) elements.get(j); JSONObject distance = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DISTANCE); JSONObject duration = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DURATION); infos[0] = distance.get(Constants.GOOGLE_DISTANCE_MATRIX_VALUE) + ""; infos[1] = duration.get(Constants.GOOGLE_DISTANCE_MATRIX_TEXT) + ""; } } String status = jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_STATUS).toString(); // Log.d("@@@@@@", status); if (!StringUtils.equalsIgnoreCase(Constants.GOOGLE_DISTANCE_MATRIX_OK, status)) { return infos; } return infos; }
From source file:com.crownpay.wallet.ExchangeRatesProvider.java
License:Open Source License
@Nullable private JSONObject requestExchangeRatesJson(final URL url) { // Return null if no connection final NetworkInfo activeInfo = connManager.getActiveNetworkInfo(); if (activeInfo == null || !activeInfo.isConnected()) return null; final long start = System.currentTimeMillis(); OkHttpClient client = NetworkUtils.getHttpClient(getContext().getApplicationContext()); Request request = new Request.Builder().url(url).build(); try {/*from w ww . j a va 2 s. co m*/ Response response = client.newCall(request).execute(); if (response.isSuccessful()) { log.info("fetched exchange rates from {}, took {} ms", url, System.currentTimeMillis() - start); return new JSONObject(response.body().string()); } else { log.warn("Error HTTP code '{}' when fetching exchange rates from {}", response.code(), url); } } catch (IOException e) { log.warn("Error '{}' when fetching exchange rates from {}", e.getMessage(), url); } catch (JSONException e) { log.warn("Could not parse exchange rates JSON: {}", e.getMessage()); } return null; }
From source file:com.cuddlesoft.norilib.clients.Danbooru.java
@Override public SearchResult search(String tags, int pid) throws IOException { // Create HTTP request. final Request request = new Request.Builder().url(createSearchURL(tags, pid, DEFAULT_LIMIT)).build(); // Get HTTP response. final Response response = okHttpClient.newCall(request).execute(); final String body = response.body().string(); // Return parsed SearchResult. return parseXMLResponse(body, tags, pid); }
From source file:com.danilov.supermanga.core.repository.HentaichanEngine.java
License:Open Source License
private String doWithLoginAttempt(final Callable<Response> callable) throws RepositoryException { try {//from www .j av a 2 s. c o m String response = null; int count = 0; do { if (!isAuthorized || count > 0) { final boolean loginSuccess = login(); if (!loginSuccess) { throw new RepositoryException("Failed to login"); } } Response _response = callable.call(); count++; response = _response.body().string(); } while (!checkAuthResponse(response)); return response; } catch (Exception e) { throw new RepositoryException("Failed to load: " + e.getMessage()); } }