Module: GitHub::Client::Gists

Included in:
GitHub::Client
Defined in:
lib/github_api_v3/client/gists.rb

Overview

Contains methods for the Gists API.

Instance Method Summary collapse

Instance Method Details

#create_gist(files = {}, options = {:public => true}) ⇒ Hash

Create a gist.

Requires authentication

Examples:

client.create_gist(files: {"file1.txt" => { content: "File contents" }}, description: "Gist description", public: "false")

Parameters:

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

    The files to add to the gist.

  • options (Hash) (defaults to: {:public => true})

    Optional options when creating the gist.

Options Hash (options):

  • :public (Boolean)

    Whether the gist should be public. True by default.

  • :description (String)

    Gist description.

Returns:

  • (Hash)

    Gist information.

See Also:



53
54
55
56
# File 'lib/github_api_v3/client/gists.rb', line 53

def create_gist(files={}, options={:public => true})
  options.merge!(files)
  post "/gists", body: options
end

#create_gist_comment(id, comment) ⇒ Hash

Create a gist comment.

Requires authentication.

Examples:

client.create_gist_comment(5928712, 'Awesome!')

Parameters:

  • id (Integer)

    The Gist ID.

  • comment (String)

    The comment text.

Returns:

  • (Hash)

    The Gist information.

See Also:



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

def create_gist_comment(id, comment)
  post "/gists/#{id}/comments", body: { body: comment }
end

#delete_gist(id) ⇒ Boolean

Delete a gist.

Requires authentication.

Examples:

client.delete_gist(5928712)

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



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

def delete_gist(id)
  boolean_request :delete, "/gists/#{id}"
end

#delete_gist_comment(id, comment_id) ⇒ Boolean

Delete a gist comment.

Requires authentication.

Examples:

client.delete_gist_comment(5928712, 889239)

Parameters:

  • id (Integer)

    The Gist ID.

  • comment_id (Integer)

    The ID of the comment to delete.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



197
198
199
# File 'lib/github_api_v3/client/gists.rb', line 197

def delete_gist_comment(id, comment_id)
  boolean_request :delete, "/gists/#{id}/comments/#{comment_id}"
end

#edit_gist(id, files = {}, options = {:public => true}) ⇒ Hash

Edit a gist

Requires authentication.

Parameters:

  • id (Integer)

    The ID of the Gist to edit.

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

    Filenames in the gist.

  • options (Hash) (defaults to: {:public => true})

    Optional options when creating the gist.

Options Hash (options):

  • :public (Boolean)

    Whether the gist should be public. True by default.

  • :description (String)

    Gist description.

Returns:

  • (Hash)

    Gist information.



68
69
70
71
# File 'lib/github_api_v3/client/gists.rb', line 68

def edit_gist(id, files={}, options={:public => true})
  options.merge!(files)
  patch "/gists/#{id}", body: options
end

#edit_gist_comment(id, comment_id, comment) ⇒ Hash

Edit an existing gist comment.

Requires authentication.

Examples:

client.edit_gist_comment(5928712, 889239, 'Even more awesome!')

Parameters:

  • id (Integer)

    The Gist ID.

  • comment_id (Integer)

    The ID of the comment to edit.

  • comment (String)

    The comment text.

Returns:

  • (Hash)

    The Gist information.

See Also:



183
184
185
# File 'lib/github_api_v3/client/gists.rb', line 183

def edit_gist_comment(id, comment_id, comment)
  patch "/gists/#{id}/comments/#{comment_id}", body: { body: comment }
end

#fork_gist(id) ⇒ Boolean

Fork a gist.

Requires authentication.

Examples:

client.fork_gist(5928712)

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



119
120
121
# File 'lib/github_api_v3/client/gists.rb', line 119

def fork_gist(id)
  boolean_request :post, "/gists/#{id}/fork"
end

#gist(id) ⇒ Hash

Get a single gist.

Examples:

GitHub.gist(5928712)

Parameters:

  • id (Integer)

    The ID of the gist to retrieve.

Returns:

  • (Hash)

    Information about the gist.

See Also:



37
38
39
# File 'lib/github_api_v3/client/gists.rb', line 37

def gist(id)
  get "/gists/#{id}"
end

#gist_comment(id, comment_id) ⇒ Hash

Get a single comment on a gist.

Examples:

GitHub.gist_comment(5928712, 889239)

Parameters:

  • id (Integer)

    The Gist ID.

  • comment_id (Integer)

    The comment ID.

Returns:

  • (Hash)

    The comment data.

See Also:



154
155
156
# File 'lib/github_api_v3/client/gists.rb', line 154

def gist_comment(id, comment_id)
  get "/gists/#{id}/comments/#{comment_id}"
end

#gist_comments(id) ⇒ Array

List comments on a gist.

Examples:

GitHub.gist_comments(5928712)

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Array)

    An array of comments.

See Also:



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

def gist_comments(id)
  get "/gists/#{id}/comments"
end

#gist_starred?(id) ⇒ Boolean

Check if a gist is starred.

Requires authentication.

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Boolean)

    True if it is starred, false if not.

See Also:



80
81
82
# File 'lib/github_api_v3/client/gists.rb', line 80

def gist_starred?(id)
  boolean_request :get, "/gists/#{id}/star"
end

#gists(username = nil) ⇒ Array

List gists.

Gets a list of all gists for a specified user. If called without username, returns gists for the authenticated user. If unauthenticated, returns all public gists.

Examples:

GitHub.gists('caseyscarborough')
GitHub.gists

Parameters:

  • username (String) (defaults to: nil)

    Username to get gists for.

Returns:

  • (Array)

    Array containing each gist.

See Also:



22
23
24
25
26
27
28
# File 'lib/github_api_v3/client/gists.rb', line 22

def gists(username=nil)
  if username
    get "/users/#{username}/gists"
  else
    get "/gists"
  end
end

#star_gist(id) ⇒ Boolean

Star a gist.

Requires authentication.

Examples:

client.star_gist(5928712)

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



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

def star_gist(id)
  boolean_request :put, "/gists/#{id}/star"
end

#unstar_gist(id) ⇒ Boolean

Unstar a gist.

Requires authentication.

Examples:

client.unstar_gist(5928712)

Parameters:

  • id (Integer)

    The Gist ID.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



106
107
108
# File 'lib/github_api_v3/client/gists.rb', line 106

def unstar_gist(id)
  boolean_request :delete, "/gists/#{id}/star"
end