octodoggy 4.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/CONTRIBUTING.md +22 -0
- data/LICENSE.md +20 -0
- data/README.md +714 -0
- data/Rakefile +22 -0
- data/lib/ext/sawyer/relation.rb +10 -0
- data/lib/octokit.rb +59 -0
- data/lib/octokit/arguments.rb +14 -0
- data/lib/octokit/authentication.rb +82 -0
- data/lib/octokit/client.rb +238 -0
- data/lib/octokit/client/authorizations.rb +244 -0
- data/lib/octokit/client/commit_comments.rb +95 -0
- data/lib/octokit/client/commits.rb +239 -0
- data/lib/octokit/client/contents.rb +162 -0
- data/lib/octokit/client/deployments.rb +62 -0
- data/lib/octokit/client/downloads.rb +50 -0
- data/lib/octokit/client/emojis.rb +18 -0
- data/lib/octokit/client/events.rb +151 -0
- data/lib/octokit/client/feeds.rb +33 -0
- data/lib/octokit/client/gists.rb +233 -0
- data/lib/octokit/client/gitignore.rb +43 -0
- data/lib/octokit/client/hooks.rb +297 -0
- data/lib/octokit/client/integrations.rb +77 -0
- data/lib/octokit/client/issues.rb +321 -0
- data/lib/octokit/client/labels.rb +156 -0
- data/lib/octokit/client/legacy_search.rb +42 -0
- data/lib/octokit/client/licenses.rb +45 -0
- data/lib/octokit/client/markdown.rb +27 -0
- data/lib/octokit/client/meta.rb +21 -0
- data/lib/octokit/client/milestones.rb +87 -0
- data/lib/octokit/client/notifications.rb +171 -0
- data/lib/octokit/client/objects.rb +141 -0
- data/lib/octokit/client/organizations.rb +768 -0
- data/lib/octokit/client/pages.rb +63 -0
- data/lib/octokit/client/projects.rb +314 -0
- data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
- data/lib/octokit/client/pull_requests.rb +301 -0
- data/lib/octokit/client/rate_limit.rb +54 -0
- data/lib/octokit/client/reactions.rb +158 -0
- data/lib/octokit/client/refs.rb +118 -0
- data/lib/octokit/client/releases.rb +163 -0
- data/lib/octokit/client/repositories.rb +654 -0
- data/lib/octokit/client/repository_invitations.rb +103 -0
- data/lib/octokit/client/reviews.rb +174 -0
- data/lib/octokit/client/say.rb +19 -0
- data/lib/octokit/client/search.rb +76 -0
- data/lib/octokit/client/service_status.rb +38 -0
- data/lib/octokit/client/source_import.rb +161 -0
- data/lib/octokit/client/stats.rb +105 -0
- data/lib/octokit/client/statuses.rb +47 -0
- data/lib/octokit/client/traffic.rb +69 -0
- data/lib/octokit/client/users.rb +354 -0
- data/lib/octokit/configurable.rb +147 -0
- data/lib/octokit/connection.rb +199 -0
- data/lib/octokit/default.rb +166 -0
- data/lib/octokit/enterprise_admin_client.rb +40 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +128 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/error.rb +286 -0
- data/lib/octokit/gist.rb +36 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/organization.rb +17 -0
- data/lib/octokit/preview.rb +38 -0
- data/lib/octokit/rate_limit.rb +33 -0
- data/lib/octokit/repo_arguments.rb +19 -0
- data/lib/octokit/repository.rb +93 -0
- data/lib/octokit/response/feed_parser.rb +21 -0
- data/lib/octokit/response/raise_error.rb +21 -0
- data/lib/octokit/user.rb +19 -0
- data/lib/octokit/version.rb +17 -0
- data/lib/octokit/warnable.rb +17 -0
- data/octokit.gemspec +22 -0
- metadata +160 -0
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :test => :spec
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
namespace :doc do
|
11
|
+
begin
|
12
|
+
require 'yard'
|
13
|
+
YARD::Rake::YardocTask.new do |task|
|
14
|
+
task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
|
15
|
+
task.options = [
|
16
|
+
'--output-dir', 'doc/yard',
|
17
|
+
'--markup', 'markdown',
|
18
|
+
]
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
end
|
22
|
+
end
|
data/lib/octokit.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'octokit/client'
|
2
|
+
require 'octokit/enterprise_admin_client'
|
3
|
+
require 'octokit/enterprise_management_console_client'
|
4
|
+
require 'octokit/default'
|
5
|
+
|
6
|
+
# Ruby toolkit for the GitHub API
|
7
|
+
module Octokit
|
8
|
+
|
9
|
+
class << self
|
10
|
+
include Octokit::Configurable
|
11
|
+
|
12
|
+
# API client based on configured options {Configurable}
|
13
|
+
#
|
14
|
+
# @return [Octokit::Client] API wrapper
|
15
|
+
def client
|
16
|
+
return @client if defined?(@client) && @client.same_options?(options)
|
17
|
+
@client = Octokit::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# EnterpriseAdminClient client based on configured options {Configurable}
|
21
|
+
#
|
22
|
+
# @return [Octokit::EnterpriseAdminClient] API wrapper
|
23
|
+
def enterprise_admin_client
|
24
|
+
return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options)
|
25
|
+
@enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# EnterpriseManagementConsoleClient client based on configured options {Configurable}
|
29
|
+
#
|
30
|
+
# @return [Octokit::EnterpriseManagementConsoleClient] API wrapper
|
31
|
+
def enterprise_management_console_client
|
32
|
+
return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options)
|
33
|
+
@enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def respond_to_missing?(method_name, include_private=false)
|
39
|
+
client.respond_to?(method_name, include_private) ||
|
40
|
+
enterprise_admin_client.respond_to?(method_name, include_private) ||
|
41
|
+
enterprise_management_console_client.respond_to?(method_name, include_private)
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(method_name, *args, &block)
|
45
|
+
if client.respond_to?(method_name)
|
46
|
+
return client.send(method_name, *args, &block)
|
47
|
+
elsif enterprise_admin_client.respond_to?(method_name)
|
48
|
+
return enterprise_admin_client.send(method_name, *args, &block)
|
49
|
+
elsif enterprise_management_console_client.respond_to?(method_name)
|
50
|
+
return enterprise_management_console_client.send(method_name, *args, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Octokit.setup
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Octokit
|
2
|
+
|
3
|
+
# Authentication methods for {Octokit::Client}
|
4
|
+
module Authentication
|
5
|
+
|
6
|
+
# Indicates if the client was supplied Basic Auth
|
7
|
+
# username and password
|
8
|
+
#
|
9
|
+
# @see https://developer.github.com/v3/#authentication
|
10
|
+
# @return [Boolean]
|
11
|
+
def basic_authenticated?
|
12
|
+
!!(@login && @password)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Indicates if the client was supplied an OAuth
|
16
|
+
# access token
|
17
|
+
#
|
18
|
+
# @see https://developer.github.com/v3/#authentication
|
19
|
+
# @return [Boolean]
|
20
|
+
def token_authenticated?
|
21
|
+
!!@access_token
|
22
|
+
end
|
23
|
+
|
24
|
+
# Indicates if the client was supplied a bearer token
|
25
|
+
#
|
26
|
+
# @see https://developer.github.com/early-access/integrations/authentication/#as-an-integration
|
27
|
+
# @return [Boolean]
|
28
|
+
def bearer_authenticated?
|
29
|
+
!!@bearer_token
|
30
|
+
end
|
31
|
+
|
32
|
+
# Indicates if the client was supplied an OAuth
|
33
|
+
# access token or Basic Auth username and password
|
34
|
+
#
|
35
|
+
# @see https://developer.github.com/v3/#authentication
|
36
|
+
# @return [Boolean]
|
37
|
+
def user_authenticated?
|
38
|
+
basic_authenticated? || token_authenticated?
|
39
|
+
end
|
40
|
+
|
41
|
+
# Indicates if the client has OAuth Application
|
42
|
+
# client_id and secret credentials to make anonymous
|
43
|
+
# requests at a higher rate limit
|
44
|
+
#
|
45
|
+
# @see https://developer.github.com/v3/#unauthenticated-rate-limited-requests
|
46
|
+
# @return Boolean
|
47
|
+
def application_authenticated?
|
48
|
+
!!application_authentication
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def application_authentication
|
54
|
+
if @client_id && @client_secret
|
55
|
+
{
|
56
|
+
:client_id => @client_id,
|
57
|
+
:client_secret => @client_secret
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def login_from_netrc
|
63
|
+
return unless netrc?
|
64
|
+
|
65
|
+
require 'netrc'
|
66
|
+
info = Netrc.read netrc_file
|
67
|
+
netrc_host = URI.parse(api_endpoint).host
|
68
|
+
creds = info[netrc_host]
|
69
|
+
if creds.nil?
|
70
|
+
# creds will be nil if there is no netrc for this end point
|
71
|
+
octokit_warn "Error loading credentials from netrc file for #{api_endpoint}"
|
72
|
+
else
|
73
|
+
creds = creds.to_a
|
74
|
+
self.login = creds.shift
|
75
|
+
self.password = creds.shift
|
76
|
+
end
|
77
|
+
rescue LoadError
|
78
|
+
octokit_warn "Please install netrc gem for .netrc support"
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'octokit/connection'
|
2
|
+
require 'octokit/warnable'
|
3
|
+
require 'octokit/arguments'
|
4
|
+
require 'octokit/repo_arguments'
|
5
|
+
require 'octokit/configurable'
|
6
|
+
require 'octokit/authentication'
|
7
|
+
require 'octokit/gist'
|
8
|
+
require 'octokit/rate_limit'
|
9
|
+
require 'octokit/repository'
|
10
|
+
require 'octokit/user'
|
11
|
+
require 'octokit/organization'
|
12
|
+
require 'octokit/preview'
|
13
|
+
require 'octokit/client/authorizations'
|
14
|
+
require 'octokit/client/commits'
|
15
|
+
require 'octokit/client/commit_comments'
|
16
|
+
require 'octokit/client/contents'
|
17
|
+
require 'octokit/client/downloads'
|
18
|
+
require 'octokit/client/deployments'
|
19
|
+
require 'octokit/client/emojis'
|
20
|
+
require 'octokit/client/events'
|
21
|
+
require 'octokit/client/feeds'
|
22
|
+
require 'octokit/client/gists'
|
23
|
+
require 'octokit/client/gitignore'
|
24
|
+
require 'octokit/client/hooks'
|
25
|
+
require 'octokit/client/integrations'
|
26
|
+
require 'octokit/client/issues'
|
27
|
+
require 'octokit/client/labels'
|
28
|
+
require 'octokit/client/legacy_search'
|
29
|
+
require 'octokit/client/licenses'
|
30
|
+
require 'octokit/client/meta'
|
31
|
+
require 'octokit/client/markdown'
|
32
|
+
require 'octokit/client/milestones'
|
33
|
+
require 'octokit/client/notifications'
|
34
|
+
require 'octokit/client/objects'
|
35
|
+
require 'octokit/client/organizations'
|
36
|
+
require 'octokit/client/pages'
|
37
|
+
require 'octokit/client/projects'
|
38
|
+
require 'octokit/client/pub_sub_hubbub'
|
39
|
+
require 'octokit/client/pull_requests'
|
40
|
+
require 'octokit/client/rate_limit'
|
41
|
+
require 'octokit/client/reactions'
|
42
|
+
require 'octokit/client/refs'
|
43
|
+
require 'octokit/client/releases'
|
44
|
+
require 'octokit/client/repositories'
|
45
|
+
require 'octokit/client/repository_invitations'
|
46
|
+
require 'octokit/client/reviews'
|
47
|
+
require 'octokit/client/say'
|
48
|
+
require 'octokit/client/search'
|
49
|
+
require 'octokit/client/service_status'
|
50
|
+
require 'octokit/client/source_import'
|
51
|
+
require 'octokit/client/stats'
|
52
|
+
require 'octokit/client/statuses'
|
53
|
+
require 'octokit/client/traffic'
|
54
|
+
require 'octokit/client/users'
|
55
|
+
require 'ext/sawyer/relation'
|
56
|
+
|
57
|
+
module Octokit
|
58
|
+
|
59
|
+
# Client for the GitHub API
|
60
|
+
#
|
61
|
+
# @see https://developer.github.com
|
62
|
+
class Client
|
63
|
+
|
64
|
+
include Octokit::Authentication
|
65
|
+
include Octokit::Configurable
|
66
|
+
include Octokit::Connection
|
67
|
+
include Octokit::Preview
|
68
|
+
include Octokit::Warnable
|
69
|
+
include Octokit::Client::Authorizations
|
70
|
+
include Octokit::Client::Commits
|
71
|
+
include Octokit::Client::CommitComments
|
72
|
+
include Octokit::Client::Contents
|
73
|
+
include Octokit::Client::Deployments
|
74
|
+
include Octokit::Client::Downloads
|
75
|
+
include Octokit::Client::Emojis
|
76
|
+
include Octokit::Client::Events
|
77
|
+
include Octokit::Client::Feeds
|
78
|
+
include Octokit::Client::Gists
|
79
|
+
include Octokit::Client::Gitignore
|
80
|
+
include Octokit::Client::Hooks
|
81
|
+
include Octokit::Client::Integrations
|
82
|
+
include Octokit::Client::Issues
|
83
|
+
include Octokit::Client::Labels
|
84
|
+
include Octokit::Client::LegacySearch
|
85
|
+
include Octokit::Client::Licenses
|
86
|
+
include Octokit::Client::Meta
|
87
|
+
include Octokit::Client::Markdown
|
88
|
+
include Octokit::Client::Milestones
|
89
|
+
include Octokit::Client::Notifications
|
90
|
+
include Octokit::Client::Objects
|
91
|
+
include Octokit::Client::Organizations
|
92
|
+
include Octokit::Client::Pages
|
93
|
+
include Octokit::Client::Projects
|
94
|
+
include Octokit::Client::PubSubHubbub
|
95
|
+
include Octokit::Client::PullRequests
|
96
|
+
include Octokit::Client::RateLimit
|
97
|
+
include Octokit::Client::Reactions
|
98
|
+
include Octokit::Client::Refs
|
99
|
+
include Octokit::Client::Releases
|
100
|
+
include Octokit::Client::Repositories
|
101
|
+
include Octokit::Client::RepositoryInvitations
|
102
|
+
include Octokit::Client::Reviews
|
103
|
+
include Octokit::Client::Say
|
104
|
+
include Octokit::Client::Search
|
105
|
+
include Octokit::Client::ServiceStatus
|
106
|
+
include Octokit::Client::SourceImport
|
107
|
+
include Octokit::Client::Stats
|
108
|
+
include Octokit::Client::Statuses
|
109
|
+
include Octokit::Client::Traffic
|
110
|
+
include Octokit::Client::Users
|
111
|
+
|
112
|
+
# Header keys that can be passed in options hash to {#get},{#head}
|
113
|
+
CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
|
114
|
+
|
115
|
+
def initialize(options = {})
|
116
|
+
# Use options passed in, but fall back to module defaults
|
117
|
+
Octokit::Configurable.keys.each do |key|
|
118
|
+
instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
|
119
|
+
end
|
120
|
+
|
121
|
+
login_from_netrc unless user_authenticated? || application_authenticated?
|
122
|
+
end
|
123
|
+
|
124
|
+
# Text representation of the client, masking tokens and passwords
|
125
|
+
#
|
126
|
+
# @return [String]
|
127
|
+
def inspect
|
128
|
+
inspected = super
|
129
|
+
|
130
|
+
# mask password
|
131
|
+
inspected = inspected.gsub! @password, "*******" if @password
|
132
|
+
inspected = inspected.gsub! @management_console_password, "*******" if @management_console_password
|
133
|
+
inspected = inspected.gsub! @bearer_token, '********' if @bearer_token
|
134
|
+
# Only show last 4 of token, secret
|
135
|
+
if @access_token
|
136
|
+
inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
|
137
|
+
end
|
138
|
+
if @client_secret
|
139
|
+
inspected = inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}"
|
140
|
+
end
|
141
|
+
|
142
|
+
inspected
|
143
|
+
end
|
144
|
+
|
145
|
+
# Duplicate client using client_id and client_secret as
|
146
|
+
# Basic Authentication credentials.
|
147
|
+
# @example
|
148
|
+
# Octokit.client_id = "foo"
|
149
|
+
# Octokit.client_secret = "bar"
|
150
|
+
#
|
151
|
+
# # GET https://api.github.com/?client_id=foo&client_secret=bar
|
152
|
+
# Octokit.get "/"
|
153
|
+
#
|
154
|
+
# Octokit.client.as_app do |client|
|
155
|
+
# # GET https://foo:bar@api.github.com/
|
156
|
+
# client.get "/"
|
157
|
+
# end
|
158
|
+
def as_app(key = client_id, secret = client_secret, &block)
|
159
|
+
if key.to_s.empty? || secret.to_s.empty?
|
160
|
+
raise ApplicationCredentialsRequired, "client_id and client_secret required"
|
161
|
+
end
|
162
|
+
app_client = self.dup
|
163
|
+
app_client.client_id = app_client.client_secret = nil
|
164
|
+
app_client.login = key
|
165
|
+
app_client.password = secret
|
166
|
+
|
167
|
+
yield app_client if block_given?
|
168
|
+
end
|
169
|
+
|
170
|
+
# Set username for authentication
|
171
|
+
#
|
172
|
+
# @param value [String] GitHub username
|
173
|
+
def login=(value)
|
174
|
+
reset_agent
|
175
|
+
@login = value
|
176
|
+
end
|
177
|
+
|
178
|
+
# Set password for authentication
|
179
|
+
#
|
180
|
+
# @param value [String] GitHub password
|
181
|
+
def password=(value)
|
182
|
+
reset_agent
|
183
|
+
@password = value
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set OAuth access token for authentication
|
187
|
+
#
|
188
|
+
# @param value [String] 40 character GitHub OAuth access token
|
189
|
+
def access_token=(value)
|
190
|
+
reset_agent
|
191
|
+
@access_token = value
|
192
|
+
end
|
193
|
+
|
194
|
+
# Set Bearer Token for authentication
|
195
|
+
#
|
196
|
+
# @param value [String] JWT
|
197
|
+
def bearer_token=(value)
|
198
|
+
reset_agent
|
199
|
+
@bearer_token = value
|
200
|
+
end
|
201
|
+
|
202
|
+
# Set OAuth app client_id
|
203
|
+
#
|
204
|
+
# @param value [String] 20 character GitHub OAuth app client_id
|
205
|
+
def client_id=(value)
|
206
|
+
reset_agent
|
207
|
+
@client_id = value
|
208
|
+
end
|
209
|
+
|
210
|
+
# Set OAuth app client_secret
|
211
|
+
#
|
212
|
+
# @param value [String] 40 character GitHub OAuth app client_secret
|
213
|
+
def client_secret=(value)
|
214
|
+
reset_agent
|
215
|
+
@client_secret = value
|
216
|
+
end
|
217
|
+
|
218
|
+
def client_without_redirects(options = {})
|
219
|
+
conn_opts = @connection_options
|
220
|
+
conn_opts[:url] = @api_endpoint
|
221
|
+
conn_opts[:builder] = @middleware.dup if @middleware
|
222
|
+
conn_opts[:proxy] = @proxy if @proxy
|
223
|
+
conn = Faraday.new(conn_opts) do |http|
|
224
|
+
if basic_authenticated?
|
225
|
+
http.basic_auth(@login, @password)
|
226
|
+
elsif token_authenticated?
|
227
|
+
http.authorization 'token', @access_token
|
228
|
+
elsif bearer_authenticated?
|
229
|
+
http.authorization 'Bearer', @bearer_token
|
230
|
+
end
|
231
|
+
http.headers['accept'] = options[:accept] if options.key?(:accept)
|
232
|
+
end
|
233
|
+
conn.builder.delete(Octokit::Middleware::FollowRedirects)
|
234
|
+
|
235
|
+
conn
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Authorizations API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
|
7
|
+
module Authorizations
|
8
|
+
|
9
|
+
# List the authenticated user's authorizations
|
10
|
+
#
|
11
|
+
# API for users to manage their own tokens.
|
12
|
+
# You can only access your own tokens, and only through
|
13
|
+
# Basic Authentication.
|
14
|
+
#
|
15
|
+
# @return [Array<Sawyer::Resource>] A list of authorizations for the authenticated user
|
16
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
|
17
|
+
# @example List authorizations for user ctshryock
|
18
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
19
|
+
# client.authorizations
|
20
|
+
def authorizations(options = {})
|
21
|
+
paginate 'authorizations', options
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get a single authorization for the authenticated user.
|
25
|
+
#
|
26
|
+
# You can only access your own tokens, and only through
|
27
|
+
# Basic Authentication.
|
28
|
+
#
|
29
|
+
# @return [Sawyer::Resource] A single authorization for the authenticated user
|
30
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
|
31
|
+
# @example Show authorization for user ctshryock's Travis auth
|
32
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
33
|
+
# client.authorization(999999)
|
34
|
+
def authorization(number, options = {})
|
35
|
+
get "authorizations/#{number}", options
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create an authorization for the authenticated user.
|
39
|
+
#
|
40
|
+
# You can create your own tokens, and only through
|
41
|
+
# Basic Authentication.
|
42
|
+
#
|
43
|
+
# @param options [Hash] A customizable set of options.
|
44
|
+
# @option options [Array] :scopes A list of scopes that this authorization is in.
|
45
|
+
# @option options [String] :note A note to remind you what the OAuth token is for.
|
46
|
+
# @option options [String] :note_url A URL to remind you what app the OAuth token is for.
|
47
|
+
# @option options [Boolean] :idempotent If true, will return an existing authorization if one has already been created.
|
48
|
+
# @option options [String] :client_id Client Id we received when our application was registered with GitHub.
|
49
|
+
# @option options [String] :client_secret Client Secret we received when our application was registered with GitHub.
|
50
|
+
#
|
51
|
+
# @return [Sawyer::Resource] A single authorization for the authenticated user
|
52
|
+
# @see https://developer.github.com/v3/oauth/#scopes Available scopes
|
53
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
|
54
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
|
55
|
+
# @example Create a new authorization for user ctshryock's project Zoidberg
|
56
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
57
|
+
# client.create_authorization({:scopes => ["public_repo", "gist"], :note => "Why not Zoidberg?", :note_url=> "https://en.wikipedia.org/wiki/Zoidberg"})
|
58
|
+
# @example Create a new OR return an existing authorization to be used by a specific client for user ctshryock's project Zoidberg
|
59
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
60
|
+
# client.create_authorization({:idempotent => true, :client_id => 'xxxx', :client_secret => 'yyyy', :scopes => ["user"]})
|
61
|
+
def create_authorization(options = {})
|
62
|
+
# Techincally we can omit scopes as GitHub has a default, however the
|
63
|
+
# API will reject us if we send a POST request with an empty body.
|
64
|
+
|
65
|
+
if options.delete :idempotent
|
66
|
+
client_id, client_secret = fetch_client_id_and_secret(options)
|
67
|
+
raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret
|
68
|
+
|
69
|
+
if fingerprint = options.delete(:fingerprint)
|
70
|
+
put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(:client_secret => client_secret)
|
71
|
+
else
|
72
|
+
put "authorizations/clients/#{client_id}", options.merge(:client_secret => client_secret)
|
73
|
+
end
|
74
|
+
|
75
|
+
else
|
76
|
+
post 'authorizations', options
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Update an authorization for the authenticated user.
|
81
|
+
#
|
82
|
+
# You can update your own tokens, but only through
|
83
|
+
# Basic Authentication.
|
84
|
+
#
|
85
|
+
# @param options [Hash] A customizable set of options.
|
86
|
+
# @option options [Array] :scopes Replace the authorization scopes with these.
|
87
|
+
# @option options [Array] :add_scopes A list of scopes to add to this authorization.
|
88
|
+
# @option options [Array] :remove_scopes A list of scopes to remove from this authorization.
|
89
|
+
# @option options [String] :note A note to remind you what the OAuth token is for.
|
90
|
+
# @option options [String] :note_url A URL to remind you what app the OAuth token is for.
|
91
|
+
#
|
92
|
+
# @return [Sawyer::Resource] A single (updated) authorization for the authenticated user
|
93
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
|
94
|
+
# @see https://developer.github.com/v3/oauth/#scopes for available scopes
|
95
|
+
# @example Update the authorization for user ctshryock's project Zoidberg
|
96
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
97
|
+
# client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})
|
98
|
+
def update_authorization(number, options = {})
|
99
|
+
patch "authorizations/#{number}", options
|
100
|
+
end
|
101
|
+
|
102
|
+
# Delete an authorization for the authenticated user.
|
103
|
+
#
|
104
|
+
# You can delete your own tokens, and only through
|
105
|
+
# Basic Authentication.
|
106
|
+
#
|
107
|
+
# @param number [Number] An existing Authorization ID
|
108
|
+
#
|
109
|
+
# @return [Boolean] Success
|
110
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
|
111
|
+
# @example Delete an authorization
|
112
|
+
# client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
|
113
|
+
# client.delete_authorization(999999)
|
114
|
+
def delete_authorization(number, options = {})
|
115
|
+
boolean_from_response :delete, "authorizations/#{number}", options
|
116
|
+
end
|
117
|
+
|
118
|
+
# Check scopes for a token
|
119
|
+
#
|
120
|
+
# @param token [String] GitHub OAuth token
|
121
|
+
# @param options [Hash] Header params for request
|
122
|
+
# @return [Array<String>] OAuth scopes
|
123
|
+
# @see https://developer.github.com/v3/oauth/#scopes
|
124
|
+
def scopes(token = @access_token, options = {})
|
125
|
+
raise ArgumentError.new("Access token required") if token.nil?
|
126
|
+
|
127
|
+
auth = { "Authorization" => "token #{token}" }
|
128
|
+
headers = (options.delete(:headers) || {}).merge(auth)
|
129
|
+
|
130
|
+
agent.call(:get, "user", :headers => headers).
|
131
|
+
headers['X-OAuth-Scopes'].
|
132
|
+
to_s.
|
133
|
+
split(',').
|
134
|
+
map(&:strip).
|
135
|
+
sort
|
136
|
+
end
|
137
|
+
|
138
|
+
# Check if a token is valid.
|
139
|
+
#
|
140
|
+
# Applications can check if a token is valid without rate limits.
|
141
|
+
#
|
142
|
+
# @param token [String] 40 character GitHub OAuth access token
|
143
|
+
#
|
144
|
+
# @return [Sawyer::Resource] A single authorization for the authenticated user
|
145
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#check-an-authorization
|
146
|
+
# @example
|
147
|
+
# client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
|
148
|
+
# client.check_application_authorization('deadbeef1234567890deadbeef987654321')
|
149
|
+
def check_application_authorization(token, options = {})
|
150
|
+
opts = options.dup
|
151
|
+
key = opts.delete(:client_id) || client_id
|
152
|
+
secret = opts.delete(:client_secret) || client_secret
|
153
|
+
|
154
|
+
as_app(key, secret) do |app_client|
|
155
|
+
app_client.get "applications/#{client_id}/tokens/#{token}", opts
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Reset a token
|
160
|
+
#
|
161
|
+
# Applications can reset a token without requiring a user to re-authorize.
|
162
|
+
#
|
163
|
+
# @param token [String] 40 character GitHub OAuth access token
|
164
|
+
#
|
165
|
+
# @return [Sawyer::Resource] A single authorization for the authenticated user
|
166
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#reset-an-authorization
|
167
|
+
# @example
|
168
|
+
# client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
|
169
|
+
# client.reset_application_authorization('deadbeef1234567890deadbeef987654321')
|
170
|
+
def reset_application_authorization(token, options = {})
|
171
|
+
opts = options.dup
|
172
|
+
key = opts.delete(:client_id) || client_id
|
173
|
+
secret = opts.delete(:client_secret) || client_secret
|
174
|
+
|
175
|
+
as_app(key, secret) do |app_client|
|
176
|
+
app_client.post "applications/#{client_id}/tokens/#{token}", opts
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Revoke a token
|
181
|
+
#
|
182
|
+
# Applications can revoke (delete) a token
|
183
|
+
#
|
184
|
+
# @param token [String] 40 character GitHub OAuth access token
|
185
|
+
#
|
186
|
+
# @return [Boolean] Result
|
187
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#revoke-an-authorization-for-an-application
|
188
|
+
# @example
|
189
|
+
# client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
|
190
|
+
# client.revoke_application_authorization('deadbeef1234567890deadbeef987654321')
|
191
|
+
def revoke_application_authorization(token, options = {})
|
192
|
+
opts = options.dup
|
193
|
+
key = opts.delete(:client_id) || client_id
|
194
|
+
secret = opts.delete(:client_secret) || client_secret
|
195
|
+
|
196
|
+
as_app(key, secret) do |app_client|
|
197
|
+
app_client.delete "applications/#{client_id}/tokens/#{token}", opts
|
198
|
+
|
199
|
+
app_client.last_response.status == 204
|
200
|
+
end
|
201
|
+
rescue Octokit::NotFound
|
202
|
+
false
|
203
|
+
end
|
204
|
+
alias :delete_application_authorization :revoke_application_authorization
|
205
|
+
|
206
|
+
# Revoke all tokens for an app
|
207
|
+
#
|
208
|
+
# Applications can revoke all of their tokens in a single request
|
209
|
+
#
|
210
|
+
# @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
|
211
|
+
# @return [Boolean] false
|
212
|
+
def revoke_all_application_authorizations(options = {})
|
213
|
+
octokit_warn("Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.")
|
214
|
+
false
|
215
|
+
end
|
216
|
+
|
217
|
+
# Get the URL to authorize a user for an application via the web flow
|
218
|
+
#
|
219
|
+
# @param app_id [String] Client Id we received when our application was registered with GitHub.
|
220
|
+
# @option options [String] :redirect_uri The url to redirect to after authorizing.
|
221
|
+
# @option options [String] :scope The scopes to request from the user.
|
222
|
+
# @option options [String] :state A random string to protect against CSRF.
|
223
|
+
# @return [String] The url to redirect the user to authorize.
|
224
|
+
# @see Octokit::Client
|
225
|
+
# @see https://developer.github.com/v3/oauth/#web-application-flow
|
226
|
+
# @example
|
227
|
+
# @client.authorize_url('xxxx')
|
228
|
+
def authorize_url(app_id = client_id, options = {})
|
229
|
+
if app_id.to_s.empty?
|
230
|
+
raise Octokit::ApplicationCredentialsRequired.new "client_id required"
|
231
|
+
end
|
232
|
+
authorize_url = options.delete(:endpoint) || Octokit.web_endpoint
|
233
|
+
authorize_url << "login/oauth/authorize?client_id=#{app_id}"
|
234
|
+
|
235
|
+
require 'cgi'
|
236
|
+
options.each do |key, value|
|
237
|
+
authorize_url << "&#{key}=#{CGI.escape value}"
|
238
|
+
end
|
239
|
+
|
240
|
+
authorize_url
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|