Skip to content

Commit 87b1fa0

Browse files
committed
Change to make :note to be required parameter, document in readme and close piotrmurach#248
1 parent d741df4 commit 87b1fa0

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ To create an access token through the GitHub Authorizations API, you are require
411411

412412
```ruby
413413
github = Github.new basic_auth: 'login:password'
414-
github.oauth.create scopes: ['repo']
414+
github.oauth.create scopes: ['repo'], note: 'admin script'
415415
```
416416

417417
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).

lib/github_api/client/authorizations.rb

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ class Client::Authorizations < API
66

77
require_all 'github_api/client/authorizations', 'app'
88

9-
VALID_AUTH_PARAM_NAMES = %w[
10-
scopes
11-
add_scopes
12-
remove_scopes
13-
note
14-
note_url
15-
client_id
16-
client_secret
17-
].freeze
18-
199
# Access to Authorizations::App API
2010
namespace :app
2111

@@ -24,9 +14,9 @@ class Client::Authorizations < API
2414
# @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
2515
#
2616
# @example
27-
# github = Github.new basic_auth: 'login:password'
28-
# github.oauth.list
29-
# github.oauth.list { |auth| ... }
17+
# github = Github.new basic_auth: 'login:password'
18+
# github.oauth.list
19+
# github.oauth.list { |auth| ... }
3020
#
3121
# @api public
3222
def list(*args)
@@ -37,7 +27,7 @@ def list(*args)
3727
return response unless block_given?
3828
response.each { |el| yield el }
3929
end
40-
alias :all :list
30+
alias_method :all, :list
4131

4232
# Get a single authorization
4333
#
@@ -56,39 +46,45 @@ def get(*args)
5646

5747
get_request("/authorizations/#{arguments.id}", arguments.params)
5848
end
59-
alias :find :get
49+
alias_method :find, :get
6050

6151
# Create a new authorization
6252
#
53+
# @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
54+
#
6355
# @param [Hash] params
6456
# @option params [Array[String]] :scopes
6557
# A list of scopes that this authorization is in.
6658
# @option params [String] :note
67-
# A note to remind you what the OAuth token is for.
59+
# Required. A note to remind you what the OAuth token is for.
6860
# @option params [String] :note_url
6961
# A URL to remind you what the OAuth token is for.
7062
# @option params [String] :client_id
7163
# The 20 character OAuth app client key for which to create the token.
7264
# @option params [String] :client_secret
7365
# The 40 character OAuth app client secret for which to create the token.
66+
# @option params [String] :fingerprint
67+
# A unique string to distinguish an authorization from others
68+
# created for the same client ID and user.
7469
#
7570
# @example
76-
# github = Github.new basic_auth: 'login:password'
77-
# github.oauth.create
78-
# "scopes" => ["public_repo"]
71+
# github = Github.new basic_auth: 'login:password'
72+
# github.oauth.create scopes: ["public_repo"], note: 'amdmin script'
7973
#
8074
# @api public
8175
def create(*args)
8276
raise_authentication_error unless authenticated?
8377
arguments(args) do
84-
permit VALID_AUTH_PARAM_NAMES
78+
assert_required :note, :scopes
8579
end
8680

8781
post_request('/authorizations', arguments.params)
8882
end
8983

9084
# Update an existing authorization
9185
#
86+
# @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
87+
#
9288
# @param [Hash] inputs
9389
# @option inputs [Array] :scopes
9490
# Optional array - A list of scopes that this authorization is in.
@@ -100,28 +96,30 @@ def create(*args)
10096
# Optional string - A note to remind you what the OAuth token is for.
10197
# @optoin inputs [String] :note_url
10298
# Optional string - A URL to remind you what the OAuth token is for.
99+
# @option params [String] :fingerprint
100+
# A unique string to distinguish an authorization from others
101+
# created for the same client ID and user.
103102
#
104103
# @example
105-
# github = Github.new basic_auth: 'login:password'
106-
# github.oauth.update "authorization-id", add_scopes: ["repo"]
104+
# github = Github.new basic_auth: 'login:password'
105+
# github.oauth.update "authorization-id", add_scopes: ["repo"]
107106
#
108107
# @api public
109108
def update(*args)
110109
raise_authentication_error unless authenticated?
111-
arguments(args, required: [:id]) do
112-
permit VALID_AUTH_PARAM_NAMES
113-
end
110+
arguments(args, required: [:id])
114111

115112
patch_request("/authorizations/#{arguments.id}", arguments.params)
116113
end
117-
alias :edit :update
114+
alias_method :edit, :update
118115

119116
# Delete an authorization
120117
#
121118
# @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
122119
#
123120
# @example
124-
# github.oauth.delete 'authorization-id'
121+
# github = Github.new
122+
# github.oauth.delete 'authorization-id'
125123
#
126124
# @api public
127125
def delete(*args)
@@ -130,14 +128,13 @@ def delete(*args)
130128

131129
delete_request("/authorizations/#{arguments.id}", arguments.params)
132130
end
133-
alias :remove :delete
131+
alias_method :remove, :delete
134132

135133
protected
136134

137135
def raise_authentication_error
138-
raise ArgumentError, 'You can only access your own tokens' +
139-
' via Basic Authentication'
136+
raise ArgumentError, 'You can only access your own tokens' \
137+
' via Basic Authentication'
140138
end
141-
142139
end # Client::Authorizations
143140
end # Github

spec/github/client/authorizations/create_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
describe Github::Client::Authorizations, '#create' do
66
let(:basic_auth) { 'login:password' }
77
let(:host) { "https://#{basic_auth}@api.github.com" }
8-
let(:inputs) { { :scopes => ['repo'] } }
8+
let(:inputs) { {scopes: ['repo'], note: 'admin script' } }
99
let(:request_path) { "/authorizations" }
1010

1111
before {
@@ -21,7 +21,6 @@
2121
let(:body) { fixture('auths/authorization.json') }
2222
let(:status) { 201 }
2323

24-
2524
it "fails to get resource without basic authentication" do
2625
reset_authentication_for subject
2726
expect { subject.create }.to raise_error(ArgumentError)
@@ -37,6 +36,13 @@
3736
authorization.should be_a Github::ResponseWrapper
3837
end
3938

39+
it "fails without a note parameter" do
40+
expect {
41+
subject.create scopes: ['repos']
42+
}.to raise_error(Github::Error::RequiredParams,
43+
/Required parameters are: note/)
44+
end
45+
4046
it "gets the authorization information" do
4147
authorization = subject.create inputs
4248
authorization.token.should == 'abc123'

0 commit comments

Comments
 (0)