| title | Gists | GitHub API |
|---|
- TOC {:toc}
You can read public gists and create them for anonymous users without a token; however, to read or write gists on a user's behalf the gist OAuth scope is required.
List a user's gists:
GET /users/:user/gists
List the authenticated user's gists or if called anonymously, this will return all public gists:
GET /gists
List all public gists:
GET /gists/public
List the authenticated user's starred gists:
GET /gists/starred
| Name | Type | Description |
|---|---|---|
since |
string |
A timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Only gists updated at or after this time are returned. |
<%= headers 200, :pagination => default_pagination_rels %> <%= json(:gist) { |h| [h] } %>
GET /gists/:id
Note: When using the v3 media type, the user attribute is renamed to owner.
<%= headers 200 %> <%= json :full_gist %>
POST /gists
| Name | Type | Description |
|---|---|---|
files |
hash |
Required. Files that make up this gist. |
description |
string |
A description of the gist. |
public |
boolean |
Indicates whether the gist is public. Default: false |
The keys in the files hash are the string filename, and the value is another hash with a key of content, and a value of the file contents. For example:
<%= json
:description => "the description for this gist",
:public => true,
:files => {
"file1.txt" => {"content" => "String file contents"}
}
%>
Note: Don't name your files "gistfile" with a numerical suffix. This is the format of the automatic naming scheme that Gist uses internally.
<%= headers 201, :Location => "https://api.github.com/gists/1" %> <%= json :full_gist %>
PATCH /gists/:id
| Name | Type | Description |
|---|---|---|
description |
string |
A description of the gist. |
files |
hash |
Files that make up this gist. |
content |
string |
Updated file contents. |
filename |
string |
New name for this file. |
The keys in the files hash are the string filename. The value is another hash with a key of content (indicating the new contents), or filename (indicating the new filename). For example:
<%= json
:description => "the description for this gist",
:files => {
"file1.txt" => {"content" => "updated file contents"},
"old_name.txt" => {"filename" => "new_name.txt", "content" => "modified contents"},
"new_file.txt" => {"content" => "a new file"},
"delete_this_file.txt" => nil,
} %>
NOTE: All files from the previous version of the gist are carried over by
default if not included in the hash. Deletes can be performed by
including the filename with a null hash.
<%= headers 200 %> <%= json :full_gist %>
PUT /gists/:id/star
<%= headers 204 %>
DELETE /gists/:id/star
<%= headers 204 %>
GET /gists/:id/star
<%= headers 204 %>
<%= headers 404 %>
POST /gists/:id/forks
Note: This was previously /gists/:id/fork
<%= headers 201, :Location => "https://api.github.com/gists/2" %> <%= json(:gist) %>
DELETE /gists/:id
<%= headers 204 %>