// Path: baselib/src/main/java/com/wecan/xhin/baselib/net/LoggingInterceptor.java
// public class LoggingInterceptor implements Interceptor {
// 
//     private static final String TAG = "OkHttp";
// 
//     @Override
//     public Response intercept(Chain chain) throws IOException {
//         Request request = chain.request();
// 
//         Log.d(TAG, String.format("%s\n%s", request, request.headers()));
// 
//         Response response = chain.proceed(request);
// 
//         Log.d(TAG, String.format("%s\n%s", response, response.headers()));
// 
//         return response;
//     }
// }
// 
// Path: app/src/main/java/com/wecan/xhin/studio/api/Api.java
// public interface Api {
// 
//     String BASE_URL = "http://121.42.209.19/RestfulApi/index.php/";
// 
//     @GET("api/users")
//     Observable<User> login(@Query("name") String name, @Query("phone") String phone);
// 
//     @POST("api/users")
//     Observable<BaseData> register(@Body RegisterBody registerUser);
// 
//     @PUT("api/users")
//     Observable<User> updateUser(@Body User updateUser);
// 
//     @POST("api/sign")
//     Observable<BaseData> sign(@Body SignBody user);
// 
//     @DELETE("api/sign")
//     Observable<BaseData> unSign(@Query("name") String name);
// 
//     @GET("api/message_all")
//     Observable<UsersData> getAllUser();
// 
//     @GET("api/message")
//     Observable<UsersData> getSignedUser();
// 
//     @GET("api/addplease/{code}")
//     Observable<BaseData> addCode(@Path("code") String code);
// 
// }


import android.app.Application;
import android.content.Context;
import com.avos.avoscloud.AVOSCloud;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Response;
import com.wecan.xhin.baselib.net.LoggingInterceptor;
import com.wecan.xhin.studio.api.Api;
import java.io.IOException;
import java.util.HashMap;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
        super.onCreate();

        AVOSCloud.initialize(this, VALUE_AVOS_APPID, VALUE_AVOS_APPKEY);
        OkHttpClient okHttpClient = new OkHttpClient();
        //OKHttp的使用
        okHttpClient.networkInterceptors().add(new Interceptor() {
            @Override
            public Response intercept(Chain chain) throws IOException {
                return chain.proceed(chain.request().newBuilder()
                        .header(KEY_BUILD_VERSION, BuildConfig.VERSION_NAME)
                        .build());
            }
        });

        if (BuildConfig.DEBUG) {
            okHttpClient.networkInterceptors().add(new LoggingInterceptor());
        }

        //初始化Gson
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setDateFormat(DATE_FORMAT_PATTERN)
                .create();


        //初始化Retrofit
        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// Path: baselib/src/main/java/com/wecan/xhin/baselib/net/LoggingInterceptor.java
// public class LoggingInterceptor implements Interceptor {
// 
//     private static final String TAG = "OkHttp";
// 
//     @Override
//     public Response intercept(Chain chain) throws IOException {
//         Request request = chain.request();
// 
//         Log.d(TAG, String.format("%s\n%s", request, request.headers()));
// 
//         Response response = chain.proceed(request);
// 
//         Log.d(TAG, String.format("%s\n%s", response, response.headers()));
// 
//         return response;
//     }
// }
// 
// Path: app/src/main/java/com/wecan/xhin/studio/api/Api.java
// public interface Api {
// 
//     String BASE_URL = "http://121.42.209.19/RestfulApi/index.php/";
// 
//     @GET("api/users")
//     Observable<User> login(@Query("name") String name, @Query("phone") String phone);
// 
//     @POST("api/users")
//     Observable<BaseData> register(@Body RegisterBody registerUser);
// 
//     @PUT("api/users")
//     Observable<User> updateUser(@Body User updateUser);
// 
//     @POST("api/sign")
//     Observable<BaseData> sign(@Body SignBody user);
// 
//     @DELETE("api/sign")
//     Observable<BaseData> unSign(@Query("name") String name);
// 
//     @GET("api/message_all")
//     Observable<UsersData> getAllUser();
// 
//     @GET("api/message")
//     Observable<UsersData> getSignedUser();
// 
//     @GET("api/addplease/{code}")
//     Observable<BaseData> addCode(@Path("code") String code);
// 
// }


// Path: app/src/main/java/com/wecan/xhin/studio/App.java
import android.app.Application;
import android.content.Context;
import com.avos.avoscloud.AVOSCloud;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Response;
import com.wecan.xhin.baselib.net.LoggingInterceptor;
import com.wecan.xhin.studio.api.Api;
import java.io.IOException;
import java.util.HashMap;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;

        super.onCreate();

        AVOSCloud.initialize(this, VALUE_AVOS_APPID, VALUE_AVOS_APPKEY);
        OkHttpClient okHttpClient = new OkHttpClient();
        //OKHttp的使用
        okHttpClient.networkInterceptors().add(new Interceptor() {
            @Override
            public Response intercept(Chain chain) throws IOException {
                return chain.proceed(chain.request().newBuilder()
                        .header(KEY_BUILD_VERSION, BuildConfig.VERSION_NAME)
                        .build());
            }
        });

        if (BuildConfig.DEBUG) {
            okHttpClient.networkInterceptors().add(new LoggingInterceptor());
        }

        //初始化Gson
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setDateFormat(DATE_FORMAT_PATTERN)
                .create();


        //初始化Retrofit
        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(Api.BASE_URL)