Search in sources :

Example 16 with POST

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();
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor) HttpUrl(okhttp3.HttpUrl)

Example 17 with POST

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();
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor) HttpUrl(okhttp3.HttpUrl)

Example 18 with POST

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);
            }
        }
    });
}
Also used : ServiceResponse(com.microsoft.rest.ServiceResponse) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) FirstParameterGroup(fixtures.azureparametergrouping.models.FirstParameterGroup) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 19 with POST

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);
            }
        }
    });
}
Also used : FirstParameterGroup(fixtures.azureparametergrouping.models.FirstParameterGroup) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ServiceResponse(com.microsoft.rest.ServiceResponse) Response(retrofit2.Response) ParameterGroupingPostMultiParamGroupsSecondParamGroup(fixtures.azureparametergrouping.models.ParameterGroupingPostMultiParamGroupsSecondParamGroup) ServiceResponse(com.microsoft.rest.ServiceResponse)

Example 20 with POST

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);
}
Also used : ServiceResponse(com.microsoft.rest.ServiceResponse) Response(retrofit2.Response) TypeToken(com.google.common.reflect.TypeToken) Product(fixtures.lro.models.Product)

Aggregations

ResponseBody (okhttp3.ResponseBody)40 Test (org.junit.Test)33 Request (okhttp3.Request)31 Response (retrofit2.Response)27 ServiceResponse (com.microsoft.rest.ServiceResponse)22 RequestBody (okhttp3.RequestBody)19 TypeToken (com.google.common.reflect.TypeToken)18 Product (fixtures.lro.models.Product)18 Buffer (okio.Buffer)14 MultipartBody (okhttp3.MultipartBody)13 Part (retrofit2.http.Part)10 OkHttpClient (okhttp3.OkHttpClient)8 Body (retrofit2.http.Body)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 Field (retrofit2.http.Field)6 FieldMap (retrofit2.http.FieldMap)6 PartMap (retrofit2.http.PartMap)6 List (java.util.List)5 Map (java.util.Map)5