use of retrofit2.http.POST in project Collar by CodeZsx.
the class HttpUtils method getRetrofitWithAppKey.
private Retrofit getRetrofitWithAppKey(String baseUrl) {
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request r = addParam(chain.request());
Log.i(TAG, r.method() + " " + r.url().toString());
return chain.proceed(r);
}
private Request addParam(Request oldRequest) {
if (oldRequest.method().equals("POST")) {
return oldRequest;
}
HttpUrl.Builder builder = oldRequest.url().newBuilder().setEncodedQueryParameter("source", Config.APP_KEY);
return oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body()).url(builder.build()).build();
}
}).build();
return new Retrofit.Builder().client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(baseUrl).build();
}
use of retrofit2.http.POST in project Collar by CodeZsx.
the class HttpUtils method getRetrofit.
private Retrofit getRetrofit(String baseUrl) {
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request r = addParam(chain.request());
Log.i(TAG, r.method() + " " + r.url().toString());
return chain.proceed(r);
}
private Request addParam(Request oldRequest) {
if (oldRequest.method().equals("POST")) {
return oldRequest;
}
HttpUrl.Builder builder = oldRequest.url().newBuilder().setEncodedQueryParameter("access_token", AccessTokenKeeper.getInstance().getAccessToken());
return oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body()).url(builder.build()).build();
}
}).build();
return new Retrofit.Builder().client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(baseUrl).build();
}
use of retrofit2.http.POST in project autorest.java by Azure.
the class ParameterGroupingsImpl method postSharedParameterGroupObjectWithServiceResponseAsync.
/**
* Post parameters with a shared parameter group object.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> postSharedParameterGroupObjectWithServiceResponseAsync() {
final FirstParameterGroup firstParameterGroup = null;
String headerOne = null;
Integer queryOne = null;
return service.postSharedParameterGroupObject(this.client.acceptLanguage(), headerOne, queryOne, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = postSharedParameterGroupObjectDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of retrofit2.http.POST in project autorest.java by Azure.
the class ParameterGroupingsImpl method postMultiParamGroupsWithServiceResponseAsync.
/**
* Post parameters from multiple different parameter groups.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> postMultiParamGroupsWithServiceResponseAsync() {
final FirstParameterGroup firstParameterGroup = null;
final ParameterGroupingPostMultiParamGroupsSecondParamGroup parameterGroupingPostMultiParamGroupsSecondParamGroup = null;
String headerOne = null;
Integer queryOne = null;
String headerTwo = null;
Integer queryTwo = null;
return service.postMultiParamGroups(this.client.acceptLanguage(), headerOne, queryOne, headerTwo, queryTwo, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = postMultiParamGroupsDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of retrofit2.http.POST in project autorest.java by Azure.
the class LROsCustomHeadersImpl method postAsyncRetrySucceededWithServiceResponseAsync.
/**
* x-ms-client-request-id = 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0 is required message header for all requests. Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable for the request
*/
public Observable<ServiceResponseWithHeaders<Void, LROsCustomHeaderPostAsyncRetrySucceededHeaders>> postAsyncRetrySucceededWithServiceResponseAsync() {
final Product product = null;
Observable<Response<ResponseBody>> observable = service.postAsyncRetrySucceeded(product, this.client.acceptLanguage(), this.client.userAgent());
return client.getAzureClient().getPostOrDeleteResultWithHeadersAsync(observable, new TypeToken<Void>() {
}.getType(), LROsCustomHeaderPostAsyncRetrySucceededHeaders.class);
}
Aggregations