github_api 0.6.0 → 0.6.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 +2 -1
- data/lib/github_api/api.rb +5 -3
- data/lib/github_api/authorizations.rb +8 -8
- data/lib/github_api/connection.rb +1 -1
- data/lib/github_api/events.rb +8 -8
- data/lib/github_api/gists/comments.rb +7 -7
- data/lib/github_api/gists.rb +10 -10
- data/lib/github_api/git_data/blobs.rb +3 -3
- data/lib/github_api/git_data/commits.rb +3 -3
- data/lib/github_api/git_data/references.rb +7 -7
- data/lib/github_api/git_data/tags.rb +3 -3
- data/lib/github_api/git_data/trees.rb +3 -3
- data/lib/github_api/issues/comments.rb +7 -7
- data/lib/github_api/issues/events.rb +2 -2
- data/lib/github_api/issues/labels.rb +12 -11
- data/lib/github_api/issues/milestones.rb +8 -8
- data/lib/github_api/issues.rb +9 -9
- data/lib/github_api/normalizer.rb +27 -0
- data/lib/github_api/orgs/members.rb +7 -7
- data/lib/github_api/orgs/teams.rb +15 -16
- data/lib/github_api/orgs.rb +4 -3
- data/lib/github_api/parameter_filter.rb +32 -0
- data/lib/github_api/pull_requests/comments.rb +7 -7
- data/lib/github_api/pull_requests.rb +12 -12
- data/lib/github_api/repos/collaborators.rb +4 -4
- data/lib/github_api/repos/commits.rb +11 -11
- data/lib/github_api/repos/contents.rb +3 -3
- data/lib/github_api/repos/downloads.rb +5 -5
- data/lib/github_api/repos/forks.rb +3 -3
- data/lib/github_api/repos/hooks.rb +8 -8
- data/lib/github_api/repos/keys.rb +7 -7
- data/lib/github_api/repos/pub_sub_hubbub.rb +4 -4
- data/lib/github_api/repos/watching.rb +5 -5
- data/lib/github_api/repos.rb +13 -13
- data/lib/github_api/search.rb +4 -4
- data/lib/github_api/users/emails.rb +3 -3
- data/lib/github_api/users/followers.rb +5 -5
- data/lib/github_api/users/keys.rb +7 -7
- data/lib/github_api/users.rb +3 -3
- data/lib/github_api/validations/presence.rb +1 -0
- data/lib/github_api/version.rb +1 -1
- data/lib/github_api.rb +26 -25
- data/spec/github/api_spec.rb +4 -4
- data/spec/github/normalizer_spec.rb +20 -0
- data/spec/github/parameter_filter_spec.rb +71 -0
- metadata +42 -40
- data/lib/github_api/filter.rb +0 -57
- data/spec/github/filter_spec.rb +0 -82
@@ -44,7 +44,7 @@ module Github
|
|
44
44
|
def list(user_name, repo_name, params={})
|
45
45
|
_update_user_repo_params(user_name, repo_name)
|
46
46
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
47
|
-
|
47
|
+
normalize! params
|
48
48
|
|
49
49
|
response = get_request("/repos/#{user}/#{repo}/hooks", params)
|
50
50
|
return response unless block_given?
|
@@ -62,7 +62,7 @@ module Github
|
|
62
62
|
_update_user_repo_params(user_name, repo_name)
|
63
63
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
64
64
|
_validate_presence_of hook_id
|
65
|
-
|
65
|
+
normalize! params
|
66
66
|
|
67
67
|
get_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
68
68
|
end
|
@@ -90,8 +90,8 @@ module Github
|
|
90
90
|
_update_user_repo_params(user_name, repo_name)
|
91
91
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
normalize! params
|
94
|
+
filter! VALID_HOOK_PARAM_NAMES, params, :recursive => false
|
95
95
|
assert_required_keys(REQUIRED_PARAMS, params)
|
96
96
|
|
97
97
|
post_request("/repos/#{user}/#{repo}/hooks", params)
|
@@ -123,8 +123,8 @@ module Github
|
|
123
123
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
124
124
|
_validate_presence_of hook_id
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
normalize! params
|
127
|
+
filter! VALID_HOOK_PARAM_NAMES, params, :recursive => false
|
128
128
|
assert_required_keys(REQUIRED_PARAMS, params)
|
129
129
|
|
130
130
|
patch_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
@@ -142,7 +142,7 @@ module Github
|
|
142
142
|
_update_user_repo_params(user_name, repo_name)
|
143
143
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
144
144
|
_validate_presence_of hook_id
|
145
|
-
|
145
|
+
normalize! params
|
146
146
|
|
147
147
|
post_request("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
|
148
148
|
end
|
@@ -157,7 +157,7 @@ module Github
|
|
157
157
|
_update_user_repo_params(user_name, repo_name)
|
158
158
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
159
159
|
_validate_presence_of hook_id
|
160
|
-
|
160
|
+
normalize! params
|
161
161
|
|
162
162
|
delete_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
163
163
|
end
|
@@ -15,7 +15,7 @@ module Github
|
|
15
15
|
def list(user_name, repo_name, params={})
|
16
16
|
_update_user_repo_params(user_name, repo_name)
|
17
17
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
18
|
-
|
18
|
+
normalize! params
|
19
19
|
|
20
20
|
response = get_request("/repos/#{user}/#{repo}/keys", params)
|
21
21
|
return response unless block_given?
|
@@ -33,7 +33,7 @@ module Github
|
|
33
33
|
_update_user_repo_params(user_name, repo_name)
|
34
34
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
35
35
|
_validate_presence_of key_id
|
36
|
-
|
36
|
+
normalize! params
|
37
37
|
|
38
38
|
get_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
39
39
|
end
|
@@ -54,8 +54,8 @@ module Github
|
|
54
54
|
def create(user_name, repo_name, params={})
|
55
55
|
_update_user_repo_params(user_name, repo_name)
|
56
56
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
57
|
-
|
58
|
-
|
57
|
+
normalize! params
|
58
|
+
filter! VALID_KEY_PARAM_NAMES, params
|
59
59
|
assert_required_keys(VALID_KEY_PARAM_NAMES, params)
|
60
60
|
|
61
61
|
post_request("/repos/#{user}/#{repo}/keys", params)
|
@@ -78,8 +78,8 @@ module Github
|
|
78
78
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
79
79
|
_validate_presence_of key_id
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
normalize! params
|
82
|
+
filter! VALID_KEY_PARAM_NAMES, params
|
83
83
|
|
84
84
|
patch_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
85
85
|
end
|
@@ -94,7 +94,7 @@ module Github
|
|
94
94
|
_update_user_repo_params(user_name, repo_name)
|
95
95
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
96
96
|
_validate_presence_of key_id
|
97
|
-
|
97
|
+
normalize! params
|
98
98
|
|
99
99
|
delete_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
100
100
|
end
|
@@ -19,7 +19,7 @@ module Github
|
|
19
19
|
#
|
20
20
|
def subscribe(topic, callback, params={})
|
21
21
|
_validate_presence_of topic, callback
|
22
|
-
|
22
|
+
normalize! params
|
23
23
|
_merge_action!("subscribe", topic, callback, params)
|
24
24
|
|
25
25
|
post_request("/hub", params)
|
@@ -41,7 +41,7 @@ module Github
|
|
41
41
|
#
|
42
42
|
def unsubscribe(topic, callback, params={})
|
43
43
|
_validate_presence_of topic, callback
|
44
|
-
|
44
|
+
normalize! params
|
45
45
|
_merge_action!("unsubscribe", topic, callback, params)
|
46
46
|
|
47
47
|
post_request("/hub", params)
|
@@ -64,7 +64,7 @@ module Github
|
|
64
64
|
#
|
65
65
|
def subscribe_service(user_name, repo_name, service_name, params={})
|
66
66
|
_validate_presence_of user_name, repo_name, service_name
|
67
|
-
|
67
|
+
normalize! params
|
68
68
|
event = params.delete('event') || 'push'
|
69
69
|
topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
|
70
70
|
callback = "github://#{service_name}?#{params.serialize}"
|
@@ -87,7 +87,7 @@ module Github
|
|
87
87
|
#
|
88
88
|
def unsubscribe_service(user_name, repo_name, service_name, params={})
|
89
89
|
_validate_presence_of user_name, repo_name, service_name
|
90
|
-
|
90
|
+
normalize! params
|
91
91
|
event = params.delete('event') || 'push'
|
92
92
|
topic = "https://github.com/#{user_name}/#{repo_name}/events/#{event}"
|
93
93
|
callback = "github://#{service_name}"
|
@@ -13,7 +13,7 @@ module Github
|
|
13
13
|
def watchers(user_name, repo_name, params={})
|
14
14
|
_update_user_repo_params(user_name, repo_name)
|
15
15
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
16
|
-
|
16
|
+
normalize! params
|
17
17
|
|
18
18
|
response = get_request("/repos/#{user}/#{repo}/watchers", params)
|
19
19
|
return response unless block_given?
|
@@ -34,7 +34,7 @@ module Github
|
|
34
34
|
#
|
35
35
|
def watched(*args)
|
36
36
|
params = args.extract_options!
|
37
|
-
|
37
|
+
normalize! params
|
38
38
|
_merge_user_into_params!(params) unless params.has_key?('user')
|
39
39
|
|
40
40
|
response = if (user_name = params.delete('user'))
|
@@ -55,7 +55,7 @@ module Github
|
|
55
55
|
#
|
56
56
|
def watching?(user_name, repo_name, params={})
|
57
57
|
_validate_presence_of user_name, repo_name
|
58
|
-
|
58
|
+
normalize! params
|
59
59
|
get_request("/user/watched/#{user_name}/#{repo_name}", params)
|
60
60
|
true
|
61
61
|
rescue Github::Error::NotFound
|
@@ -72,7 +72,7 @@ module Github
|
|
72
72
|
#
|
73
73
|
def start_watching(user_name, repo_name, params={})
|
74
74
|
_validate_presence_of user_name, repo_name
|
75
|
-
|
75
|
+
normalize! params
|
76
76
|
put_request("/user/watched/#{user_name}/#{repo_name}", params)
|
77
77
|
end
|
78
78
|
|
@@ -85,7 +85,7 @@ module Github
|
|
85
85
|
#
|
86
86
|
def stop_watching(user_name, repo_name, params={})
|
87
87
|
_validate_presence_of user_name, repo_name
|
88
|
-
|
88
|
+
normalize! params
|
89
89
|
delete_request("/user/watched/#{user_name}/#{repo_name}", params)
|
90
90
|
end
|
91
91
|
|
data/lib/github_api/repos.rb
CHANGED
@@ -100,7 +100,7 @@ module Github
|
|
100
100
|
def branches(user_name, repo_name, params={})
|
101
101
|
_update_user_repo_params(user_name, repo_name)
|
102
102
|
_validate_user_repo_params(user, repo) unless (user? && repo?)
|
103
|
-
|
103
|
+
normalize! params
|
104
104
|
|
105
105
|
response = get_request("/repos/#{user}/#{repo}/branches", params)
|
106
106
|
return response unless block_given?
|
@@ -140,8 +140,8 @@ module Github
|
|
140
140
|
#
|
141
141
|
def create(*args)
|
142
142
|
params = args.extract_options!
|
143
|
-
|
144
|
-
|
143
|
+
normalize! params
|
144
|
+
filter! VALID_REPO_OPTIONS + %w[ org ], params
|
145
145
|
assert_required_keys(%w[ name ], params)
|
146
146
|
|
147
147
|
# Requires authenticated user
|
@@ -166,8 +166,8 @@ module Github
|
|
166
166
|
def contributors(user_name, repo_name, params={})
|
167
167
|
_update_user_repo_params(user_name, repo_name)
|
168
168
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
169
|
-
|
170
|
-
|
169
|
+
normalize! params
|
170
|
+
filter! ['anon'], params
|
171
171
|
|
172
172
|
response = get_request("/repos/#{user}/#{repo}/contributors", params)
|
173
173
|
return response unless block_given?
|
@@ -200,8 +200,8 @@ module Github
|
|
200
200
|
_update_user_repo_params(user_name, repo_name)
|
201
201
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
202
202
|
|
203
|
-
|
204
|
-
|
203
|
+
normalize! params
|
204
|
+
filter! VALID_REPO_OPTIONS, params
|
205
205
|
assert_required_keys(%w[ name ], params)
|
206
206
|
|
207
207
|
patch_request("/repos/#{user}/#{repo}", DEFAULT_REPO_OPTIONS.merge(params))
|
@@ -216,7 +216,7 @@ module Github
|
|
216
216
|
def get(user_name, repo_name, params={})
|
217
217
|
_update_user_repo_params(user_name, repo_name)
|
218
218
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
219
|
-
|
219
|
+
normalize! params
|
220
220
|
|
221
221
|
get_request("/repos/#{user}/#{repo}", params)
|
222
222
|
end
|
@@ -232,7 +232,7 @@ module Github
|
|
232
232
|
def languages(user_name, repo_name, params={})
|
233
233
|
_update_user_repo_params(user_name, repo_name)
|
234
234
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
235
|
-
|
235
|
+
normalize! params
|
236
236
|
|
237
237
|
response = get_request("/repos/#{user}/#{repo}/languages", params)
|
238
238
|
return response unless block_given?
|
@@ -263,9 +263,9 @@ module Github
|
|
263
263
|
#
|
264
264
|
def list(*args)
|
265
265
|
params = args.extract_options!
|
266
|
-
|
266
|
+
normalize! params
|
267
267
|
_merge_user_into_params!(params) unless params.has_key?('user')
|
268
|
-
|
268
|
+
filter! %w[ org user type ], params
|
269
269
|
|
270
270
|
response = if (user_name = params.delete("user"))
|
271
271
|
get_request("/users/#{user_name}/repos", params)
|
@@ -290,7 +290,7 @@ module Github
|
|
290
290
|
def tags(user_name, repo_name, params={})
|
291
291
|
_update_user_repo_params(user_name, repo_name)
|
292
292
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
293
|
-
|
293
|
+
normalize! params
|
294
294
|
|
295
295
|
response = get_request("/repos/#{user}/#{repo}/tags", params)
|
296
296
|
return response unless block_given?
|
@@ -310,7 +310,7 @@ module Github
|
|
310
310
|
def teams(user_name, repo_name, params={})
|
311
311
|
_update_user_repo_params(user_name, repo_name)
|
312
312
|
_validate_user_repo_params(user, repo) unless user? && repo?
|
313
|
-
|
313
|
+
normalize! params
|
314
314
|
|
315
315
|
response = get_request("/repos/#{user}/#{repo}/teams", params)
|
316
316
|
return response unless block_given?
|
data/lib/github_api/search.rb
CHANGED
@@ -22,7 +22,7 @@ module Github
|
|
22
22
|
#
|
23
23
|
def issues(*args)
|
24
24
|
params = args.extract_options!
|
25
|
-
normalize params
|
25
|
+
normalize! params
|
26
26
|
|
27
27
|
required = ['owner', 'repo', 'state', 'keyword']
|
28
28
|
assert_required_keys required, params
|
@@ -48,7 +48,7 @@ module Github
|
|
48
48
|
#
|
49
49
|
def repos(*args)
|
50
50
|
params = args.extract_options!
|
51
|
-
normalize params
|
51
|
+
normalize! params
|
52
52
|
assert_required_keys %w[ keyword ], params
|
53
53
|
|
54
54
|
get_request("/legacy/repos/search/#{params.delete('keyword')}", params)
|
@@ -68,7 +68,7 @@ module Github
|
|
68
68
|
#
|
69
69
|
def users(*args)
|
70
70
|
params = args.extract_options!
|
71
|
-
normalize params
|
71
|
+
normalize! params
|
72
72
|
assert_required_keys %w[ keyword ], params
|
73
73
|
|
74
74
|
get_request("/legacy/user/search/#{params.delete('keyword')}", params)
|
@@ -88,7 +88,7 @@ module Github
|
|
88
88
|
#
|
89
89
|
def email(*args)
|
90
90
|
params = args.extract_options!
|
91
|
-
normalize params
|
91
|
+
normalize! params
|
92
92
|
assert_required_keys %w[ email ], params
|
93
93
|
|
94
94
|
get_request("/legacy/user/email/#{params.delete('email')}", params)
|
@@ -12,7 +12,7 @@ module Github
|
|
12
12
|
# github.users.emails.list { |email| ... }
|
13
13
|
#
|
14
14
|
def list(params={})
|
15
|
-
|
15
|
+
normalize! params
|
16
16
|
response = get_request("/user/emails", params)
|
17
17
|
return response unless block_given?
|
18
18
|
response.each { |el| yield el }
|
@@ -30,7 +30,7 @@ module Github
|
|
30
30
|
#
|
31
31
|
def add(*args)
|
32
32
|
params = args.extract_options!
|
33
|
-
|
33
|
+
normalize! params
|
34
34
|
params['data'] = args if args
|
35
35
|
post_request("/user/emails", params)
|
36
36
|
end
|
@@ -47,7 +47,7 @@ module Github
|
|
47
47
|
#
|
48
48
|
def delete(*args)
|
49
49
|
params = args.extract_options!
|
50
|
-
|
50
|
+
normalize! params
|
51
51
|
params['data'] = args if args
|
52
52
|
delete_request("/user/emails", params)
|
53
53
|
end
|
@@ -18,7 +18,7 @@ module Github
|
|
18
18
|
# github.users.followers { |user| ... }
|
19
19
|
#
|
20
20
|
def list(user_name=nil, params={})
|
21
|
-
|
21
|
+
normalize! params
|
22
22
|
response = if user_name
|
23
23
|
get_request("/users/#{user_name}/followers", params)
|
24
24
|
else
|
@@ -44,7 +44,7 @@ module Github
|
|
44
44
|
# github.users.followers.following
|
45
45
|
#
|
46
46
|
def following(user_name=nil, params={})
|
47
|
-
|
47
|
+
normalize! params
|
48
48
|
response = if user_name
|
49
49
|
get_request("/users/#{user_name}/following", params)
|
50
50
|
else
|
@@ -62,7 +62,7 @@ module Github
|
|
62
62
|
#
|
63
63
|
def following?(user_name, params={})
|
64
64
|
_validate_presence_of user_name
|
65
|
-
|
65
|
+
normalize! params
|
66
66
|
get_request("/user/following/#{user_name}", params)
|
67
67
|
true
|
68
68
|
rescue Github::Error::NotFound
|
@@ -77,7 +77,7 @@ module Github
|
|
77
77
|
#
|
78
78
|
def follow(user_name, params={})
|
79
79
|
_validate_presence_of user_name
|
80
|
-
|
80
|
+
normalize! params
|
81
81
|
put_request("/user/following/#{user_name}", params)
|
82
82
|
end
|
83
83
|
|
@@ -89,7 +89,7 @@ module Github
|
|
89
89
|
#
|
90
90
|
def unfollow(user_name, params={})
|
91
91
|
_validate_presence_of user_name
|
92
|
-
|
92
|
+
normalize! params
|
93
93
|
delete_request("/user/following/#{user_name}", params)
|
94
94
|
end
|
95
95
|
|
@@ -13,7 +13,7 @@ module Github
|
|
13
13
|
# github.users.followers.list { |key| ... }
|
14
14
|
#
|
15
15
|
def list(params={})
|
16
|
-
|
16
|
+
normalize! params
|
17
17
|
response = get_request("/user/keys", params)
|
18
18
|
return response unless block_given?
|
19
19
|
response.each { |el| yield el }
|
@@ -28,7 +28,7 @@ module Github
|
|
28
28
|
#
|
29
29
|
def get(key_id, params={})
|
30
30
|
_validate_presence_of key_id
|
31
|
-
|
31
|
+
normalize! params
|
32
32
|
get_request("/user/keys/#{key_id}", params)
|
33
33
|
end
|
34
34
|
alias :find :get
|
@@ -45,8 +45,8 @@ module Github
|
|
45
45
|
# "key" => "ssh-rsa AAA..."
|
46
46
|
#
|
47
47
|
def create(params={})
|
48
|
-
|
49
|
-
|
48
|
+
normalize! params
|
49
|
+
filter! VALID_KEY_PARAM_NAMES, params
|
50
50
|
post_request("/user/keys", params)
|
51
51
|
end
|
52
52
|
|
@@ -63,8 +63,8 @@ module Github
|
|
63
63
|
#
|
64
64
|
def update(key_id, params={})
|
65
65
|
_validate_presence_of key_id
|
66
|
-
|
67
|
-
|
66
|
+
normalize! params
|
67
|
+
filter! VALID_KEY_PARAM_NAMES, params
|
68
68
|
patch_request("/user/keys/#{key_id}", params)
|
69
69
|
end
|
70
70
|
|
@@ -76,7 +76,7 @@ module Github
|
|
76
76
|
#
|
77
77
|
def delete(key_id, params={})
|
78
78
|
_validate_presence_of key_id
|
79
|
-
|
79
|
+
normalize! params
|
80
80
|
delete_request("/user/keys/#{key_id}", params)
|
81
81
|
end
|
82
82
|
|
data/lib/github_api/users.rb
CHANGED
@@ -54,7 +54,7 @@ module Github
|
|
54
54
|
#
|
55
55
|
def get(*args)
|
56
56
|
params = args.extract_options!
|
57
|
-
|
57
|
+
normalize! params
|
58
58
|
if user_name = params.delete('user')
|
59
59
|
get_request("/users/#{user_name}", params)
|
60
60
|
else
|
@@ -87,8 +87,8 @@ module Github
|
|
87
87
|
#
|
88
88
|
def update(*args)
|
89
89
|
params = args.extract_options!
|
90
|
-
|
91
|
-
|
90
|
+
normalize! params
|
91
|
+
filter! VALID_USER_PARAMS_NAMES, params
|
92
92
|
patch_request("/user", params)
|
93
93
|
end
|
94
94
|
|
data/lib/github_api/version.rb
CHANGED
data/lib/github_api.rb
CHANGED
@@ -59,30 +59,31 @@ module Github
|
|
59
59
|
extend AutoloadHelper
|
60
60
|
|
61
61
|
autoload_all 'github_api',
|
62
|
-
:API
|
63
|
-
:ApiFactory
|
64
|
-
:Client
|
65
|
-
:Repos
|
66
|
-
:Request
|
67
|
-
:Response
|
68
|
-
:Result
|
69
|
-
:Error
|
70
|
-
:Issues
|
71
|
-
:Gists
|
72
|
-
:GitData
|
73
|
-
:Orgs
|
74
|
-
:PullRequests
|
75
|
-
:Users
|
76
|
-
:Events
|
77
|
-
:Search
|
78
|
-
:CoreExt
|
79
|
-
:MimeType
|
80
|
-
:Authorization
|
81
|
-
:Authorizations
|
82
|
-
:PageLinks
|
83
|
-
:PageIterator
|
84
|
-
:PagedRequest
|
85
|
-
:Validations
|
86
|
-
:
|
62
|
+
:API => 'api',
|
63
|
+
:ApiFactory => 'api_factory',
|
64
|
+
:Client => 'client',
|
65
|
+
:Repos => 'repos',
|
66
|
+
:Request => 'request',
|
67
|
+
:Response => 'response',
|
68
|
+
:Result => 'result',
|
69
|
+
:Error => 'error',
|
70
|
+
:Issues => 'issues',
|
71
|
+
:Gists => 'gists',
|
72
|
+
:GitData => 'git_data',
|
73
|
+
:Orgs => 'orgs',
|
74
|
+
:PullRequests => 'pull_requests',
|
75
|
+
:Users => 'users',
|
76
|
+
:Events => 'events',
|
77
|
+
:Search => 'search',
|
78
|
+
:CoreExt => 'core_ext',
|
79
|
+
:MimeType => 'mime_type',
|
80
|
+
:Authorization => 'authorization',
|
81
|
+
:Authorizations => 'authorizations',
|
82
|
+
:PageLinks => 'page_links',
|
83
|
+
:PageIterator => 'page_iterator',
|
84
|
+
:PagedRequest => 'paged_request',
|
85
|
+
:Validations => 'validations',
|
86
|
+
:ParameterFilter => 'parameter_filter',
|
87
|
+
:Normalizer => 'normalizer'
|
87
88
|
|
88
89
|
end # Github
|
data/spec/github/api_spec.rb
CHANGED
@@ -46,23 +46,23 @@ describe Github::API do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context '
|
49
|
+
context 'normalize!' do
|
50
50
|
before do
|
51
51
|
@params = { 'a' => { :b => { 'c' => 1 }, 'd' => [ 'a', { :e => 2 }] } }
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should stringify all the keys inside nested hash" do
|
55
|
-
actual = api.
|
55
|
+
actual = api.normalize! @params
|
56
56
|
expected = { 'a' => { 'b'=> { 'c' => 1 }, 'd' => [ 'a', { 'e'=> 2 }] } }
|
57
57
|
actual.should be_eql expected
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context '
|
61
|
+
context 'filter!' do
|
62
62
|
it "should remove non valid param keys" do
|
63
63
|
valid = ['a', 'b', 'e']
|
64
64
|
hash = {'a' => 1, 'b' => 3, 'c' => 2, 'd'=> 4, 'e' => 5 }
|
65
|
-
actual = api.
|
65
|
+
actual = api.filter! valid, hash
|
66
66
|
expected = {'a' => 1, 'b' => 3, 'e' => 5 }
|
67
67
|
actual.should be_eql expected
|
68
68
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'github_api/core_ext/hash'
|
3
|
+
|
4
|
+
describe Github::Normalizer do
|
5
|
+
let(:github) { Github.new }
|
6
|
+
let(:repos_instance) { Github::Repos.new }
|
7
|
+
let(:hash) { { :a => { :b => { :c => 1 } } } }
|
8
|
+
|
9
|
+
context '#normalize!' do
|
10
|
+
it 'converts hash keys to string' do
|
11
|
+
['a', 'b', 'c'].each do |key|
|
12
|
+
github.repos.normalize!(hash).all_keys.should include key
|
13
|
+
end
|
14
|
+
[:a, :b, :c].each do |key|
|
15
|
+
github.repos.normalize!(hash).all_keys.should_not include key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end # Github::Normalizer
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'github_api/core_ext/hash'
|
3
|
+
|
4
|
+
describe Github::ParameterFilter do
|
5
|
+
let(:github) { Github.new }
|
6
|
+
let(:repos_instance) { Github::Repos.new }
|
7
|
+
let(:block) {
|
8
|
+
Proc.new do |repo|
|
9
|
+
repo = repos_instance
|
10
|
+
end
|
11
|
+
}
|
12
|
+
let(:hash) { { :a => { :b => { :c => 1 } } } }
|
13
|
+
|
14
|
+
context '#filter!' do
|
15
|
+
it 'removes unwanted keys from hash' do
|
16
|
+
github.repos.filter!([:a], hash)
|
17
|
+
hash.all_keys.should include :a
|
18
|
+
hash.all_keys.should_not include :b
|
19
|
+
hash.all_keys.should_not include :c
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'recursively filters inputs tree' do
|
23
|
+
github.repos.filter!([:a, :b], hash)
|
24
|
+
hash.all_keys.should_not include :c
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'filters inputs tree only on top level' do
|
28
|
+
github.repos.filter!([:a, :b], hash, :recursive => false)
|
29
|
+
hash.all_keys.should include :c
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# context '#process_params' do
|
34
|
+
#
|
35
|
+
# it 'correctly yields current api instance' do
|
36
|
+
# github.repos.should_receive(:process_params).and_yield repos_instance
|
37
|
+
# github.repos.process_params(&block).should eq repos_instance
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
41
|
+
# context '#normalize' do
|
42
|
+
# it 'should call normalize on passed block' do
|
43
|
+
# github.repos.process_params(&block).should respond_to :normalize
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# it 'should normalize params inside block' do
|
47
|
+
# github.repos.stub(:process_params).and_yield repos_instance
|
48
|
+
# github.repos.process_params do |repo|
|
49
|
+
# repo.normalize hash
|
50
|
+
# end
|
51
|
+
# hash.all_keys.should include 'a'
|
52
|
+
# hash.all_keys.should_not include :a
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
|
56
|
+
# context '#filter' do
|
57
|
+
# it 'should call filter on passed block' do
|
58
|
+
# github.repos.process_params(&block).should respond_to :filter
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# it 'should filter params inside block' do
|
62
|
+
# github.repos.stub(:process_params).and_yield repos_instance
|
63
|
+
# github.repos.process_params do |repo|
|
64
|
+
# repo.filter [:a], hash
|
65
|
+
# end
|
66
|
+
# hash.all_keys.should include :a
|
67
|
+
# hash.all_keys.should_not include :b
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
|
71
|
+
end # Github::ParameterFilter
|