github_api 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +50 -5
- data/features/cassettes/git_data/commits/get.yml +69 -0
- data/features/git_data/commmits.feature +14 -0
- data/lib/github_api.rb +1 -0
- data/lib/github_api/activity/events.rb +42 -33
- data/lib/github_api/activity/notifications.rb +22 -22
- data/lib/github_api/activity/starring.rb +16 -21
- data/lib/github_api/activity/watching.rb +16 -19
- data/lib/github_api/api.rb +51 -8
- data/lib/github_api/arguments.rb +155 -0
- data/lib/github_api/authorizations.rb +19 -20
- data/lib/github_api/configuration.rb +5 -0
- data/lib/github_api/emojis.rb +3 -3
- data/lib/github_api/error/validations.rb +2 -2
- data/lib/github_api/gists.rb +32 -42
- data/lib/github_api/gists/comments.rb +21 -23
- data/lib/github_api/git_data/blobs.rb +13 -16
- data/lib/github_api/git_data/commits.rb +12 -10
- data/lib/github_api/git_data/references.rb +24 -28
- data/lib/github_api/git_data/tags.rb +9 -11
- data/lib/github_api/git_data/trees.rb +10 -13
- data/lib/github_api/gitignore.rb +4 -6
- data/lib/github_api/issues.rb +24 -32
- data/lib/github_api/issues/assignees.rb +11 -8
- data/lib/github_api/issues/comments.rb +21 -26
- data/lib/github_api/issues/events.rb +7 -9
- data/lib/github_api/issues/labels.rb +39 -53
- data/lib/github_api/issues/milestones.rb +26 -33
- data/lib/github_api/markdown.rb +5 -6
- data/lib/github_api/meta.rb +3 -3
- data/lib/github_api/orgs.rb +10 -11
- data/lib/github_api/orgs/members.rb +18 -20
- data/lib/github_api/orgs/teams.rb +54 -58
- data/lib/github_api/pull_requests.rb +40 -54
- data/lib/github_api/pull_requests/comments.rb +19 -26
- data/lib/github_api/repos.rb +146 -101
- data/lib/github_api/repos/collaborators.rb +29 -30
- data/lib/github_api/repos/comments.rb +20 -25
- data/lib/github_api/repos/commits.rb +12 -14
- data/lib/github_api/repos/contents.rb +22 -14
- data/lib/github_api/repos/downloads.rb +19 -23
- data/lib/github_api/repos/forks.rb +6 -11
- data/lib/github_api/repos/hooks.rb +25 -34
- data/lib/github_api/repos/keys.rb +25 -27
- data/lib/github_api/repos/merging.rb +7 -6
- data/lib/github_api/repos/pub_sub_hubbub.rb +14 -18
- data/lib/github_api/repos/statuses.rb +13 -14
- data/lib/github_api/say.rb +1 -3
- data/lib/github_api/search.rb +12 -21
- data/lib/github_api/users.rb +10 -9
- data/lib/github_api/users/emails.rb +11 -9
- data/lib/github_api/users/followers.rb +25 -23
- data/lib/github_api/users/keys.rb +27 -29
- data/lib/github_api/version.rb +1 -1
- data/spec/github/activity/events/org_spec.rb +6 -6
- data/spec/github/activity/events/performed_spec.rb +1 -1
- data/spec/github/activity/events/received_spec.rb +1 -1
- data/spec/github/activity/events/user_org_spec.rb +4 -2
- data/spec/github/activity/notifications/create_spec.rb +1 -1
- data/spec/github/activity/notifications/delete_spec.rb +1 -1
- data/spec/github/activity/notifications/get_spec.rb +1 -1
- data/spec/github/activity/notifications/subscribed_spec.rb +1 -1
- data/spec/github/activity/starring/list_spec.rb +2 -0
- data/spec/github/activity/starring/starring_spec.rb +1 -1
- data/spec/github/activity/watching/list_spec.rb +2 -0
- data/spec/github/activity/watching/watching_spec.rb +1 -3
- data/spec/github/api/set_spec.rb +18 -4
- data/spec/github/api/with_spec.rb +28 -0
- data/spec/github/api_spec.rb +11 -33
- data/spec/github/arguments/parse_spec.rb +68 -0
- data/spec/github/authorizations/delete_spec.rb +1 -1
- data/spec/github/authorizations/get_spec.rb +1 -1
- data/spec/github/error/validations_spec.rb +3 -3
- data/spec/github/gists/comments/list_spec.rb +1 -1
- data/spec/github/gists/delete_spec.rb +1 -1
- data/spec/github/gists/fork_spec.rb +1 -1
- data/spec/github/gists/get_spec.rb +1 -1
- data/spec/github/gists/is_starred_spec.rb +2 -0
- data/spec/github/gists/star_spec.rb +1 -1
- data/spec/github/gists/unstar_spec.rb +1 -1
- data/spec/github/git_data/blobs/create_spec.rb +2 -0
- data/spec/github/git_data/blobs/get_spec.rb +1 -1
- data/spec/github/git_data/commits/create_spec.rb +2 -0
- data/spec/github/git_data/commits/get_spec.rb +3 -3
- data/spec/github/git_data/references/create_spec.rb +1 -1
- data/spec/github/git_data/references/delete_spec.rb +3 -1
- data/spec/github/git_data/tags/create_spec.rb +2 -0
- data/spec/github/gitignore/get_spec.rb +1 -1
- data/spec/github/issues/events/get_spec.rb +3 -1
- data/spec/github/issues/events/list_spec.rb +3 -1
- data/spec/github/issues/labels/add_spec.rb +6 -6
- data/spec/github/issues/labels/list_spec.rb +3 -1
- data/spec/github/issues/labels/replace_spec.rb +6 -7
- data/spec/github/issues/milestones/get_spec.rb +2 -0
- data/spec/github/normalizer_spec.rb +18 -6
- data/spec/github/orgs/members/conceal_spec.rb +6 -4
- data/spec/github/orgs/members/delete_spec.rb +2 -0
- data/spec/github/orgs/members/list_spec.rb +1 -1
- data/spec/github/orgs/members/member_spec.rb +3 -1
- data/spec/github/orgs/members/publicize_spec.rb +2 -0
- data/spec/github/orgs/teams/add_member_spec.rb +2 -0
- data/spec/github/orgs/teams/create_spec.rb +1 -1
- data/spec/github/orgs/teams/delete_spec.rb +1 -1
- data/spec/github/orgs/teams/edit_spec.rb +1 -1
- data/spec/github/orgs/teams/get_spec.rb +1 -1
- data/spec/github/orgs/teams/list_spec.rb +1 -1
- data/spec/github/orgs/teams/team_member_spec.rb +3 -1
- data/spec/github/parameter_filter_spec.rb +19 -58
- data/spec/github/pull_requests/comments/create_spec.rb +3 -1
- data/spec/github/pull_requests/comments/delete_spec.rb +1 -1
- data/spec/github/pull_requests/comments/edit_spec.rb +2 -0
- data/spec/github/pull_requests/comments/get_spec.rb +3 -1
- data/spec/github/pull_requests/comments/list_spec.rb +3 -1
- data/spec/github/pull_requests/commits_spec.rb +3 -3
- data/spec/github/pull_requests/create_spec.rb +4 -0
- data/spec/github/pull_requests/files_spec.rb +4 -0
- data/spec/github/pull_requests/get_spec.rb +3 -3
- data/spec/github/pull_requests/list_spec.rb +3 -3
- data/spec/github/pull_requests/merge_spec.rb +2 -0
- data/spec/github/pull_requests/merged_spec.rb +3 -1
- data/spec/github/pull_requests/update_spec.rb +4 -0
- data/spec/github/repos/collaborators/add_spec.rb +3 -1
- data/spec/github/repos/collaborators/get_spec.rb +1 -3
- data/spec/github/repos/collaborators/list_spec.rb +5 -1
- data/spec/github/repos/collaborators/remove_spec.rb +3 -1
- data/spec/github/repos/comments/create_spec.rb +4 -0
- data/spec/github/repos/comments/delete_spec.rb +2 -2
- data/spec/github/repos/comments/get_spec.rb +6 -2
- data/spec/github/repos/commits/compare_spec.rb +3 -3
- data/spec/github/repos/commits/get_spec.rb +3 -3
- data/spec/github/repos/commits/list_spec.rb +3 -3
- data/spec/github/repos/contents/archive_spec.rb +12 -0
- data/spec/github/repos/contents/get_spec.rb +5 -0
- data/spec/github/repos/contributors_spec.rb +7 -2
- data/spec/github/repos/downloads/create_spec.rb +4 -0
- data/spec/github/repos/downloads/delete_spec.rb +5 -1
- data/spec/github/repos/downloads/get_spec.rb +3 -1
- data/spec/github/repos/downloads/list_spec.rb +3 -1
- data/spec/github/repos/forks/create_spec.rb +2 -0
- data/spec/github/repos/forks/list_spec.rb +3 -1
- data/spec/github/repos/hooks/edit_spec.rb +1 -1
- data/spec/github/repos/keys/delete_spec.rb +1 -1
- data/spec/github/repos/keys/edit_spec.rb +2 -0
- data/spec/github/repos/keys/get_spec.rb +3 -1
- data/spec/github/repos/keys/list_spec.rb +4 -2
- data/spec/github/repos/list_spec.rb +6 -1
- data/spec/github/repos/pub_sub_hubbub/subscribe_service_spec.rb +27 -0
- data/spec/github/repos/pub_sub_hubbub/subscribe_spec.rb +51 -0
- data/spec/github/repos/pub_sub_hubbub/unsubscribe_service_spec.rb +21 -0
- data/spec/github/repos/pub_sub_hubbub/unsubscribe_spec.rb +58 -0
- data/spec/github/repos/statuses/create_spec.rb +2 -0
- data/spec/github/search_spec.rb +25 -10
- data/spec/github/users/followers/follow_spec.rb +1 -1
- data/spec/github/users/followers/is_following_spec.rb +1 -1
- data/spec/github/users/followers/unfollow_spec.rb +1 -1
- data/spec/github/users/keys/delete_spec.rb +1 -1
- data/spec/github/users/keys/get_spec.rb +1 -1
- data/spec/github/users/keys/update_spec.rb +1 -1
- data/spec/github/users/update_spec.rb +1 -1
- data/spec/integration/arguments_spec.rb +76 -0
- data/spec/{github → integration}/authorizations_spec.rb +0 -0
- metadata +44 -35
- data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -78
|
@@ -12,12 +12,10 @@ module Github
|
|
|
12
12
|
# github.activity.watching.list
|
|
13
13
|
# github.activity.watching.list { |watcher| ... }
|
|
14
14
|
#
|
|
15
|
-
def list(
|
|
16
|
-
|
|
17
|
-
assert_presence_of user, repo
|
|
18
|
-
normalize! params
|
|
15
|
+
def list(*args)
|
|
16
|
+
arguments(args, :required => [:user, :repo])
|
|
19
17
|
|
|
20
|
-
response = get_request("/repos/#{user}/#{repo}/subscribers", params)
|
|
18
|
+
response = get_request("/repos/#{user}/#{repo}/subscribers", arguments.params)
|
|
21
19
|
return response unless block_given?
|
|
22
20
|
response.each { |el| yield el }
|
|
23
21
|
end
|
|
@@ -36,8 +34,7 @@ module Github
|
|
|
36
34
|
# github.activity.watching.watched
|
|
37
35
|
#
|
|
38
36
|
def watched(*args)
|
|
39
|
-
params = args.
|
|
40
|
-
normalize! params
|
|
37
|
+
params = arguments(args).params
|
|
41
38
|
|
|
42
39
|
response = if (user_name = params.delete('user'))
|
|
43
40
|
get_request("/users/#{user_name}/subscriptions", params)
|
|
@@ -55,10 +52,10 @@ module Github
|
|
|
55
52
|
# github = Github.new
|
|
56
53
|
# github.activity.watching.watching? 'user-name', 'repo-name'
|
|
57
54
|
#
|
|
58
|
-
def watching?(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
get_request("/user/subscriptions/#{
|
|
55
|
+
def watching?(*args)
|
|
56
|
+
arguments(args, :required => [:user, :repo])
|
|
57
|
+
|
|
58
|
+
get_request("/user/subscriptions/#{user}/#{repo}", arguments.params)
|
|
62
59
|
true
|
|
63
60
|
rescue Github::Error::NotFound
|
|
64
61
|
false
|
|
@@ -72,10 +69,10 @@ module Github
|
|
|
72
69
|
# github = Github.new
|
|
73
70
|
# github.activity.watching.watch 'user-name', 'repo-name'
|
|
74
71
|
#
|
|
75
|
-
def watch(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
put_request("/user/subscriptions/#{
|
|
72
|
+
def watch(*args)
|
|
73
|
+
arguments(args, :required => [:user, :repo])
|
|
74
|
+
|
|
75
|
+
put_request("/user/subscriptions/#{user}/#{repo}", arguments.params)
|
|
79
76
|
end
|
|
80
77
|
|
|
81
78
|
# Stop watching a repository
|
|
@@ -85,10 +82,10 @@ module Github
|
|
|
85
82
|
# github = Github.new
|
|
86
83
|
# github.activity.watching.unwatch 'user-name', 'repo-name'
|
|
87
84
|
#
|
|
88
|
-
def unwatch(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
delete_request("/user/subscriptions/#{
|
|
85
|
+
def unwatch(*args)
|
|
86
|
+
arguments(args, :required => [:user, :repo])
|
|
87
|
+
|
|
88
|
+
delete_request("/user/subscriptions/#{user}/#{repo}", arguments.params)
|
|
92
89
|
end
|
|
93
90
|
|
|
94
91
|
end # Activity::Watching
|
data/lib/github_api/api.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'github_api/configuration'
|
|
4
4
|
require 'github_api/connection'
|
|
5
|
-
require 'github_api/validations'
|
|
6
5
|
require 'github_api/request'
|
|
7
6
|
require 'github_api/mime_type'
|
|
8
7
|
require 'github_api/rate_limit'
|
|
@@ -21,16 +20,10 @@ module Github
|
|
|
21
20
|
include Connection
|
|
22
21
|
include Request
|
|
23
22
|
include RateLimit
|
|
24
|
-
# include Configuration
|
|
25
|
-
|
|
26
|
-
# TODO consider these optional in a stack
|
|
27
|
-
include Validations
|
|
28
|
-
include ParameterFilter
|
|
29
|
-
include Normalizer
|
|
30
23
|
|
|
31
24
|
attr_reader *Configuration.keys
|
|
32
25
|
|
|
33
|
-
attr_accessor *VALID_API_KEYS
|
|
26
|
+
attr_accessor *Validations::VALID_API_KEYS
|
|
34
27
|
|
|
35
28
|
attr_accessor :current_options
|
|
36
29
|
|
|
@@ -92,9 +85,36 @@ module Github
|
|
|
92
85
|
end
|
|
93
86
|
end
|
|
94
87
|
|
|
88
|
+
# Acts as setter and getter for api requests arguments parsing.
|
|
89
|
+
#
|
|
90
|
+
# Returns Arguments instance.
|
|
91
|
+
#
|
|
92
|
+
def arguments(args=(not_set = true), options={}, &block)
|
|
93
|
+
if not_set
|
|
94
|
+
@arguments
|
|
95
|
+
else
|
|
96
|
+
@arguments = Arguments.new(self, options).parse(*args, &block)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Scope for passing request required arguments.
|
|
101
|
+
#
|
|
102
|
+
def with(args)
|
|
103
|
+
case args
|
|
104
|
+
when Hash
|
|
105
|
+
set args
|
|
106
|
+
when /.*\/.*/i
|
|
107
|
+
user, repo = args.split('/')
|
|
108
|
+
set :user => user, :repo => repo
|
|
109
|
+
else
|
|
110
|
+
::Kernel.raise ArgumentError, 'This api does not support passed in arguments'
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
95
114
|
# Set an option to a given value
|
|
96
115
|
def set(option, value=(not_set = true), &block)
|
|
97
116
|
raise ArgumentError, 'value not set' if block and !not_set
|
|
117
|
+
return self if !not_set and value.nil?
|
|
98
118
|
|
|
99
119
|
if not_set
|
|
100
120
|
set_options option
|
|
@@ -105,12 +125,14 @@ module Github
|
|
|
105
125
|
return __send__("#{option}=", value)
|
|
106
126
|
end
|
|
107
127
|
|
|
128
|
+
define_accessors option, value
|
|
108
129
|
self
|
|
109
130
|
end
|
|
110
131
|
|
|
111
132
|
private
|
|
112
133
|
|
|
113
134
|
# Set multiple options
|
|
135
|
+
#
|
|
114
136
|
def set_options(options)
|
|
115
137
|
unless options.respond_to?(:each)
|
|
116
138
|
raise ArgumentError, 'cannot iterate over value'
|
|
@@ -118,6 +140,27 @@ module Github
|
|
|
118
140
|
options.each { |key, value| set(key, value) }
|
|
119
141
|
end
|
|
120
142
|
|
|
143
|
+
def define_accessors(option, value)
|
|
144
|
+
setter = proc { |val| set option, value }
|
|
145
|
+
getter = proc { value }
|
|
146
|
+
|
|
147
|
+
define_singleton_method("#{option}=", setter) if setter
|
|
148
|
+
define_singleton_method(option, getter) if getter
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Dynamically define a method for setting request option
|
|
152
|
+
#
|
|
153
|
+
def define_singleton_method(name, content=Proc.new)
|
|
154
|
+
(class << self; self; end).class_eval do
|
|
155
|
+
undef_method(name) if method_defined? name
|
|
156
|
+
if String === content
|
|
157
|
+
class_eval("def #{name}() #{content}; end")
|
|
158
|
+
else
|
|
159
|
+
define_method(name, &content)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
121
164
|
def _merge_mime_type(resource, params) # :nodoc:
|
|
122
165
|
# params['resource'] = resource
|
|
123
166
|
# params['mime_type'] = params['mime_type'] || :raw
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Github
|
|
4
|
+
# Request arguments handler
|
|
5
|
+
class Arguments
|
|
6
|
+
|
|
7
|
+
include Normalizer
|
|
8
|
+
include ParameterFilter
|
|
9
|
+
include Validations
|
|
10
|
+
|
|
11
|
+
# Parameters passed to request
|
|
12
|
+
attr_reader :params
|
|
13
|
+
|
|
14
|
+
attr_reader :remaining
|
|
15
|
+
|
|
16
|
+
# The request api
|
|
17
|
+
#
|
|
18
|
+
attr_reader :api
|
|
19
|
+
|
|
20
|
+
# Required arguments
|
|
21
|
+
#
|
|
22
|
+
attr_reader :required
|
|
23
|
+
private :required
|
|
24
|
+
|
|
25
|
+
# Optional arguments
|
|
26
|
+
#
|
|
27
|
+
attr_reader :optional
|
|
28
|
+
private :optional
|
|
29
|
+
|
|
30
|
+
# Takes api, filters and required arguments
|
|
31
|
+
#
|
|
32
|
+
# = Parameters
|
|
33
|
+
# :required - arguments that must be present before request is fired
|
|
34
|
+
#
|
|
35
|
+
def initialize(api, options={})
|
|
36
|
+
normalize! options
|
|
37
|
+
@api = api
|
|
38
|
+
@required = options.fetch('required', []).map(&:to_s)
|
|
39
|
+
@optional = options.fetch('optional', []).map(&:to_s)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Parse arguments to allow for flexible api calls.
|
|
43
|
+
# Arguments can be part of parameters hash or be simple string arguments.
|
|
44
|
+
#
|
|
45
|
+
def parse(*args, &block)
|
|
46
|
+
options = args.extract_options!
|
|
47
|
+
normalize! options
|
|
48
|
+
|
|
49
|
+
if !args.size.zero?
|
|
50
|
+
parse_arguments *args
|
|
51
|
+
else
|
|
52
|
+
# Arguments are inside the parameters hash
|
|
53
|
+
parse_options options
|
|
54
|
+
end
|
|
55
|
+
@params = options
|
|
56
|
+
@remaining = extract_remaining(args)
|
|
57
|
+
yield_or_eval(&block)
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Remove unkown keys from parameters hash.
|
|
62
|
+
#
|
|
63
|
+
# = Parameters
|
|
64
|
+
# :recursive - boolean that toggles whether nested filtering should be applied
|
|
65
|
+
#
|
|
66
|
+
def sift(keys, key=nil, options={})
|
|
67
|
+
filter! keys, (key.nil? ? params : params[key]), options if keys.any?
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Check if required keys are present inside parameters hash.
|
|
72
|
+
#
|
|
73
|
+
def assert_required(required)
|
|
74
|
+
assert_required_keys required, params
|
|
75
|
+
self
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Check if parameters match expected values.
|
|
79
|
+
#
|
|
80
|
+
def assert_values(values, key=nil)
|
|
81
|
+
assert_valid_values values, (key.nil? ? params : params[key])
|
|
82
|
+
self
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
# Check and set all requried arguments.
|
|
88
|
+
#
|
|
89
|
+
def parse_arguments(*args)
|
|
90
|
+
assert_presence_of *args
|
|
91
|
+
required.each_with_index do |req, indx|
|
|
92
|
+
api.set req, args[indx]
|
|
93
|
+
end
|
|
94
|
+
check_requirement!(*args)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Find remaining arguments
|
|
98
|
+
#
|
|
99
|
+
def extract_remaining(args)
|
|
100
|
+
args[required.size..-1]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Remove required arguments from parameters and
|
|
104
|
+
# validate their presence(if not nil or empty string).
|
|
105
|
+
#
|
|
106
|
+
def parse_options(options)
|
|
107
|
+
options.each { |key, val| remove_required(options, key, val) }
|
|
108
|
+
provided_args = check_assignment!(options)
|
|
109
|
+
check_requirement!(*provided_args.keys)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Remove required argument from parameters
|
|
113
|
+
#
|
|
114
|
+
def remove_required(options, key, val)
|
|
115
|
+
key = key.to_s
|
|
116
|
+
if required.include? key
|
|
117
|
+
assert_presence_of val
|
|
118
|
+
options.delete key
|
|
119
|
+
api.set key, val
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Check if required arguments have been set on instance.
|
|
124
|
+
#
|
|
125
|
+
def check_assignment!(options)
|
|
126
|
+
result = required.inject({}) { |hash, arg|
|
|
127
|
+
if api.respond_to?(:"#{arg}") && (value = api.send(:"#{arg}"))
|
|
128
|
+
hash[arg] = value
|
|
129
|
+
end
|
|
130
|
+
hash
|
|
131
|
+
}
|
|
132
|
+
assert_presence_of result
|
|
133
|
+
result
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Check if required arguments are present.
|
|
137
|
+
#
|
|
138
|
+
def check_requirement!(*args)
|
|
139
|
+
args_length = args.length
|
|
140
|
+
required_length = required.length
|
|
141
|
+
|
|
142
|
+
if args_length < required_length
|
|
143
|
+
::Kernel.raise ArgumentError, "wrong number of arguments (#{args_length} for #{required_length})"
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Evaluate block
|
|
148
|
+
#
|
|
149
|
+
def yield_or_eval(&block)
|
|
150
|
+
return unless block
|
|
151
|
+
block.arity > 0 ? yield(self) : self.instance_eval(&block)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end # Arguments
|
|
155
|
+
end # Github
|
|
@@ -20,11 +20,11 @@ module Github
|
|
|
20
20
|
# github.oauth.list
|
|
21
21
|
# github.oauth.list { |auth| ... }
|
|
22
22
|
#
|
|
23
|
-
def list(
|
|
23
|
+
def list(*args)
|
|
24
24
|
_check_if_authenticated
|
|
25
|
-
|
|
25
|
+
arguments(args)
|
|
26
26
|
|
|
27
|
-
response = get_request("/authorizations", params)
|
|
27
|
+
response = get_request("/authorizations", arguments.params)
|
|
28
28
|
return response unless block_given?
|
|
29
29
|
response.each { |el| yield el }
|
|
30
30
|
end
|
|
@@ -36,12 +36,11 @@ module Github
|
|
|
36
36
|
# github = Github.new :basic_auth => 'login:password'
|
|
37
37
|
# github.oauth.get 'authorization-id'
|
|
38
38
|
#
|
|
39
|
-
def get(
|
|
40
|
-
assert_presence_of(authorization_id)
|
|
39
|
+
def get(*args)
|
|
41
40
|
_check_if_authenticated
|
|
42
|
-
|
|
41
|
+
arguments(args, :required => [:authorization_id])
|
|
43
42
|
|
|
44
|
-
get_request("/authorizations/#{authorization_id}", params)
|
|
43
|
+
get_request("/authorizations/#{authorization_id}", arguments.params)
|
|
45
44
|
end
|
|
46
45
|
alias :find :get
|
|
47
46
|
|
|
@@ -57,12 +56,13 @@ module Github
|
|
|
57
56
|
# github.oauth.create
|
|
58
57
|
# "scopes" => ["public_repo"]
|
|
59
58
|
#
|
|
60
|
-
def create(
|
|
59
|
+
def create(*args)
|
|
61
60
|
_check_if_authenticated
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
arguments(args) do
|
|
62
|
+
sift VALID_AUTH_PARAM_NAMES
|
|
63
|
+
end
|
|
64
64
|
|
|
65
|
-
post_request("/authorizations", params)
|
|
65
|
+
post_request("/authorizations", arguments.params)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# Update an existing authorization
|
|
@@ -78,13 +78,13 @@ module Github
|
|
|
78
78
|
# github = Github.new :basic_auth => 'login:password'
|
|
79
79
|
# github.oauth.update "authorization-id", "add_scopes" => ["repo"],
|
|
80
80
|
#
|
|
81
|
-
def update(
|
|
81
|
+
def update(*args)
|
|
82
82
|
_check_if_authenticated
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
arguments(args, :required => [:authorization_id]) do
|
|
84
|
+
sift VALID_AUTH_PARAM_NAMES
|
|
85
|
+
end
|
|
86
86
|
|
|
87
|
-
patch_request("/authorizations/#{authorization_id}", params)
|
|
87
|
+
patch_request("/authorizations/#{authorization_id}", arguments.params)
|
|
88
88
|
end
|
|
89
89
|
alias :edit :update
|
|
90
90
|
|
|
@@ -93,12 +93,11 @@ module Github
|
|
|
93
93
|
# = Examples
|
|
94
94
|
# github.oauth.delete 'authorization-id'
|
|
95
95
|
#
|
|
96
|
-
def delete(
|
|
96
|
+
def delete(*args)
|
|
97
97
|
_check_if_authenticated
|
|
98
|
-
|
|
99
|
-
normalize! params
|
|
98
|
+
arguments(args, :required => [:authorization_id])
|
|
100
99
|
|
|
101
|
-
delete_request("/authorizations/#{authorization_id}", params)
|
|
100
|
+
delete_request("/authorizations/#{authorization_id}", arguments.params)
|
|
102
101
|
end
|
|
103
102
|
alias :remove :delete
|
|
104
103
|
|
|
@@ -16,6 +16,7 @@ module Github
|
|
|
16
16
|
:connection_options,
|
|
17
17
|
:repo,
|
|
18
18
|
:user,
|
|
19
|
+
:org,
|
|
19
20
|
:login,
|
|
20
21
|
:password,
|
|
21
22
|
:basic_auth
|
|
@@ -66,6 +67,9 @@ module Github
|
|
|
66
67
|
# By default, don't set repository name
|
|
67
68
|
DEFAULT_REPO = nil
|
|
68
69
|
|
|
70
|
+
# By default, don't set organization name
|
|
71
|
+
DEFAULT_ORG = nil
|
|
72
|
+
|
|
69
73
|
attr_accessor *VALID_OPTIONS_KEYS
|
|
70
74
|
|
|
71
75
|
# Convenience method to allow for global setting of configuration options
|
|
@@ -104,6 +108,7 @@ module Github
|
|
|
104
108
|
self.mime_type = DEFAULT_MIME_TYPE
|
|
105
109
|
self.user = DEFAULT_USER
|
|
106
110
|
self.repo = DEFAULT_REPO
|
|
111
|
+
self.org = DEFAULT_ORG
|
|
107
112
|
self.login = DEFAULT_LOGIN
|
|
108
113
|
self.password = DEFAULT_PASSWORD
|
|
109
114
|
self.basic_auth = DEFAULT_BASIC_AUTH
|
data/lib/github_api/emojis.rb
CHANGED