Search in sources :

Example 1 with APIEnvelopeTransformerConverterFactory

use of co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory in project CubedPay-Java by MelonDevelopment.

the class CubedPayAPI method create.

static CubedPayAPI create(String appID, String accessToken, String apiUrl) {
    Dispatcher dispatcher = new Dispatcher();
    CubedPayAPI api = new Retrofit.Builder().baseUrl(apiUrl).addConverterFactory(new Converter.Factory() {

        @Override
        public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            return super.responseBodyConverter(type, annotations, retrofit);
        }
    }).addConverterFactory(new APIEnvelopeTransformerConverterFactory(GsonConverterFactory.create())).addCallAdapterFactory(Java8CallAdapterFactory.create()).client(new OkHttpClient.Builder().addInterceptor(chain -> chain.proceed(chain.request().newBuilder().addHeader("app-id", appID).url(chain.request().url().newBuilder().addQueryParameter("access_token", accessToken).build()).build())).dispatcher(dispatcher).build()).build().create(CubedPayAPI.class);
    DispatcherMap.dispatcherMap.put(api, dispatcher);
    return api;
}
Also used : APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) Converter(retrofit2.Converter) co.melondev.cubedpay.data(co.melondev.cubedpay.data) java.util.concurrent(java.util.concurrent) HashMap(java.util.HashMap) CubedEventRunnable(co.melondev.cubedpay.event.CubedEventRunnable) Retrofit(retrofit2.Retrofit) Dispatcher(okhttp3.Dispatcher) CubedAnnotationProcessor(co.melondev.cubedpay.event.CubedAnnotationProcessor) Java8CallAdapterFactory(retrofit2.adapter.java8.Java8CallAdapterFactory) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) Type(java.lang.reflect.Type) retrofit2.http(retrofit2.http) Map(java.util.Map) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) Annotation(java.lang.annotation.Annotation) CubedEvent(co.melondev.cubedpay.event.CubedEvent) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) Type(java.lang.reflect.Type) Java8CallAdapterFactory(retrofit2.adapter.java8.Java8CallAdapterFactory) APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) Dispatcher(okhttp3.Dispatcher) ResponseBody(okhttp3.ResponseBody)

Aggregations

co.melondev.cubedpay.data (co.melondev.cubedpay.data)1 APIEnvelopeTransformerConverterFactory (co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory)1 CubedAnnotationProcessor (co.melondev.cubedpay.event.CubedAnnotationProcessor)1 CubedEvent (co.melondev.cubedpay.event.CubedEvent)1 CubedEventRunnable (co.melondev.cubedpay.event.CubedEventRunnable)1 Annotation (java.lang.annotation.Annotation)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 java.util.concurrent (java.util.concurrent)1 Dispatcher (okhttp3.Dispatcher)1 OkHttpClient (okhttp3.OkHttpClient)1 ResponseBody (okhttp3.ResponseBody)1 Converter (retrofit2.Converter)1 Retrofit (retrofit2.Retrofit)1 Java8CallAdapterFactory (retrofit2.adapter.java8.Java8CallAdapterFactory)1 GsonConverterFactory (retrofit2.converter.gson.GsonConverterFactory)1 retrofit2.http (retrofit2.http)1