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 ;
@@ -42,12 +40,28 @@ class Contributor {
4240 String login ;
4341 }
4442
43+ class Issue {
44+
45+ Issue () {
46+
47+ }
48+
49+ String title ;
50+ String body ;
51+ List <String > assignees ;
52+ int milestone ;
53+ List <String > labels ;
54+ }
55+
4556 @ RequestLine ("GET /users/{username}/repos?sort=full_name" )
4657 List <Repository > repos (@ Param ("username" ) String owner );
4758
4859 @ RequestLine ("GET /repos/{owner}/{repo}/contributors" )
4960 List <Contributor > contributors (@ Param ("owner" ) String owner , @ Param ("repo" ) String repo );
5061
62+ @ RequestLine ("POST /repos/{owner}/{repo}/issues" )
63+ void createIssue (Issue issue , @ Param ("owner" ) String owner , @ Param ("repo" ) String repo );
64+
5165 /** Lists all contributors for all repos owned by a user. */
5266 default List <String > contributors (String owner ) {
5367 return repos (owner ).stream ()
@@ -59,7 +73,9 @@ default List<String> contributors(String owner) {
5973
6074 static GitHub connect () {
6175 Decoder decoder = new GsonDecoder ();
76+ Encoder encoder = new GsonEncoder ();
6277 return Feign .builder ()
78+ .encoder (encoder )
6379 .decoder (decoder )
6480 .errorDecoder (new GitHubErrorDecoder (decoder ))
6581 .logger (new Logger .ErrorLogger ())
@@ -101,6 +117,16 @@ public static void main(String... args) {
101117 } catch (GitHubClientError e ) {
102118 System .out .println (e .getMessage ());
103119 }
120+
121+ System .out .println ("Now, try to create an issue - which will also cause an error." );
122+ try {
123+ GitHub .Issue issue = new GitHub .Issue ();
124+ issue .title = "The title" ;
125+ issue .body = "Some Text" ;
126+ github .createIssue (issue , "OpenFeign" , "SomeRepo" );
127+ } catch (GitHubClientError e ) {
128+ System .out .println (e .getMessage ());
129+ }
104130 }
105131
106132 static class GitHubErrorDecoder implements ErrorDecoder {
0 commit comments