1313 */
1414package example .github ;
1515
16+ import java .io .IOException ;
17+ import java .util .List ;
18+ import java .util .stream .Collectors ;
1619import feign .*;
1720import feign .codec .Decoder ;
1821import feign .codec .Encoder ;
1922import feign .codec .ErrorDecoder ;
2023import feign .gson .GsonDecoder ;
2124import feign .gson .GsonEncoder ;
22- import java .io .IOException ;
23- import java .util .List ;
24- import java .util .stream .Collectors ;
2525
2626/**
2727 * Inspired by {@code com.example.retrofit.GitHubClient}
@@ -72,8 +72,8 @@ default List<String> contributors(String owner) {
7272 }
7373
7474 static GitHub connect () {
75- Decoder decoder = new GsonDecoder ();
76- Encoder encoder = new GsonEncoder ();
75+ final Decoder decoder = new GsonDecoder ();
76+ final Encoder encoder = new GsonEncoder ();
7777 return Feign .builder ()
7878 .encoder (encoder )
7979 .decoder (decoder )
@@ -84,6 +84,8 @@ static GitHub connect() {
8484 if (System .getenv ().containsKey (GITHUB_TOKEN )) {
8585 System .out .println ("Detected Authorization token from environment variable" );
8686 template .header (
87+ // not available when building PRs...
88+ // https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml
8789 "Authorization" ,
8890 "token " + System .getenv (GITHUB_TOKEN ));
8991 }
@@ -103,28 +105,28 @@ public String getMessage() {
103105 }
104106
105107 public static void main (String ... args ) {
106- GitHub github = GitHub .connect ();
108+ final GitHub github = GitHub .connect ();
107109
108110 System .out .println ("Let's fetch and print a list of the contributors to this org." );
109- List <String > contributors = github .contributors ("openfeign" );
110- for (String contributor : contributors ) {
111+ final List <String > contributors = github .contributors ("openfeign" );
112+ for (final String contributor : contributors ) {
111113 System .out .println (contributor );
112114 }
113115
114116 System .out .println ("Now, let's cause an error." );
115117 try {
116118 github .contributors ("openfeign" , "some-unknown-project" );
117- } catch (GitHubClientError e ) {
119+ } catch (final GitHubClientError e ) {
118120 System .out .println (e .getMessage ());
119121 }
120122
121123 System .out .println ("Now, try to create an issue - which will also cause an error." );
122124 try {
123- GitHub .Issue issue = new GitHub .Issue ();
125+ final GitHub .Issue issue = new GitHub .Issue ();
124126 issue .title = "The title" ;
125127 issue .body = "Some Text" ;
126128 github .createIssue (issue , "OpenFeign" , "SomeRepo" );
127- } catch (GitHubClientError e ) {
129+ } catch (final GitHubClientError e ) {
128130 System .out .println (e .getMessage ());
129131 }
130132 }
@@ -144,7 +146,7 @@ public Exception decode(String methodKey, Response response) {
144146 // must replace status by 200 other GSONDecoder returns null
145147 response = response .toBuilder ().status (200 ).build ();
146148 return (Exception ) decoder .decode (response , GitHubClientError .class );
147- } catch (IOException fallbackToDefault ) {
149+ } catch (final IOException fallbackToDefault ) {
148150 return defaultDecoder .decode (methodKey , response );
149151 }
150152 }
0 commit comments