1313 */
1414package example .github ;
1515
16- import feign .Feign ;
17- import feign .Logger ;
18- import feign .Param ;
19- import feign .RequestLine ;
20- import feign .Response ;
16+ import feign .*;
2117import feign .codec .Decoder ;
18+ import feign .codec .Encoder ;
2219import feign .codec .ErrorDecoder ;
2320import feign .gson .GsonDecoder ;
21+ import feign .gson .GsonEncoder ;
2422import java .io .IOException ;
2523import java .util .List ;
2624import java .util .stream .Collectors ;
@@ -40,12 +38,26 @@ class Contributor {
4038 String login ;
4139 }
4240
41+ class Issue {
42+
43+ Issue () {}
44+
45+ String title ;
46+ String body ;
47+ List <String > assignees ;
48+ int milestone ;
49+ List <String > labels ;
50+ }
51+
4352 @ RequestLine ("GET /users/{username}/repos?sort=full_name" )
4453 List <Repository > repos (@ Param ("username" ) String owner );
4554
4655 @ RequestLine ("GET /repos/{owner}/{repo}/contributors" )
4756 List <Contributor > contributors (@ Param ("owner" ) String owner , @ Param ("repo" ) String repo );
4857
58+ @ RequestLine ("POST /repos/{owner}/{repo}/issues" )
59+ void createIssue (Issue issue , @ Param ("owner" ) String owner , @ Param ("repo" ) String repo );
60+
4961 /** Lists all contributors for all repos owned by a user. */
5062 default List <String > contributors (String owner ) {
5163 return repos (owner ).stream ()
@@ -57,7 +69,9 @@ default List<String> contributors(String owner) {
5769
5870 static GitHub connect () {
5971 Decoder decoder = new GsonDecoder ();
72+ Encoder encoder = new GsonEncoder ();
6073 return Feign .builder ()
74+ .encoder (encoder )
6175 .decoder (decoder )
6276 .errorDecoder (new GitHubErrorDecoder (decoder ))
6377 .logger (new Logger .ErrorLogger ())
@@ -97,6 +111,16 @@ public static void main(String... args) {
97111 } catch (GitHubClientError e ) {
98112 System .out .println (e .getMessage ());
99113 }
114+
115+ System .out .println ("Now, try to create an issue - which will also cause an error." );
116+ try {
117+ GitHub .Issue issue = new GitHub .Issue ();
118+ issue .title = "The title" ;
119+ issue .body = "Some Text" ;
120+ github .createIssue (issue , "OpenFeign" , "SomeRepo" );
121+ } catch (GitHubClientError e ) {
122+ System .out .println (e .getMessage ());
123+ }
100124 }
101125
102126 static class GitHubErrorDecoder implements ErrorDecoder {
0 commit comments