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 +4 -4
- data/README.md +11 -4
- data/lib/github_api/api.rb +11 -16
- data/lib/github_api/api/actions.rb +4 -2
- data/lib/github_api/authorization.rb +0 -2
- data/lib/github_api/client.rb +19 -19
- data/lib/github_api/client/authorizations.rb +2 -2
- data/lib/github_api/client/orgs.rb +3 -0
- data/lib/github_api/client/scopes.rb +33 -7
- data/lib/github_api/connection.rb +33 -26
- data/lib/github_api/constants.rb +1 -1
- data/lib/github_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c509b47b9406a28c186ff6f1a0f9634b20a4ce35
|
4
|
+
data.tar.gz: c4a47665d1ab2f0170afd089cbf2b6e4612eb18e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
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
|
data/lib/github_api/api.rb
CHANGED
@@ -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
|
-
|
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.
|
15
|
-
self.new.module_methods_in(#{child_class})
|
17
|
+
self.new.actions
|
16
18
|
end
|
17
19
|
|
18
20
|
def actions
|
data/lib/github_api/client.rb
CHANGED
@@ -2,26 +2,25 @@
|
|
2
2
|
|
3
3
|
module Github
|
4
4
|
class Client < API
|
5
|
-
|
6
5
|
require_all 'github_api/client',
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# Serving up the
|
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
|
@@ -4,15 +4,41 @@ module Github
|
|
4
4
|
class Client::Scopes < API
|
5
5
|
# Check what OAuth scopes you have.
|
6
6
|
#
|
7
|
-
#
|
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
|
-
|
14
|
-
|
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
|
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
|
-
|
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
|
-
}
|
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)
|
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
|
-
|
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
|
-
|
75
|
+
Faraday.new(connection_options)
|
69
76
|
end
|
70
77
|
end # Connection
|
71
78
|
end # Github
|
data/lib/github_api/constants.rb
CHANGED
data/lib/github_api/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|