Advertisement
Guest User

RetrofitClient.kt

a guest
Sep 14th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.22 KB | None | 0 0
  1. package com.joaomartins.srodkitrwale
  2.  
  3. import android.util.Base64
  4. import retrofit2.Retrofit
  5. import retrofit2.converter.gson.GsonConverterFactory
  6. import okhttp3.OkHttpClient
  7. import okhttp3.logging.HttpLoggingInterceptor
  8. import java.util.*
  9.  
  10.  
  11. //val cred = username + ":" + password
  12. //val AUTH = Base64.encodeToString(cred.getBytes(), Base64.DEFAULT).replace("\n", "")
  13.  
  14.  
  15. class RetrofitClient {
  16.     // Initializing Retrofit
  17.     fun init() : Retrofit{
  18.  
  19.         // Creating the instance of an Interceptor
  20.         val logging = HttpLoggingInterceptor()
  21.         logging.level = HttpLoggingInterceptor.Level.BODY
  22.         // Creating the OkHttp Builder
  23.         val client = OkHttpClient.Builder()
  24.                 .addInterceptor(logging)
  25.                 .build()
  26.         // Creating the instance of a Builder
  27.         return Retrofit.Builder()
  28.                 .baseUrl("https://srodki.herokuapp.com/")   // The API server
  29.                 .client(client)                                     // Adding Http Client
  30.                 .addConverterFactory(GsonConverterFactory.create()) // Object Converter
  31.                 .build()
  32.     }
  33.  
  34.     fun providesGetLogin(retrofit: Retrofit): GET_LOGIN = retrofit.create(GET_LOGIN::class.java)
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement