module Octokit::Client::Gists

Methods for the Gists API

@see developer.github.com/v3/gists/

Public Instance Methods

create_gist(options = {}) click to toggle source

Create a gist

@param options [Hash] Gist information. @option options [String] :description @option options [Boolean] :public Sets gist visibility @option options [Array<Hash>] :files 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.

@return [Sawyer::Resource] Newly created gist info @see developer.github.com/v3/gists/#create-a-gist

# File lib/octokit/client/gists.rb, line 71
def create_gist(options = {})
  post 'gists', options
end
create_gist_comment(gist_id, comment, options = {}) click to toggle source

Create gist comment

Requires authenticated client.

@param gist_id [String] Id of the gist. @param comment [String] Comment contents. @return [Sawyer::Resource] Hash representing the new comment. @see developer.github.com/v3/gists/comments/#create-a-comment @example

@client.create_gist_comment('3528645', 'This is very helpful.')
# 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 = {}) click to toggle source

Delete a gist

@param gist [String] Gist ID @return [Boolean] Indicating success of deletion @see developer.github.com/v3/gists/#delete-a-gist

# 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 = {}) click to toggle source

Delete gist comment

Requires authenticated client.

@param gist_id [String] Id of the gist. @param gist_comment_id [Integer] Id of the gist comment to delete. @return [Boolean] True if comment deleted, false otherwise. @see developer.github.com/v3/gists/comments/#delete-a-comment @example

@client.delete_gist_comment('208sdaz3', '586399')
# 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 = {}) click to toggle source

Edit a gist

@param options [Hash] Gist information. @option options [String] :description @option options [Hash] :files 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.

@return

[Sawyer::Resource] Newly created gist info

@see developer.github.com/v3/gists/#edit-a-gist @example Update a gist

@client.edit_gist('some_id', {
  :files => {"boo.md" => {"content" => "updated stuff"}}
})
# File lib/octokit/client/gists.rb, line 93
def edit_gist(gist, options = {})
  patch "gists/#{Gist.new(gist)}", options
end
fork_gist(gist, options = {}) click to toggle source

Fork a gist

@param gist [String] Gist ID @return [Sawyer::Resource] Data for the new gist @see developer.github.com/v3/gists/#fork-a-gist

# File lib/octokit/client/gists.rb, line 141
def fork_gist(gist, options = {})
  post "gists/#{Gist.new(gist)}/forks", options
end
gist(gist, options = {}) click to toggle source

Get a single gist

@param gist [String] ID of gist to fetch @option options [String] :sha Specific gist revision SHA @return [Sawyer::Resource] Gist information @see developer.github.com/v3/gists/#get-a-single-gist @see developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist

# 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 = {}) click to toggle source

Get gist comment

@param gist_id [String] Id of the gist. @param gist_comment_id [Integer] Id of the gist comment. @return [Sawyer::Resource] Hash representing gist comment. @see developer.github.com/v3/gists/comments/#get-a-single-comment @example

Octokit.gist_comment('208sdaz3', 1451398)
# 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 = {}) click to toggle source

List gist comments

@param gist_id [String] Gist Id. @return [Array<Sawyer::Resource>] Array of hashes representing comments. @see developer.github.com/v3/gists/comments/#list-comments-on-a-gist @example

Octokit.gist_comments('3528ae645')
# 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 = {}) click to toggle source

List gist commits

@param gist [String] Gist ID @return [Array] List of commits to the gist @see developer.github.com/v3/gists/#list-gist-commits @example List commits for a gist

@client.gist_commits('some_id')
# 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 = {}) click to toggle source

List gist forks

@param gist [String] Gist ID @return [Array] List of gist forks @see developer.github.com/v3/gists/#list-gist-forks @example List gist forks

@client.gist_forks('some-id')
# 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 = {}) click to toggle source

Check if a gist is starred

@param gist [String] Gist ID @return [Boolean] Indicates if gist is starred @see developer.github.com/v3/gists/#check-if-a-gist-is-starred

# 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 = {}) click to toggle source

List gists for a user or all public gists

@param user [String] An optional user to filter listing @return [Array<Sawyer::Resource>] A list of gists @example Fetch all gists for defunkt

Octokit.gists('defunkt')

@example Fetch all public gists

Octokit.gists

@see developer.github.com/v3/gists/#list-gists

# 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
Also aliased as: list_gists
list_gists(user=nil, options = {})
Alias for: gists
public_gists(options = {}) click to toggle source

List public gists

@return [Array<Sawyer::Resource>] A list of gists @example Fetch all public gists

Octokit.public_gists

@see developer.github.com/v3/gists/#list-gists

# File lib/octokit/client/gists.rb, line 33
def public_gists(options = {})
  paginate 'gists/public', options
end
star_gist(gist, options = {}) click to toggle source

Star a gist

@param gist [String] Gist ID @return [Boolean] Indicates if gist is starred successfully @see developer.github.com/v3/gists/#star-a-gist

# 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 = {}) click to toggle source

List the authenticated user’s starred gists

@return [Array<Sawyer::Resource>] A list of gists @see developer.github.com/v3/gists/#list-gists

# File lib/octokit/client/gists.rb, line 41
def starred_gists(options = {})
  paginate 'gists/starred', options
end
unstar_gist(gist, options = {}) click to toggle source

Unstar a gist

@param gist [String] Gist ID @return [Boolean] Indicates if gist is unstarred successfully @see developer.github.com/v3/gists/#unstar-a-gist

# 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 = {}) click to toggle source

Update gist comment

Requires authenticated client

@param gist_id [String] Id of the gist. @param gist_comment_id [Integer] Id of the gist comment to update. @param comment [String] Updated comment contents. @return [Sawyer::Resource] Hash representing the updated comment. @see developer.github.com/v3/gists/comments/#edit-a-comment @example

@client.update_gist_comment('208sdaz3', '3528645', ':heart:')
# 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