Java源码示例:retrofit.android.AndroidLog

示例1
private void appelAsynchrone() {
    GithubService githubService = new RestAdapter.Builder()
            .setEndpoint(GithubService.ENDPOINT)
            .setLog(new AndroidLog("retrofit"))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build()
            .create(GithubService.class);

    githubService.listReposAsync("florent37", new Callback<List<Repo>>() {
        @Override
        public void success(List<Repo> repos, Response response) {
            afficherRepos(repos);
        }

        @Override
        public void failure(RetrofitError error) {

        }
    });
}
 
示例2
/**
 * Créé le GithubService via Retrofit, qui réaliser les appels webservices,
 * en utilisant le StorageModule afin de gérer les clés
 *
 * @param storage le Storage injecté par Dagger2 via le StorageModule
 */
@Singleton
@Provides
public GithubService provideGithubService(final Storage storage) {
    return new RestAdapter.Builder()
            .setEndpoint(BuildConfig.URL_GITHUB)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setLog(new AndroidLog("Retrofit"))
            .setRequestInterceptor(new RequestInterceptor() {
                @Override
                public void intercept(RequestFacade request) {
                    String key = storage.getApiKey();
                    if (key != null) {
                        //ajoute aux header la ApiKey en clé bearer
                        request.addHeader("bearer", key);
                    }
                }
            })
            .build()
            .create(GithubService.class);
}
 
示例3
@Provides @Singleton
public ApiService provideApiService() {
    if(mockMode) {
        return new MockApiService();
    }
    else {
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();
        return new RestAdapter.Builder()
                .setEndpoint(ApiService.API_URL)
                .setConverter(new GsonConverter(gson))
                .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("API"))
                .build()
                .create(ApiService.class);
    }
}
 
示例4
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = (TextView) findViewById(R.id.textView);

    githubService = new RestAdapter.Builder()
            .setEndpoint(GithubService.ENDPOINT)
            .setLog(new AndroidLog("retrofit"))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build()
            .create(GithubService.class);

    getListRepos();
}
 
示例5
private YoutubeApi(){
    youtubeService = new RestAdapter.Builder()
            .setEndpoint(BuildConfig.YOUTUBE_API_URL)
            .setLog(new AndroidLog("Retrofit"))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setRequestInterceptor(new RequestInterceptor() {
                @Override
                public void intercept(RequestFacade request) {
                    request.addQueryParam("key", BuildConfig.YOUTUBE_KEY);
                }
            })
            .build()
            .create(YoutubeService.class);
}
 
示例6
private void rebuildClient() {

        RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint("http://"+host)
            .setConverter(new GsonConverter(realmGson))
            .setLogLevel(RestAdapter.LogLevel.HEADERS)
            .setLog(new AndroidLog("wow-api"))
            .build();
        apiClient = adapter.create(BlizzardApiClient.class);
    }
 
示例7
private RestAdapter.Builder authoirizeAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(authorizationRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例8
private RestAdapter.Builder getBgAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(getBgRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例9
@Provides @Singleton
public ApiService provideApiService() {
    Gson gson = new GsonBuilder()
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .create();
    return new RestAdapter.Builder()
            .setEndpoint(ApiService.API_URL)
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("API"))
            .build()
            .create(ApiService.class);
}
 
示例10
private RestAdapter.Builder authoirizeAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(authorizationRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例11
private RestAdapter.Builder getBgAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(getBgRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例12
private RestAdapter.Builder authoirizeAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(authorizationRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例13
private RestAdapter.Builder getBgAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(getBgRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
示例14
private NetworkManager(BaseContext baseContext) {
    this.baseContext = baseContext;
    restAdapter = new RestAdapter.Builder()
            .setClient(new RetrofitHttpClient())
            .setEndpoint(Config.BASE_URL)
            .setConverter(new JacksonConverter(JsonHelper.getObjectMapper()))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setLog(new AndroidLog("=NETWORK="))
            .build();
}