Class: Github::Client::Gists

Inherits:
API
  • Object
show all
Defined in:
lib/github_api2/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!, #disable_redirects, #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, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

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

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

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:



189
190
191
192
193
194
195
# File 'lib/github_api2/client/gists.rb', line 189

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:



131
132
133
134
135
# File 'lib/github_api2/client/gists.rb', line 131

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:



283
284
285
286
287
# File 'lib/github_api2/client/gists.rb', line 283

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:



174
175
176
177
178
# File 'lib/github_api2/client/gists.rb', line 174

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'


251
252
253
254
255
# File 'lib/github_api2/client/gists.rb', line 251

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:



266
267
268
269
270
271
272
# File 'lib/github_api2/client/gists.rb', line 266

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:



90
91
92
93
94
95
96
97
98
# File 'lib/github_api2/client/gists.rb', line 90

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:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/github_api2/client/gists.rb', line 38

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:



206
207
208
209
210
# File 'lib/github_api2/client/gists.rb', line 206

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:



64
65
66
67
68
69
# File 'lib/github_api2/client/gists.rb', line 64

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:



236
237
238
239
240
241
242
# File 'lib/github_api2/client/gists.rb', line 236

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

Examples:

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

See Also:



221
222
223
224
225
# File 'lib/github_api2/client/gists.rb', line 221

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

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