github_api 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b428d8782ec8d52580f70a96939c878db0cdf4ec
4
- data.tar.gz: 578c3e1c036ec22952d056349972057d5518a48a
3
+ metadata.gz: c509b47b9406a28c186ff6f1a0f9634b20a4ce35
4
+ data.tar.gz: c4a47665d1ab2f0170afd089cbf2b6e4612eb18e
5
5
  SHA512:
6
- metadata.gz: 57cd89c6a9f21ffbbb1e036894de9ac9a43fb7d1eb33a9bee31e27c9b5c6a956b6d9591cf0a15fde0fcb219f730b8ab0608b867f4d7d18066ecff6e7d2c2bd9d
7
- data.tar.gz: 606683bd7c29321ece30e435c84720d3d426f53c1116bb510c171f1683a3f48f7aebb4aeb3ff32e4ed86c4e003d3ce1025c314f9d82911ebcafd911c1b33c9dc
6
+ metadata.gz: 5e20bca947fe37fc506743485b515e35dbcb7e6fddce356492549729055da1420a9a8f538f55bced926eed2d0bb60a0575e47f029eb974fbcd0903d5fb717768
7
+ data.tar.gz: 3cf563db4fe0944d9768ebb063e12b3b18d64797cc687e0fe53bf5c58b24cc70ed477db2840e3ca6968e936ce7211f6955f1f38967d224feb35f374a7ca1ab5f
data/README.md CHANGED
@@ -412,7 +412,7 @@ To create an access token through the GitHub Authorizations API, you are require
412
412
 
413
413
  ```ruby
414
414
  github = Github.new basic_auth: 'login:password'
415
- github.oauth.create scopes: ['repo'], note: 'admin script'
415
+ github.auth.create scopes: ['repo'], note: 'admin script'
416
416
  ```
417
417
 
418
418
  You can add more than one scope from the `user`, `public_repo`, `repo`, `gist` or leave the scopes parameter out, in which case, the default read-only access will be assumed (includes public user profile info, public repo info, and gists).
@@ -423,20 +423,20 @@ Furthermore, to create auth token for an application you need to pass `:app` arg
423
423
 
424
424
  ```ruby
425
425
  github = Github.new basic_auth: 'login:password'
426
- github.oauth.app.create 'client-id', scopes: ['repo']
426
+ github.auth.app.create 'client-id', scopes: ['repo']
427
427
  ```
428
428
 
429
429
  In order to revoke auth token(s) for an application you must use basic authentication with `client_id` as login and `client_secret` as password.
430
430
 
431
431
  ```ruby
432
432
  github = Github.new basic_auth: "client_id:client_secret"
433
- github.oauth.app.delete 'client-id'
433
+ github.auth.app.delete 'client-id'
434
434
  ```
435
435
 
436
436
  Revoke a specific app token.
437
437
 
438
438
  ```ruby
439
- github.oauth.app.delete 'client-id', 'access-token'
439
+ github.auth.app.delete 'client-id', 'access-token'
440
440
  ```
441
441
 
442
442
  ### 3.3 Scopes
@@ -448,6 +448,13 @@ github = Github.new oauth_token: 'token'
448
448
  github.scopes.list # => ['repo']
449
449
  ```
450
450
 
451
+ or inidividually for a given user:
452
+
453
+ ```ruby
454
+ github = Github.new
455
+ github.scopes.list 'token'
456
+ ```
457
+
451
458
  To list the scopes that the particular GitHub API action checks for do:
452
459
 
453
460
  ```ruby
@@ -255,20 +255,6 @@ module Github
255
255
  end
256
256
  end
257
257
 
258
- # Scope for passing request required arguments.
259
- #
260
- def with(args)
261
- case args
262
- when Hash
263
- set args
264
- when /.*\/.*/i
265
- user, repo = args.split('/')
266
- set :user => user, :repo => repo
267
- else
268
- ::Kernel.raise ArgumentError, 'This api does not support passed in arguments'
269
- end
270
- end
271
-
272
258
  # Set a configuration option for a given namespace
273
259
  #
274
260
  # @param [String] option
@@ -300,6 +286,9 @@ module Github
300
286
  # @param [Array[Symbol]] names
301
287
  # the name for the scope
302
288
  #
289
+ # @example
290
+ # namespace :scopes
291
+ #
303
292
  # @return [self]
304
293
  #
305
294
  # @api public
@@ -307,14 +296,17 @@ module Github
307
296
  options = names.last.is_a?(Hash) ? names.pop : {}
308
297
  names = names.map(&:to_sym)
309
298
  name = names.pop
310
- return if public_method_defined?(name)
299
+
300
+ if public_method_defined?(name)
301
+ raise ArgumentError, "namespace '#{name}' is already defined"
302
+ end
311
303
 
312
304
  class_name = extract_class_name(name, options)
305
+
313
306
  define_method(name) do |*args, &block|
314
307
  options = args.last.is_a?(Hash) ? args.pop : {}
315
308
  API::Factory.new(class_name, current_options.merge(options), &block)
316
309
  end
317
- self
318
310
  end
319
311
 
320
312
  # Extracts class name from options
@@ -325,6 +317,9 @@ module Github
325
317
  # @option options [Boolean] :root
326
318
  # if the class is at the root or not
327
319
  #
320
+ # @example
321
+ # extract_class_name(:stats, class_name: :statistics)
322
+ #
328
323
  # @return [String]
329
324
  #
330
325
  # @api private
@@ -9,10 +9,12 @@ module Github
9
9
  #
10
10
  # @api public
11
11
  def self.extend_with_actions(child_class)
12
+ return unless child_class.is_a?(Class)
13
+ return if child_class.name.nil? # Skip anonymous classes
14
+
12
15
  child_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
13
16
  def self.actions
14
- self.new.api_methods_in(#{child_class}) +
15
- self.new.module_methods_in(#{child_class})
17
+ self.new.actions
16
18
  end
17
19
 
18
20
  def actions
@@ -3,8 +3,6 @@
3
3
  module Github
4
4
  module Authorization
5
5
 
6
- attr_accessor :scopes
7
-
8
6
  # Setup OAuth2 instance
9
7
  def client
10
8
  @client ||= ::OAuth2::Client.new(client_id, client_secret,
@@ -2,26 +2,25 @@
2
2
 
3
3
  module Github
4
4
  class Client < API
5
-
6
5
  require_all 'github_api/client',
7
- 'activity',
8
- 'authorizations',
9
- 'emojis',
10
- 'gists',
11
- 'gitignore',
12
- 'git_data',
13
- 'issues',
14
- 'markdown',
15
- 'meta',
16
- 'orgs',
17
- 'pull_requests',
18
- 'repos',
19
- 'say',
20
- 'scopes',
21
- 'search',
22
- 'users'
23
-
24
- # Serving up the social in Social Coding™, the Activity APIs
6
+ 'activity',
7
+ 'authorizations',
8
+ 'emojis',
9
+ 'gists',
10
+ 'gitignore',
11
+ 'git_data',
12
+ 'issues',
13
+ 'markdown',
14
+ 'meta',
15
+ 'orgs',
16
+ 'pull_requests',
17
+ 'repos',
18
+ 'say',
19
+ 'scopes',
20
+ 'search',
21
+ 'users'
22
+
23
+ # Serving up the 'social' in Social Coding, the Activity APIs
25
24
  # provide access to notifications, subscriptions, and timelines.
26
25
  namespace :activity
27
26
 
@@ -48,6 +47,7 @@ module Github
48
47
  # tokens, and only through Basic Authentication.
49
48
  namespace :authorizations
50
49
  alias :oauth :authorizations
50
+ alias :auth :authorizations
51
51
 
52
52
  namespace :orgs
53
53
  alias :organizations :orgs
@@ -15,8 +15,8 @@ module Github
15
15
  #
16
16
  # @example
17
17
  # github = Github.new basic_auth: 'login:password'
18
- # github.oauth.list
19
- # github.oauth.list { |auth| ... }
18
+ # github.auth.list
19
+ # github.auth.list { |auth| ... }
20
20
  #
21
21
  # @api public
22
22
  def list(*args)
@@ -10,6 +10,9 @@ module Github
10
10
  'memberships',
11
11
  'teams'
12
12
 
13
+ # Access to Client::Orgs::Hooks API
14
+ namespace :hooks
15
+
13
16
  # Access to Client::Orgs::Members API
14
17
  namespace :members
15
18
 
@@ -4,15 +4,41 @@ module Github
4
4
  class Client::Scopes < API
5
5
  # Check what OAuth scopes you have.
6
6
  #
7
- # = Examples
8
- # github = Github.new :oauth_token => 'token'
9
- # github.scopes.all
7
+ # @see https://developer.github.com/v3/oauth/#scopes
10
8
  #
9
+ # @example
10
+ # github = Github.new oauth_token: 'e72e16c7e42f292c6912e7710c838347ae17'
11
+ # github.scopes.all
12
+ #
13
+ # @example
14
+ # github = Github.new
15
+ # github.scopes.list 'e72e16c7e42f292c6912e7710c838347ae17'
16
+ #
17
+ # @example
18
+ # github = Github.new
19
+ # github.scopes.list token: 'e72e16c7e42f292c6912e7710c838347ae17'
20
+ #
21
+ # @api public
11
22
  def list(*args)
12
23
  arguments(args)
13
- response = get_request("/user", arguments.params)
14
- response.headers.oauth_scopes ? response.headers.oauth_scopes.split(',') : response
24
+ params = arguments.params
25
+ token = args.shift
26
+
27
+ if token.is_a?(Hash) && !params['token'].nil?
28
+ token = params.delete('token')
29
+ elsif token.nil?
30
+ token = oauth_token
31
+ end
32
+
33
+ if token.nil?
34
+ raise ArgumentError, 'Access token required'
35
+ end
36
+
37
+ headers = { 'Authorization' => "token #{token}" }
38
+ params['headers'] = headers
39
+ response = get_request("/user", params)
40
+ response.headers.oauth_scopes.split(',').map(&:strip)
15
41
  end
16
- alias :all :list
17
- end
42
+ alias all list
43
+ end # Client::Scopes
18
44
  end # Github
@@ -14,32 +14,34 @@ module Github
14
14
  :ssl
15
15
  ].freeze
16
16
 
17
+ # Default requets header information
18
+ #
19
+ # @return [Hash[String]]
20
+ #
21
+ # @api private
22
+ def default_headers
23
+ {
24
+ ACCEPT => 'application/vnd.github.v3+json,' \
25
+ 'application/vnd.github.beta+json;q=0.5,' \
26
+ 'application/json;q=0.1',
27
+ ACCEPT_CHARSET => 'utf-8'
28
+ }
29
+ end
30
+
31
+ # Create default connection options
32
+ #
33
+ # @return [Hash[Symbol]]
34
+ # the default options
35
+ #
36
+ # @api private
17
37
  def default_options(options = {})
18
- accept = options[:headers] && options[:headers][:accept]
38
+ headers = default_headers.merge(options[:headers] || {})
39
+ headers.merge!({USER_AGENT => options[:user_agent]})
19
40
  {
20
- headers: {
21
- ACCEPT => accept || 'application/vnd.github.v3+json,' \
22
- 'application/vnd.github.beta+json;q=0.5,' \
23
- 'application/json;q=0.1',
24
- ACCEPT_CHARSET => 'utf-8',
25
- USER_AGENT => options[:user_agent]
26
- },
41
+ headers: headers,
27
42
  ssl: options[:ssl],
28
43
  url: options[:endpoint]
29
- }.tap do |h|
30
- if type = options[:headers] && options[:headers][CONTENT_TYPE]
31
- h[:headers][CONTENT_TYPE] = type
32
- end
33
- h
34
- end
35
- end
36
-
37
- def clear_cache
38
- @connection = nil
39
- end
40
-
41
- def caching?
42
- !@connection.nil?
44
+ }
43
45
  end
44
46
 
45
47
  # Exposes middleware builder to facilitate custom stacks and easy
@@ -48,7 +50,11 @@ module Github
48
50
  # @api public
49
51
  def stack(options = {})
50
52
  @stack ||= begin
51
- builder_class = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
53
+ builder_class = if defined?(Faraday::RackBuilder)
54
+ Faraday::RackBuilder
55
+ else
56
+ Faraday::Builder
57
+ end
52
58
  builder_class.new(&Github.default_middleware(options))
53
59
  end
54
60
  end
@@ -58,14 +64,15 @@ module Github
58
64
  # Returns a Fraday::Connection object
59
65
  def connection(api, options = {})
60
66
  connection_options = default_options(options)
61
- clear_cache unless options.empty?
62
67
  connection_options.merge!(builder: stack(options.merge!(api: api)))
63
- connection_options.deep_merge!(options[:connection_options]) if options[:connection_options]
68
+ if options[:connection_options]
69
+ connection_options.deep_merge!(options[:connection_options])
70
+ end
64
71
  if ENV['DEBUG']
65
72
  p "Connection options : \n"
66
73
  pp connection_options
67
74
  end
68
- @connection ||= Faraday.new(connection_options)
75
+ Faraday.new(connection_options)
69
76
  end
70
77
  end # Connection
71
78
  end # Github
@@ -29,7 +29,7 @@ module Github
29
29
 
30
30
  ACCEPT_CHARSET = 'Accept-Charset'.freeze
31
31
 
32
- OAUTH_SCOPES = 'X-Oauth-Scopes'.freeze
32
+ OAUTH_SCOPES = 'X-OAuth-Scopes'.freeze
33
33
 
34
34
  ACCEPTED_OAUTH_SCOPES = 'X-Accepted-Oauth-Scopes'.freeze
35
35
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- VERSION = "0.14.1"
4
+ VERSION = "0.14.2"
5
5
  end # Github
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable