File tree Expand file tree Collapse file tree 4 files changed +37
-3
lines changed
src/main/java/com/blockscore Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ public final class Constants {
99 public static final String AUTHORIZATION_HEADER = "Authorization" ;
1010 public static final String ACCEPT_HEADER = "Accept" ;
1111 public static final String BLOCKSCORE_DOMAIN = "https://api.blockscore.com" ;
12-
12+ public static final String USER_AGENT = "blockscore-java/4.0.0 (https://github.com/BlockScore/blockscore-java)" ;
13+
1314 private static final String VERSION_CODE = "4" ;
1415 private static final String ACCEPT_CONTENTS = "application/vnd.blockscore+json;version=%s" ;
1516
Original file line number Diff line number Diff line change 1616import retrofit .converter .JacksonConverter ;
1717
1818import java .io .UnsupportedEncodingException ;
19- import java .util .Base64 ;
19+
20+ import javax .xml .bind .DatatypeConverter ;
2021
2122/**
2223 * The Blockscore Java API client.
@@ -152,7 +153,7 @@ public PaginatedResult<Candidate> listCandidates() {
152153 @ NotNull
153154 private String getEncodedAuthorization () {
154155 try {
155- return "Basic " + Base64 . getEncoder (). encodeToString ( apiKey .getBytes ("utf -8" ));
156+ return "Basic " + DatatypeConverter . printBase64Binary ( apiKey .getBytes ("UTF -8" ));
156157 } catch (UnsupportedEncodingException e ) {
157158 throw new RuntimeException (e );
158159 }
Original file line number Diff line number Diff line change 11package com .blockscore .net ;
22
3+ import com .blockscore .common .Constants ;
4+ import com .blockscore .net .UserAgentInterceptor ;
5+
36import com .squareup .okhttp .OkHttpClient ;
47import com .squareup .okhttp .OkUrlFactory ;
58import retrofit .client .Request ;
@@ -28,6 +31,7 @@ private OkHttpClient generateDefaultHttpClient() {
2831 OkHttpClient client = new OkHttpClient ();
2932 client .setConnectTimeout (CONNECT_TIMEOUT_MILLIS , TimeUnit .MILLISECONDS );
3033 client .setReadTimeout (READ_TIMEOUT_MILLIS , TimeUnit .MILLISECONDS );
34+ client .networkInterceptors ().add (new UserAgentInterceptor (Constants .USER_AGENT ));
3135 return client ;
3236 }
3337
Original file line number Diff line number Diff line change 1+ package com .blockscore .net ;
2+
3+ import com .squareup .okhttp .Interceptor ;
4+ import com .squareup .okhttp .Interceptor .Chain ;
5+ import com .squareup .okhttp .Response ;
6+ import com .squareup .okhttp .Request ;
7+
8+ import java .io .IOException ;
9+
10+ class UserAgentInterceptor implements Interceptor {
11+
12+ private final String userAgent ;
13+
14+ public UserAgentInterceptor (String userAgent ) {
15+ this .userAgent = userAgent ;
16+ }
17+
18+ @ Override
19+ public Response intercept (Chain chain ) throws IOException {
20+ Request originalRequest = chain .request ();
21+ Request requestWithUserAgent =
22+ originalRequest .newBuilder ()
23+ .removeHeader ("User-Agent" )
24+ .addHeader ("User-Agent" , userAgent )
25+ .build ();
26+ return chain .proceed (requestWithUserAgent );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments