GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ref: abstract creation of GithubService · MStart/RxJava-Android-Samples@0b8efac

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/morihacky/android/rxjava/retrofit
    • GithubService.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/retrofit/GithubService.java‎

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.morihacky.android.rxjava.retrofit;
2+
3+
import android.text.TextUtils;
4+
5+
import java.io.IOException;
6+
7+
import okhttp3.Interceptor;
8+
import okhttp3.OkHttpClient;
9+
import okhttp3.Request;
10+
import okhttp3.Response;
11+
import retrofit2.GsonConverterFactory;
12+
import retrofit2.Retrofit;
13+
import retrofit2.RxJavaCallAdapterFactory;
14+
15+
import static java.lang.String.format;
16+
17+
public class GithubService {
18+
19+
private GithubService() { }
20+
21+
public static GithubApi createGithubService(final String githubToken) {
22+
Retrofit.Builder builder = new Retrofit.Builder().addCallAdapterFactory(RxJavaCallAdapterFactory.create())
23+
.addConverterFactory(GsonConverterFactory.create())
24+
.baseUrl("https://api.github.com");
25+
26+
if (!TextUtils.isEmpty(githubToken)) {
27+
28+
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
29+
@Override public Response intercept(Chain chain) throws IOException {
30+
Request request = chain.request();
31+
Request newReq = request.newBuilder()
32+
.addHeader("Authorization", format("token %s", githubToken))
33+
.build();
34+
return chain.proceed(newReq);
35+
}
36+
}).build();
37+
38+
builder.client(client);
39+
}
40+
41+
return builder.build().create(GithubApi.class);
42+
}
43+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.