Class: Github::Client::Gists

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/gists.rb

Defined Under Namespace

Classes: Comments

Constant Summary

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Github::ClassMethods

#configuration, #configure, #require_all

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#commits(*args) ⇒ Object

List gist commits

Examples:

github = Github.new
github.gists.commits 'gist-id'

See Also:


187
188
189
190
191
192
193
# File 'lib/github_api/client/gists.rb', line 187

def commits(*args)
  arguments(args, required: [:id])

  response = get_request("/gists/#{arguments.id}/commits")
  return response unless block_given?
  response.each { |el| yield el }
end

#create(*args) ⇒ Hash

Create a gist

Examples:

github = Github.new
github.gists.create
  description: 'the description for this gist',
  public: true,
  files: {
    'file1.txt' => {
       content: 'String file contents'
     }
  }

Parameters:

Returns:

See Also:


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

def create(*args)
  arguments(args)

  post_request("/gists", arguments.params)
end

#delete(*args) ⇒ Object

Delete a gist

Examples:

github = Github.new
github.gists.delete 'gist-id'

See Also:


281
282
283
284
285
# File 'lib/github_api/client/gists.rb', line 281

def delete(*args)
  arguments(args, required: [:id])

  delete_request("/gists/#{arguments.id}", arguments.params)
end

#edit(*args) ⇒ Hash

Edit a gist

Parameters:

  • params (Hash)
  • [String] (Hash)

    a customizable set of options

  • [Hash] (Hash)

    a customizable set of options

Returns:

See Also:


172
173
174
175
176
# File 'lib/github_api/client/gists.rb', line 172

def edit(*args)
  arguments(args, required: [:id])

  patch_request("/gists/#{arguments.id}", arguments.params)
end

#fork(*args) ⇒ Object

Fork a gist

Examples:

github = Github.new
github.gists.fork 'gist-id'

249
250
251
252
253
# File 'lib/github_api/client/gists.rb', line 249

def fork(*args)
  arguments(args, required: [:id])

  post_request("/gists/#{arguments.id}/forks", arguments.params)
end

#forks(*args) ⇒ Object

List gist forks

Examples:

github = Github.new
github.gists.forks 'gist-id'

See Also:


264
265
266
267
268
269
270
# File 'lib/github_api/client/gists.rb', line 264

def forks(*args)
  arguments(args, required: [:id])

  response = get_request("/gists/#{arguments.id}/forks")
  return response unless block_given?
  response.each { |el| yield el }
end

#get(*args) ⇒ Hash Also known as: find

Get a single gist

Get a specific revision of gist

Examples:

github = Github.new
github.gists.get 'gist-id'
github = Github.new
github.gists.get 'gist-id', sha: '

Returns:

See Also:


88
89
90
91
92
93
94
95
96
# File 'lib/github_api/client/gists.rb', line 88

def get(*args)
  arguments(args, required: [:id])

  if (sha = arguments.params.delete('sha'))
    get_request("/gists/#{arguments.id}/#{sha}")
  else
    get_request("/gists/#{arguments.id}", arguments.params)
  end
end

#list(*args) ⇒ Hash Also known as: all

List a user's gists

List the authenticated user’s gists or if called anonymously, this will returns all public gists

List all public gists

Examples:

github = Github.new
github.gists.list user: 'user-name'
github = Github.new oauth_token: '...'
github.gists.list

Returns:

See Also:


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/github_api/client/gists.rb', line 36

def list(*args)
  params = arguments(args).params

  response = if (user = params.delete('user'))
    get_request("/users/#{user}/gists", params)
  elsif args.map(&:to_s).include?('public')
    get_request("/gists/public", params)
  else
    get_request("/gists", params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#star(*args) ⇒ Object

Star a gist

Examples:

github = Github.new
github.gists.star 'gist-id'

See Also:


204
205
206
207
208
# File 'lib/github_api/client/gists.rb', line 204

def star(*args)
  arguments(args, required: [:id])

  put_request("/gists/#{arguments.id}/star", arguments.params)
end

#starred(*args) ⇒ Hash

List the authenticated user's starred gists

Examples:

github = Github.new oauth_token: '...'
github.gists.starred

Returns:

See Also:


62
63
64
65
66
67
# File 'lib/github_api/client/gists.rb', line 62

def starred(*args)
  arguments(args)
  response = get_request("/gists/starred", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#starred?(*args) ⇒ Boolean

Check if a gist is starred

Examples:

github = Github.new
github.gists.starred? 'gist-id'

Returns:

  • (Boolean)

See Also:


234
235
236
237
238
239
240
# File 'lib/github_api/client/gists.rb', line 234

def starred?(*args)
  arguments(args, required: [:id])
  get_request("/gists/#{arguments.id}/star", arguments.params)
  true
rescue Github::Error::NotFound
  false
end

#unstar(*args) ⇒ Object

Unstar a gist


219
220
221
222
223
# File 'lib/github_api/client/gists.rb', line 219

def unstar(*args)
  arguments(args, required: [:id])

  delete_request("/gists/#{arguments.id}/star", arguments.params)
end