@@ -9,6 +9,7 @@ Github4s supports the [Gist API](https://developer.github.com/v3/gists/). As a r
99with Github4s, you can:
1010
1111- [ Create a gist] ( #create-a-gist )
12+ - [ Get a single gist or specific revision of a gist] ( #get-a-gist )
1213
1314The following examples assume the following imports and token:
1415
@@ -58,6 +59,70 @@ The `result` on the right is the created [Gist][gist-scala].
5859
5960See [ the API doc] ( https://developer.github.com/v3/gists/#create-a-gist ) for full reference.
6061
62+ ## Get a single gist or specific revision of a gist
63+
64+ You can create a gist using ` getGist ` ; it takes as arguments:
65+
66+ - the gist id (obtained via [ creation of a gist] ( #create-a-gist ) , for ex.).
67+ - optional sha of the gist revision.
68+
69+ To get a single gist:
70+
71+ ``` scala
72+ val singleGist = Github (accessToken).gists.getGist(" aa5a315d61ae9438b18d" )
73+
74+ singleGist.exec[cats.Id , HttpResponse [String ]]() match {
75+ case Left (e) => println(s " Something went wrong: ${e.getMessage}" )
76+ case Right (r) => println(r.result)
77+ }
78+ ```
79+
80+ Similarly, to get a specific revision of a gist:
81+
82+ ``` scala
83+ val sepcificRevisionGist = Github (accessToken).gists.getGist(" aa5a315d61ae9438b18d" , Some (" 4e481528046a016fc11d6e7d8d623b55ea11e372" ))
84+
85+ sepcificRevisionGist.exec[cats.Id , HttpResponse [String ]]() match {
86+ case Left (e) => println(s " Something went wrong: ${e.getMessage}" )
87+ case Right (r) => println(r.result)
88+ }
89+ ```
90+
91+ The ` result ` on the right is the requested [ Gist] [ gist-scala ] .
92+
93+ See [ the API doc] ( https://developer.github.com/v3/gists/#get-a-single-gist ) for full reference.
94+
95+ ## Edit a gist
96+
97+ You can edit a gist using ` editGist ` ; it takes as arguments:
98+
99+ - the gist id (obtained via [ creation of a gist] ( #create-a-gist ) , for ex.).
100+ - the gist description.
101+ - an association of file names and optional file contents where the contents are wrapped in
102+ [ EditGistFile] [ gist-scala ] s, if a new file name required, then it must be provided.
103+
104+ To edit a gist (change description, update content of _ token.scala_ , rename _ gh4s.scala_ and remove _ token.class_ file):
105+
106+ ``` scala
107+ import github4s .free .domain .EditGistFile
108+ val files = Map (
109+ " token.scala" -> Some (EditGistFile (" lazy val accessToken = sys.env.get(\" GITHUB4S_ACCESS_TOKEN\" )" )),
110+ " gh4s.scala" -> Some (EditGistFile (" val gh = Github(accessToken)" , Some (" GH4s.scala" ))),
111+ " token.class" -> None
112+ )
113+
114+ val updatedGist = Github (accessToken).gists.editGist(" aa5a315d61ae9438b18d" , " Updated github4s entry point" , files)
115+
116+ updatedGist.exec[cats.Id , HttpResponse [String ]]() match {
117+ case Left (e) => println(s " Something went wrong: ${e.getMessage}" )
118+ case Right (r) => println(r.result)
119+ }
120+ ```
121+
122+ The ` result ` on the right is the updated [ Gist] [ gist-scala ] .
123+
124+ See [ the API doc] ( https://developer.github.com/v3/gists/#edit-a-gist ) for full reference.
125+
61126As you can see, a few features of the gist endpoint are missing. As a result, if you'd like to see a
62127feature supported, feel free to create an issue and/or a pull request!
63128
0 commit comments