use of com.squareup.okhttp.Request in project fresco by facebook.
the class OkHttpNetworkFetcher method fetch.
@Override
public void fetch(final OkHttpNetworkFetchState fetchState, final Callback callback) {
fetchState.submitTime = SystemClock.uptimeMillis();
final Uri uri = fetchState.getUri();
try {
Request request = new Request.Builder().cacheControl(new CacheControl.Builder().noStore().build()).url(uri.toString()).get().build();
fetchWithRequest(fetchState, callback, request);
} catch (Exception e) {
// handle error while creating the request
callback.onFailure(e);
}
}
use of com.squareup.okhttp.Request in project LookLook by xinghongfei.
the class OkHttpUtils method getRequest.
private void getRequest(String url, final ResultCallback callback) {
final Request request = new Request.Builder().url(url).build();
deliveryResult(callback, request);
}
use of com.squareup.okhttp.Request in project PocketHub by pockethub.
the class RawCommentFragment method onActivityResult.
@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
showProgressIndeterminate(R.string.loading);
ImageBinPoster.post(getActivity(), data.getData(), new Callback() {
@Override
public void onFailure(Request request, IOException e) {
dismissProgress();
showImageError();
}
@Override
public void onResponse(Response response) throws IOException {
dismissProgress();
if (response.isSuccessful()) {
insertImage(ImageBinPoster.getUrl(response.body().string()));
} else {
showImageError();
}
}
});
}
}
use of com.squareup.okhttp.Request in project java by kubernetes-client.
the class ProtoClient method request.
/**
* Generic protocol buffer based HTTP request. Not intended for general consumption, but public
* for advance use cases.
*
* @param builder The appropriate Builder for the object receveived from the request.
* @param method The HTTP method (e.g. GET) for this request.
* @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
* @param body The body to send with the request (optional)
* @param apiVersion The 'apiVersion' to use when encoding, required if body is non-null, ignored
* otherwise.
* @param kind The 'kind' field to use when encoding, required if body is non-null, ignored
* otherwise.
* @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
*/
public <T extends Message> ObjectOrStatus<T> request(T.Builder builder, String path, String method, T body, String apiVersion, String kind) throws ApiException, IOException {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", MEDIA_TYPE);
headers.put("Accept", MEDIA_TYPE);
String[] localVarAuthNames = new String[] { "BearerToken" };
Request request = apiClient.buildRequest(path, method, new ArrayList<Pair>(), new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), localVarAuthNames, null);
if (body != null) {
byte[] bytes = encode(body, apiVersion, kind);
switch(method) {
case "POST":
request = request.newBuilder().post(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
break;
case "PUT":
request = request.newBuilder().put(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
break;
case "PATCH":
request = request.newBuilder().patch(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
break;
default:
throw new ApiException("Unknown proto client API method: " + method);
}
}
Response resp = apiClient.getHttpClient().newCall(request).execute();
Unknown u = parse(resp.body().byteStream());
resp.body().close();
if (u.getTypeMeta().getApiVersion().equals("v1") && u.getTypeMeta().getKind().equals("Status")) {
Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
return new ObjectOrStatus(null, status);
}
return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
}
use of com.squareup.okhttp.Request in project AisenWeiBo by wangdan.
the class DefHttpUtility method doGet.
@Override
public <T> T doGet(HttpConfig config, Setting action, Params urlParams, Class<T> responseCls) throws TaskException {
Request.Builder builder = createRequestBuilder(config, action, urlParams, "Get");
Request request = builder.build();
return executeRequest(request, responseCls, action, "Get");
}
Aggregations