@@ -0,0 +1,3604 @@
+package com.myduka.app.api;%0A%0Aimport com.myduka.app.api.services.STKPushService;%0A%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport okhttp3.OkHttpClient;%0Aimport okhttp3.logging.HttpLoggingInterceptor;%0Aimport retrofit2.Retrofit;%0Aimport retrofit2.converter.gson.GsonConverterFactory;%0A%0Aimport static com.myduka.app.util.AppConstants.BASE_URL;%0Aimport static com.myduka.app.util.AppConstants.CONNECT_TIMEOUT;%0Aimport static com.myduka.app.util.AppConstants.READ_TIMEOUT;%0Aimport static com.myduka.app.util.AppConstants.WRITE_TIMEOUT;%0A%0A/**%0A * API Client helper class used to configure Retrofit object.%0A *%0A * @author Thomas Kioko%0A */%0A%0Apublic class ApiClient %7B%0A%0A    private Retrofit retrofit;%0A    private boolean isDebug;%0A    private boolean isGetAccessToken;%0A    private String mAuthToken;%0A    private HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();%0A%0A    /**%0A     * Set the %7B@link Retrofit%7D log level. This allows one to view network traffic.%0A     *%0A     * @param isDebug If true, the log level is set to%0A     *                %7B@link HttpLoggingInterceptor.Level#BODY%7D. Otherwise%0A     *                %7B@link HttpLoggingInterceptor.Level#NONE%7D.%0A     */%0A    public ApiClient setIsDebug(boolean isDebug) %7B%0A        this.isDebug = isDebug;%0A        return this;%0A    %7D%0A%0A    /**%0A     * Helper method used to set the authenication Token%0A     *%0A     * @param authToken token from api%0A     */%0A    public ApiClient setAuthToken(String authToken) %7B%0A        mAuthToken = authToken;%0A        return this;%0A    %7D%0A%0A    /**%0A     * Helper method used to determine if get token enpoint has been invoked. This should be called%0A     * only when requesting of an accessToken%0A     *%0A     * @param getAccessToken %7B@link Boolean%7D%0A     */%0A    public ApiClient setGetAccessToken(boolean getAccessToken) %7B%0A        isGetAccessToken = getAccessToken;%0A        return this;%0A    %7D%0A%0A    /**%0A     * Configure OkHttpClient%0A     *%0A     * @return OkHttpClient%0A     */%0A    private OkHttpClient.Builder okHttpClient() %7B%0A        OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();%0A        okHttpClient%0A                .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)%0A                .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)%0A                .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)%0A                .addInterceptor(httpLoggingInterceptor);%0A%0A        return okHttpClient;%0A    %7D%0A%0A    /**%0A     * Return the current %7B@link Retrofit%7D instance. If none exists (first call, API key changed),%0A     * builds a new one.%0A     * %3Cp/%3E%0A     * When building, sets the endpoint and a %7B@link HttpLoggingInterceptor%7D which adds the API key as query param.%0A     */%0A    private Retrofit getRestAdapter() %7B%0A%0A        Retrofit.Builder builder = new Retrofit.Builder();%0A        builder.baseUrl(BASE_URL);%0A        builder.addConverterFactory(GsonConverterFactory.create());%0A%0A        if (isDebug) %7B%0A            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);%0A        %7D%0A%0A        OkHttpClient.Builder okhttpBuilder = okHttpClient();%0A%0A        if (isGetAccessToken) %7B%0A            okhttpBuilder.addInterceptor(new AccessTokenIterceptor());%0A        %7D%0A%0A        if (mAuthToken != null && !mAuthToken.isEmpty()) %7B%0A            okhttpBuilder.addInterceptor(new AuthInterceptor(mAuthToken));%0A        %7D%0A%0A        builder.client(okhttpBuilder.build());%0A%0A        retrofit = builder.build();%0A%0A        return retrofit;%0A    %7D%0A%0A    /**%0A     * Create service instance.%0A     *%0A     * @return STKPushService Service.%0A     */%0A    public STKPushService mpesaService() %7B%0A        return getRestAdapter().create(STKPushService.class);%0A    %7D%0A%0A%7D%0A

create retrofit api client class