Module: Octokit::Client::Gists

Included in:
Octokit::Client
Defined in:
lib/octokit/client/gists.rb

Overview

Methods for the Gists API

Instance Method Summary collapse

Instance Method Details

#create_gist(options = {}) ⇒ Sawyer::Resource

Create a gist

Parameters:

  • options (Hash) (defaults to: {})

    Gist information.

Options Hash (options):

  • :description (String)
  • :public (Boolean)

    Sets gist visibility

  • :files (Array<Hash>)

    Files that make up this gist. Keys should be the filename, the value a Hash with a :content key with text content of the Gist.

Returns:

  • (Sawyer::Resource)

    Newly created gist info

See Also:



71
72
73
# File 'lib/octokit/client/gists.rb', line 71

def create_gist(options = {})
  post 'gists', options
end

#create_gist_comment(gist_id, comment, options = {}) ⇒ Sawyer::Resource

Create gist comment

Requires authenticated client.

Examples:

@client.create_gist_comment('3528645', 'This is very helpful.')

Parameters:

  • gist_id (String)

    Id of the gist.

  • comment (String)

    Comment contents.

Returns:

  • (Sawyer::Resource)

    Hash representing the new comment.

See Also:



198
199
200
201
# File 'lib/octokit/client/gists.rb', line 198

def create_gist_comment(gist_id, comment, options = {})
  options = options.merge({ body: comment })
  post "gists/#{gist_id}/comments", options
end

#delete_gist(gist, options = {}) ⇒ Boolean

Delete a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicating success of deletion

See Also:



161
162
163
# File 'lib/octokit/client/gists.rb', line 161

def delete_gist(gist, options = {})
  boolean_from_response :delete, "gists/#{Gist.new(gist)}", options
end

#delete_gist_comment(gist_id, gist_comment_id, options = {}) ⇒ Boolean

Delete gist comment

Requires authenticated client.

Examples:

@client.delete_gist_comment('208sdaz3', '586399')

Parameters:

  • gist_id (String)

    Id of the gist.

  • gist_comment_id (Integer)

    Id of the gist comment to delete.

Returns:

  • (Boolean)

    True if comment deleted, false otherwise.

See Also:



229
230
231
# File 'lib/octokit/client/gists.rb', line 229

def delete_gist_comment(gist_id, gist_comment_id, options = {})
  boolean_from_response(:delete, "gists/#{gist_id}/comments/#{gist_comment_id}", options)
end

#edit_gist(gist, options = {}) ⇒ Object

Edit a gist

Examples:

Update a gist

@client.edit_gist('some_id', {
  :files => {"boo.md" => {"content" => "updated stuff"}}
})

Parameters:

  • options (Hash) (defaults to: {})

    Gist information.

Options Hash (options):

  • :description (String)
  • :files (Hash)

    Files that make up this gist. Keys should be the filename, the value a Hash with a :content key with text content of the Gist.

    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.

Returns:

  • [Sawyer::Resource] Newly created gist info

See Also:



93
94
95
# File 'lib/octokit/client/gists.rb', line 93

def edit_gist(gist, options = {})
  patch "gists/#{Gist.new(gist)}", options
end

#fork_gist(gist, options = {}) ⇒ Sawyer::Resource

Fork a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Sawyer::Resource)

    Data for the new gist

See Also:



141
142
143
# File 'lib/octokit/client/gists.rb', line 141

def fork_gist(gist, options = {})
  post "gists/#{Gist.new(gist)}/forks", options
end

#gist(gist, options = {}) ⇒ Sawyer::Resource

Get a single gist

Parameters:

  • gist (String)

    ID of gist to fetch

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :sha (String)

    Specific gist revision SHA

Returns:

  • (Sawyer::Resource)

    Gist information

See Also:



52
53
54
55
56
57
58
59
# File 'lib/octokit/client/gists.rb', line 52

def gist(gist, options = {})
  options = options.dup
  if sha = options.delete(:sha)
    get "gists/#{Gist.new(gist)}/#{sha}", options
  else
    get "gists/#{Gist.new(gist)}", options
  end
end

#gist_comment(gist_id, gist_comment_id, options = {}) ⇒ Sawyer::Resource

Get gist comment

Examples:

Octokit.gist_comment('208sdaz3', 1451398)

Parameters:

  • gist_id (String)

    Id of the gist.

  • gist_comment_id (Integer)

    Id of the gist comment.

Returns:

  • (Sawyer::Resource)

    Hash representing gist comment.

See Also:



184
185
186
# File 'lib/octokit/client/gists.rb', line 184

def gist_comment(gist_id, gist_comment_id, options = {})
  get "gists/#{gist_id}/comments/#{gist_comment_id}", options
end

#gist_comments(gist_id, options = {}) ⇒ Array<Sawyer::Resource>

List gist comments

Examples:

Octokit.gist_comments('3528ae645')

Parameters:

  • gist_id (String)

    Gist Id.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing comments.

See Also:



172
173
174
# File 'lib/octokit/client/gists.rb', line 172

def gist_comments(gist_id, options = {})
  paginate "gists/#{gist_id}/comments", options
end

#gist_commits(gist, options = {}) ⇒ Array

List gist commits

Examples:

List commits for a gist

@client.gist_commits('some_id')

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Array)

    List of commits to the gist

See Also:



104
105
106
# File 'lib/octokit/client/gists.rb', line 104

def gist_commits(gist, options = {})
  paginate "gists/#{Gist.new(gist)}/commits", options
end

#gist_forks(gist, options = {}) ⇒ Array

List gist forks

Examples:

List gist forks

@client.gist_forks('some-id')

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Array)

    List of gist forks

See Also:



152
153
154
# File 'lib/octokit/client/gists.rb', line 152

def gist_forks(gist, options = {})
  paginate "gists/#{Gist.new(gist)}/forks", options
end

#gist_starred?(gist, options = {}) ⇒ Boolean

Check if a gist is starred

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicates if gist is starred

See Also:



132
133
134
# File 'lib/octokit/client/gists.rb', line 132

def gist_starred?(gist, options = {})
  boolean_from_response :get, "gists/#{Gist.new(gist)}/star", options
end

#gists(user = nil, options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_gists

List gists for a user or all public gists

Examples:

Fetch all gists for defunkt

Octokit.gists('defunkt')

Fetch all public gists

Octokit.gists

Parameters:

  • user (String) (defaults to: nil)

    An optional user to filter listing

Returns:

  • (Array<Sawyer::Resource>)

    A list of gists

See Also:



18
19
20
21
22
23
24
# File 'lib/octokit/client/gists.rb', line 18

def gists(user = nil, options = {})
  if user.nil?
    paginate 'gists', options
  else
    paginate "#{User.path user}/gists", options
  end
end

#public_gists(options = {}) ⇒ Array<Sawyer::Resource>

List public gists

Examples:

Fetch all public gists

Octokit.public_gists

Returns:

  • (Array<Sawyer::Resource>)

    A list of gists

See Also:



33
34
35
# File 'lib/octokit/client/gists.rb', line 33

def public_gists(options = {})
  paginate 'gists/public', options
end

#star_gist(gist, options = {}) ⇒ Boolean

Star a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicates if gist is starred successfully

See Also:



114
115
116
# File 'lib/octokit/client/gists.rb', line 114

def star_gist(gist, options = {})
  boolean_from_response :put, "gists/#{Gist.new(gist)}/star", options
end

#starred_gists(options = {}) ⇒ Array<Sawyer::Resource>

List the authenticated user’s starred gists

Returns:

  • (Array<Sawyer::Resource>)

    A list of gists

See Also:



41
42
43
# File 'lib/octokit/client/gists.rb', line 41

def starred_gists(options = {})
  paginate 'gists/starred', options
end

#unstar_gist(gist, options = {}) ⇒ Boolean

Unstar a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicates if gist is unstarred successfully

See Also:



123
124
125
# File 'lib/octokit/client/gists.rb', line 123

def unstar_gist(gist, options = {})
  boolean_from_response :delete, "gists/#{Gist.new(gist)}/star", options
end

#update_gist_comment(gist_id, gist_comment_id, comment, options = {}) ⇒ Sawyer::Resource

Update gist comment

Requires authenticated client

Examples:

@client.update_gist_comment('208sdaz3', '3528645', ':heart:')

Parameters:

  • gist_id (String)

    Id of the gist.

  • gist_comment_id (Integer)

    Id of the gist comment to update.

  • comment (String)

    Updated comment contents.

Returns:

  • (Sawyer::Resource)

    Hash representing the updated comment.

See Also:



214
215
216
217
# File 'lib/octokit/client/gists.rb', line 214

def update_gist_comment(gist_id, gist_comment_id, comment, options = {})
  options = options.merge({ body: comment })
  patch "gists/#{gist_id}/comments/#{gist_comment_id}", options
end