MCPcopy Create free account
hub / github.com/JakeWharton/u2020 / ApiModule

Class ApiModule

app/src/main/java/com/jakewharton/u2020/data/api/ApiModule.java:16–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14import retrofit2.converter.moshi.MoshiConverterFactory;
15
16@Module(
17 complete = false,
18 library = true,
19 injects = {
20 OauthService.class
21 }
22)
23public final class ApiModule {
24 public static final HttpUrl PRODUCTION_API_URL = HttpUrl.parse("https://api.github.com/");
25
26 @Provides @Singleton HttpUrl provideBaseUrl() {
27 return PRODUCTION_API_URL;
28 }
29
30 @Provides @Singleton @Named("Api") OkHttpClient provideApiClient(OkHttpClient client,
31 OauthInterceptor oauthInterceptor) {
32 return createApiClient(client, oauthInterceptor).build();
33 }
34
35 @Provides @Singleton Retrofit provideRetrofit(HttpUrl baseUrl, @Named("Api") OkHttpClient client,
36 Moshi moshi) {
37 return new Retrofit.Builder() //
38 .client(client) //
39 .baseUrl(baseUrl) //
40 .addConverterFactory(MoshiConverterFactory.create(moshi)) //
41 .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) //
42 .build();
43 }
44
45 @Provides @Singleton GithubService provideGithubService(Retrofit retrofit) {
46 return retrofit.create(GithubService.class);
47 }
48
49 static OkHttpClient.Builder createApiClient(OkHttpClient client, OauthInterceptor oauthInterceptor) {
50 return client.newBuilder()
51 .addInterceptor(oauthInterceptor);
52 }
53}

Callers

nothing calls this directly

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected