@@ -42,6 +42,7 @@ dependencies {
|
||
| 42 | 42 |
compile 'com.jakewharton:butterknife:8.2.1' |
| 43 | 43 |
apt 'com.jakewharton:butterknife-compiler:8.2.1' |
| 44 | 44 |
compile 'com.squareup.okhttp3:okhttp:3.4.1' |
| 45 |
+ compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' |
|
| 45 | 46 |
compile 'com.squareup.retrofit2:retrofit:2.1.0' |
| 46 | 47 |
compile 'com.google.code.gson:gson:2.7' |
| 47 | 48 |
compile 'com.squareup.retrofit2:converter-gson:2.1.0' |
@@ -0,0 +1,54 @@ |
||
| 1 |
+package ai.pai.lensman.box; |
|
| 2 |
+ |
|
| 3 |
+import com.google.gson.GsonBuilder; |
|
| 4 |
+ |
|
| 5 |
+import java.io.IOException; |
|
| 6 |
+import java.util.concurrent.TimeUnit; |
|
| 7 |
+ |
|
| 8 |
+import ai.pai.lensman.BuildConfig; |
|
| 9 |
+import okhttp3.Interceptor; |
|
| 10 |
+import okhttp3.OkHttpClient; |
|
| 11 |
+import okhttp3.Request; |
|
| 12 |
+import okhttp3.Response; |
|
| 13 |
+import okhttp3.logging.HttpLoggingInterceptor; |
|
| 14 |
+import retrofit2.Retrofit; |
|
| 15 |
+import retrofit2.converter.gson.GsonConverterFactory; |
|
| 16 |
+ |
|
| 17 |
+public final class ApiClient {
|
|
| 18 |
+ |
|
| 19 |
+ private static final String BASE_URL = ""; |
|
| 20 |
+ |
|
| 21 |
+ private static final OkHttpClient client = new OkHttpClient.Builder() |
|
| 22 |
+ .retryOnConnectionFailure(true) |
|
| 23 |
+ .connectTimeout(10, TimeUnit.SECONDS) |
|
| 24 |
+ .addInterceptor(createUserAgentInterceptor()) |
|
| 25 |
+ .addInterceptor(createHttpLoggingInterceptor()) |
|
| 26 |
+ .build(); |
|
| 27 |
+ |
|
| 28 |
+ public static final ApiService service = new Retrofit.Builder() |
|
| 29 |
+ .baseUrl(BASE_URL) |
|
| 30 |
+ .client(client) |
|
| 31 |
+ .addConverterFactory(GsonConverterFactory.create( new GsonBuilder().create())) |
|
| 32 |
+ .build() |
|
| 33 |
+ .create(ApiService.class); |
|
| 34 |
+ |
|
| 35 |
+ private static Interceptor createUserAgentInterceptor() {
|
|
| 36 |
+ return new Interceptor() {
|
|
| 37 |
+ |
|
| 38 |
+ @Override |
|
| 39 |
+ public Response intercept(Chain chain) throws IOException {
|
|
| 40 |
+ Request request = chain.request().newBuilder() |
|
| 41 |
+ .build(); |
|
| 42 |
+ return chain.proceed(request); |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ }; |
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ private static Interceptor createHttpLoggingInterceptor() {
|
|
| 49 |
+ HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); |
|
| 50 |
+ loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE); |
|
| 51 |
+ return loggingInterceptor; |
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+} |
@@ -0,0 +1,17 @@ |
||
| 1 |
+package ai.pai.lensman.box; |
|
| 2 |
+ |
|
| 3 |
+import retrofit2.Call; |
|
| 4 |
+import retrofit2.http.GET; |
|
| 5 |
+import retrofit2.http.Query; |
|
| 6 |
+ |
|
| 7 |
+public interface ApiService {
|
|
| 8 |
+ |
|
| 9 |
+ |
|
| 10 |
+ @GET("session/new")
|
|
| 11 |
+ Call<String> startNewSession( |
|
| 12 |
+ @Query("sessionId") String sessionId
|
|
| 13 |
+ |
|
| 14 |
+ ); |
|
| 15 |
+ |
|
| 16 |
+ |
|
| 17 |
+} |