@@ -44,13 +44,18 @@ public final class RetrofitHelper {
4444 *
4545 * @return the api helper
4646 */
47- public static APIRequestInterface getApiHelper (String baseUrl , Context context , Boolean debugMode , String packageId , @ Nullable AppCompatActivity activity ) {
47+ public static APIRequestInterface getApiHelper (String baseUrl , Context context , Boolean debugMode , String packageId , @ Nullable AppCompatActivity activity , @ Nullable String authtoken ) {
4848 if (retrofit == null ) {
4949 if (NetworkApp .getAuthToken () == null ) {
5050 throw new NoAuthTokenProvidedException ();
5151 }
5252
53- okHttpClient = getOkHttpClient (context , debugMode , packageId );
53+ if (authtoken .contains ("pk" )){
54+ okHttpClient = getOkHttpClientPK (context , debugMode , packageId );
55+ }else {
56+
57+ okHttpClient = getOkHttpClient (context , debugMode , packageId );
58+ }
5459
5560 retrofit = new Retrofit .Builder ()
5661 .baseUrl (baseUrl )
@@ -160,6 +165,54 @@ private static OkHttpClient getOkHttpClient(Context context, Boolean debugMode,
160165*/
161166 return httpClientBuilder .build ();
162167 }
168+ private static OkHttpClient getOkHttpClientPK (Context context , Boolean debugMode , String packageId ) {
169+ OkHttpClient .Builder httpClientBuilder = new OkHttpClient .Builder ();
170+
171+ httpClientBuilder .connectTimeout (30 , TimeUnit .SECONDS );
172+ httpClientBuilder .readTimeout (30 , TimeUnit .SECONDS );
173+
174+ httpClientBuilder .addInterceptor (chain -> {
175+ Request request = chain .request ()
176+ .newBuilder ()
177+ // .addHeader(APIConstants.TOKEN_PREFIX, APIConstants.AUTH_TOKEN_PREFIX + NetworkApp.getHeaderToken())
178+ .addHeader (APIConstants .AUTH_TOKEN_KEY , NetworkApp .getAuthToken ())
179+ .addHeader (APIConstants .PACKAGE_ID , NetworkApp .getPackageId ())
180+ .addHeader (APIConstants .SESSION_PREFIX , NetworkApp .getHeaderToken ())
181+ .addHeader (APIConstants .APPLICATION , NetworkApp .getApplicationInfo ())
182+ .addHeader (APIConstants .ACCEPT_KEY , APIConstants .ACCEPT_VALUE )
183+ .addHeader (APIConstants .CONTENT_TYPE_KEY , APIConstants .CONTENT_TYPE_VALUE )
184+ .addHeader (APIConstants .IP_ADDRESS , NetworkApp .getUserIpAddress ())
185+
186+ .build ();
187+ if (debugMode ) {
188+ Log .e ("dataRequestBody Request" , String .valueOf (request .toString ()));
189+ if (request .body () != null ) {
190+ Log .e ("dataRequestBody body" , bodyToString (request .body ()));
191+ }
192+
193+ Log .e ("dataRequestBody Headers" , String .valueOf (request .headers ().toString ()));
194+ Response response = chain .proceed (request );
195+ try {
196+ Log .e ("dataRequestBody" , response .toString ());
197+ } catch (Exception ex ) {
198+ return response ;
199+ }
200+ }
201+
202+ return chain .proceed (request );
203+ });
204+ httpClientBuilder .addInterceptor (new HttpLoggingInterceptor ().setLevel (HttpLoggingInterceptor .Level .BODY ));
205+
206+ /* if(debugMode|| NetworkApp.debugMode){
207+ httpClientBuilder.addInterceptor(getLogging(debugMode));
208+
209+ }else{
210+ httpClientBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(!BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.NONE : HttpLoggingInterceptor.Level.NONE));
211+
212+ }
213+ */
214+ return httpClientBuilder .build ();
215+ }
163216
164217 public static HttpLoggingInterceptor getLogging (Boolean debugMode ) {
165218 HttpLoggingInterceptor logging = new HttpLoggingInterceptor (new HttpLoggingInterceptor .Logger () {
0 commit comments