Module: Octokit::Client::Gists

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

Instance Method Summary collapse

Instance Method Details

#create_gist(options = {}) ⇒ Hashie::Mash

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 conent of the Gist.

Returns:

  • (Hashie::Mash)

    Newly created gist info

See Also:



59
60
61
# File 'lib/octokit/client/gists.rb', line 59

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

#create_gist_comment(gist_id, comment, options = {}) ⇒ Hashie::Mash

Create gist comment

Requires authenticated client.

Examples:

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

Parameters:

  • gist_id (Integer)

    Id of the gist.

  • comment (String)

    Comment contents.

Returns:

  • (Hashie::Mash)

    Hash representing the new comment.

See Also:



168
169
170
171
# File 'lib/octokit/client/gists.rb', line 168

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

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

Delete a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicating success of deletion

See Also:



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

def delete_gist(gist, options={})
  response = delete("gists/#{Gist.new gist}", options, 3, true, true)
  response.status == 204
end

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

Delete gist comment

Requires authenticated client.

Examples:

@client.delete_gist_comment(586399)

Parameters:

  • gist_comment_id (Integer)

    Id of the gist comment to delete.

Returns:

  • (Boolean)

    True if comment deleted, false otherwise.

See Also:



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

def delete_gist_comment(gist_comment_id, options={})
  delete("gists/comments/#{gist_comment_id}", options, 3, true, true).status == 204
end

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

Edit 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 conent 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:

  • Hashie::Mash

    Newly created gist info

See Also:



78
79
80
# File 'lib/octokit/client/gists.rb', line 78

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

#fork_gist(gist, options = {}) ⇒ Hashie::Mash

Fork a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Hashie::Mash)

    Data for the new gist

See Also:



121
122
123
# File 'lib/octokit/client/gists.rb', line 121

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

#gist(gist, options = {}) ⇒ Hash::Mash

Get a single gist

Parameters:

  • gist (String)

    ID of gist to fetch

Returns:

  • (Hash::Mash)

    Gist information

See Also:



45
46
47
# File 'lib/octokit/client/gists.rb', line 45

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

#gist_comment(gist_comment_id, options = {}) ⇒ Hashie::Mash

Get gist comment

Examples:

Octokit.gist_comment(451398)

Parameters:

  • gist_comment_id (Integer)

    Id of the gist comment.

Returns:

  • (Hashie::Mash)

    Hash representing gist comment.

See Also:



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

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

#gist_comments(gist_id, options = {}) ⇒ Array<Hashie::Mash>

List gist comments

Examples:

Octokit.gist_comments(3528645)

Parameters:

  • gist_id (Integer)

    Gist Id.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing comments.

See Also:



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

def gist_comments(gist_id, options={})
  get "gists/#{gist_id}/comments", options, 3
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:



107
108
109
110
111
112
113
114
# File 'lib/octokit/client/gists.rb', line 107

def gist_starred?(gist, options={})
  begin
    get("gists/#{Gist.new gist}/star", options, 3, true, true)
    return true
  rescue Octokit::NotFound
    return false
  end
end

#gists(username = nil, options = {}) ⇒ Array<Hashie::Mash> 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:

  • username (String) (defaults to: nil)

    An optional user to filter listing

Returns:

  • (Array<Hashie::Mash>)

    A list of gists

See Also:



14
15
16
17
18
19
20
# File 'lib/octokit/client/gists.rb', line 14

def gists(username=nil, options={})
  if username.nil?
    get 'gists', options, 3
  else
    get "users/#{username}/gists", options, 3
  end
end

#public_gists(options = {}) ⇒ Array<Hashie::Mash>

List public gists

Examples:

Fetch all public gists

Octokit.public_gists

Returns:

  • (Array<Hashie::Mash>)

    A list of gists

See Also:



29
30
31
# File 'lib/octokit/client/gists.rb', line 29

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

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

Star a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicates if gist is starred successfully

See Also:



87
88
89
90
# File 'lib/octokit/client/gists.rb', line 87

def star_gist(gist, options={})
  response = put("gists/#{Gist.new gist}/star", options, 3, true, true)
  response.status == 204
end

#starred_gists(options = {}) ⇒ Array<Hashie::Mash>

List the authenticated user’s starred gists

Returns:

  • (Array<Hashie::Mash>)

    A list of gists



36
37
38
# File 'lib/octokit/client/gists.rb', line 36

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

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

Unstar a gist

Parameters:

  • gist (String)

    Gist ID

Returns:

  • (Boolean)

    Indicates if gist is unstarred successfully

See Also:



97
98
99
100
# File 'lib/octokit/client/gists.rb', line 97

def unstar_gist(gist, options={})
  response = delete("gists/#{Gist.new gist}/star", options, 3, true, true)
  response.status == 204
end

#update_gist_comment(gist_comment_id, comment, options = {}) ⇒ Hashie::Mash

Update gist comment

Requires authenticated client

Examples:

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

Parameters:

  • gist_comment_id (Integer)

    Id of the gist comment to update.

  • comment (String)

    Updated comment contents.

Returns:

  • (Hashie::Mash)

    Hash representing the updated comment.

See Also:



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

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