github_api 0.4.3 → 0.4.4
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 +10 -4
- data/features/cassettes/gists/comments/all.yml +121 -0
- data/features/cassettes/gists/comments/first.yml +46 -0
- data/features/gists/comments.feature +25 -0
- data/features/step_definitions/common_steps.rb +4 -0
- data/lib/github_api.rb +4 -1
- data/lib/github_api/api.rb +4 -82
- data/lib/github_api/api/actions.rb +14 -2
- data/lib/github_api/api_factory.rb +24 -0
- data/lib/github_api/client.rb +9 -9
- data/lib/github_api/filter.rb +56 -0
- data/lib/github_api/gists.rb +6 -2
- data/lib/github_api/gists/comments.rb +37 -16
- data/lib/github_api/ratelimit_status.rb +17 -0
- data/lib/github_api/repos/hooks.rb +8 -4
- data/lib/github_api/result.rb +4 -0
- data/lib/github_api/validation.rb +49 -0
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/gists/comment.json +13 -0
- data/spec/fixtures/gists/comments.json +15 -0
- data/spec/github/api_factory_spec.rb +14 -0
- data/spec/github/filter_spec.rb +82 -0
- data/spec/github/gists/comments_spec.rb +253 -1
- data/spec/github/repos/hooks_spec.rb +22 -6
- data/spec/github/result_spec.rb +6 -0
- data/spec/github/validation_spec.rb +61 -0
- metadata +14 -2
data/README.md
CHANGED
@@ -141,13 +141,19 @@ or organisation name, allow you to switch the way the data is returned to you, f
|
|
141
141
|
|
142
142
|
```ruby
|
143
143
|
@github = Github.new
|
144
|
-
@github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea'
|
144
|
+
@github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea'
|
145
|
+
# => gets a tree
|
145
146
|
|
146
|
-
@github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea', :recursive => true
|
147
|
+
@github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea', :recursive => true
|
148
|
+
# => gets a whole tree recursively
|
149
|
+
```
|
147
150
|
|
148
151
|
by passing a block you can iterate over the file tree
|
149
152
|
|
150
|
-
|
153
|
+
```ruby
|
154
|
+
@github.git_data.tree 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031e5d833b7f12ea',
|
155
|
+
:recursive => true do |file|
|
156
|
+
|
151
157
|
puts file.path
|
152
158
|
end
|
153
159
|
```
|
@@ -210,7 +216,7 @@ end
|
|
210
216
|
or
|
211
217
|
|
212
218
|
Github.new(:oauth_token => YOUR_OAUTH_TOKEN)
|
213
|
-
Github.new(:basic_auth => 'login:password)
|
219
|
+
Github.new(:basic_auth => 'login:password')
|
214
220
|
```
|
215
221
|
|
216
222
|
All parameters can be overwirtten as per method call. By passing parameters hash...
|
@@ -0,0 +1,121 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://api.github.com:443/gists/999390/comments
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept-encoding:
|
9
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
server:
|
16
|
+
- nginx/1.0.4
|
17
|
+
date:
|
18
|
+
- Sun, 05 Feb 2012 12:59:01 GMT
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
transfer-encoding:
|
22
|
+
- chunked
|
23
|
+
connection:
|
24
|
+
- keep-alive
|
25
|
+
status:
|
26
|
+
- 200 OK
|
27
|
+
x-ratelimit-limit:
|
28
|
+
- "5000"
|
29
|
+
etag:
|
30
|
+
- "\"505353f9d67f512676a7f199e6cd34db\""
|
31
|
+
x-ratelimit-remaining:
|
32
|
+
- "4997"
|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
113
|
+
9jK02Sfd9B6zT3rlwYuloIoyEHQty0Pg3oZW0ol0/OAROz+FDMuRGiRbAzDS
|
114
|
+
4V2dJokljtjCRrVecasU4SdwvnJEEb5XgGxKRTsDrefbtj+ZHsiwD36i8xPu
|
115
|
+
2Lu9zmIw1M3v4Rhyxu5Wyj0DemAQe/8vgCLrAGbRaoyUOywDcctNr2rOz8Lv
|
116
|
+
EtFRfgemGjaA44wsbAVcrs6RaVqmBiTqt6fkzZuWTlse3RWqx45vzf3JoYbg
|
117
|
+
RSqRb7vhSsPZ1HbDSRAF3J1b3hQmVcysaIyDrd405P2aRdfCoeF6Xx/3G669
|
118
|
+
yXjmdTyEpb5brW2n9ggMuf14beaq1f/DTv/fzRDTC2uCVUU16kCGeAgy28V1
|
119
|
+
7wwy/en9+ut/AVz6QpKlNAAA
|
120
|
+
|
121
|
+
http_version: "1.1"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://api.github.com:443/gists/comments/33469
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept-encoding:
|
9
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
server:
|
16
|
+
- nginx/1.0.4
|
17
|
+
date:
|
18
|
+
- Sun, 05 Feb 2012 12:59:01 GMT
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
transfer-encoding:
|
22
|
+
- chunked
|
23
|
+
connection:
|
24
|
+
- keep-alive
|
25
|
+
status:
|
26
|
+
- 200 OK
|
27
|
+
x-ratelimit-limit:
|
28
|
+
- "5000"
|
29
|
+
etag:
|
30
|
+
- "\"612aa3594782fab47ab767da9f377a8c\""
|
31
|
+
x-ratelimit-remaining:
|
32
|
+
- "4996"
|
33
|
+
content-encoding:
|
34
|
+
- gzip
|
35
|
+
body: !binary |
|
36
|
+
H4sIAAAAAAAAA4VSy27cMAz8FcJAb+vX2smuDRQ5FAjSe5BDLwElUbZgWRIk
|
37
|
+
ua0T5N8jO91ie2luA4kznCH5mi1eZ302xuhCX5boVDGoOC6s4HYuBxViKBOa
|
38
|
+
ySTQNO1tlx0yZsWaSE/kV+DW6gNoa6cAWk0EcSTwNNBvCoBGgMM47v+LSw+e
|
39
|
+
YFJaKzOAIy+tn9FwKuDbSHwCu0S4WLmy4Tg6X4rV2JxpFV/IQ2ICI8PHGf20
|
40
|
+
qSEIJSX5ZBQwOOIRrLzusZsJHDUylURWyGG0vyD1X2GTDiAsfAdDJMAaeCA/
|
41
|
+
2eUOUtzFCYwknjGm0MeqrvPqJm/qx/q2P970TfNjqwnks/71/+PcikK5p0mU
|
42
|
+
weNPjOiflUi6TNatrLqT5GdG7flUdazFTiIxLpF3MhG0HZRJpReBP/R/NxiI
|
43
|
+
L56Ki/i+xo/C8rMWd+Lr3zs4tueCCpxwRlUYiiWGQDFcHceX472acaCQwKXb
|
44
|
+
Nc7rtiqcGZLxLeCpObf12wfe7+iQcU+fzPXtHbPbLeKgAgAA
|
45
|
+
|
46
|
+
http_version: "1.1"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature: Accessing Gists Comments API
|
2
|
+
In order to interact with github gist comments
|
3
|
+
GithubAPI gem
|
4
|
+
Should return the expected results depending on passed parameters
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I have "Github::Gists" instance
|
8
|
+
|
9
|
+
Scenario: Lists comments on a gist
|
10
|
+
When I am looking for "comments" with the following params:
|
11
|
+
| gist_id |
|
12
|
+
| 999390 |
|
13
|
+
And I make request within a cassette named "gists/comments/all"
|
14
|
+
Then the response should be "200"
|
15
|
+
And the response type should be "JSON"
|
16
|
+
And the response should have 18 items
|
17
|
+
|
18
|
+
Scenario: Gets a single gist's comment
|
19
|
+
When I am looking for "comment" with the following params:
|
20
|
+
| comment_id |
|
21
|
+
| 33469 |
|
22
|
+
And I make request within a cassette named "gists/comments/first"
|
23
|
+
Then the response should be "200"
|
24
|
+
And the response type should be "JSON"
|
25
|
+
And the response should not be empty
|
data/lib/github_api.rb
CHANGED
@@ -59,6 +59,7 @@ module Github
|
|
59
59
|
|
60
60
|
autoload_all 'github_api',
|
61
61
|
:API => 'api',
|
62
|
+
:ApiFactory => 'api_factory',
|
62
63
|
:Client => 'client',
|
63
64
|
:Repos => 'repos',
|
64
65
|
:Request => 'request',
|
@@ -78,6 +79,8 @@ module Github
|
|
78
79
|
:Authorizations => 'authorizations',
|
79
80
|
:PageLinks => 'page_links',
|
80
81
|
:PageIterator => 'page_iterator',
|
81
|
-
:PagedRequest => 'paged_request'
|
82
|
+
:PagedRequest => 'paged_request',
|
83
|
+
:Validation => 'validation',
|
84
|
+
:Filter => 'filter'
|
82
85
|
|
83
86
|
end # Github
|
data/lib/github_api/api.rb
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'github_api/configuration'
|
4
4
|
require 'github_api/connection'
|
5
|
+
require 'github_api/validation'
|
5
6
|
require 'github_api/request'
|
6
7
|
require 'github_api/mime_type'
|
7
8
|
require 'github_api/core_ext/hash'
|
8
9
|
require 'github_api/core_ext/array'
|
9
10
|
require 'github_api/compatibility'
|
10
11
|
require 'github_api/api/actions'
|
12
|
+
require 'github_api/api_factory'
|
11
13
|
|
12
14
|
module Github
|
13
15
|
|
@@ -17,12 +19,8 @@ module Github
|
|
17
19
|
include MimeType
|
18
20
|
include Connection
|
19
21
|
include Request
|
20
|
-
|
21
|
-
|
22
|
-
'page',
|
23
|
-
'per_page',
|
24
|
-
'jsonp_callback'
|
25
|
-
]
|
22
|
+
include Validation
|
23
|
+
include Filter
|
26
24
|
|
27
25
|
attr_reader *Configuration::VALID_OPTIONS_KEYS
|
28
26
|
attr_accessor *VALID_API_KEYS
|
@@ -69,14 +67,6 @@ module Github
|
|
69
67
|
Github.api_client = self
|
70
68
|
end
|
71
69
|
|
72
|
-
# Passes configuration options to instantiated class
|
73
|
-
def _create_instance(klass, options)
|
74
|
-
options.symbolize_keys!
|
75
|
-
instance = klass.send :new, options
|
76
|
-
Github.api_client = instance
|
77
|
-
instance
|
78
|
-
end
|
79
|
-
|
80
70
|
# Responds to attribute query or attribute clear
|
81
71
|
def method_missing(method, *args, &block) # :nodoc:
|
82
72
|
case method.to_s
|
@@ -89,23 +79,6 @@ module Github
|
|
89
79
|
end
|
90
80
|
end
|
91
81
|
|
92
|
-
def _validate_inputs(required, provided) # :nodoc:
|
93
|
-
required.all? do |key|
|
94
|
-
provided.has_deep_key? key
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def _validate_presence_of(*params) # :nodoc:
|
99
|
-
params.each do |param|
|
100
|
-
raise ArgumentError, "parameter cannot be nil" if param.nil?
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def _validate_user_repo_params(user_name, repo_name) # :nodoc:
|
105
|
-
raise ArgumentError, "[user] parameter cannot be nil" if user_name.nil?
|
106
|
-
raise ArgumentError, "[repo] parameter cannot be nil" if repo_name.nil?
|
107
|
-
end
|
108
|
-
|
109
82
|
def _update_user_repo_params(user_name, repo_name=nil) # :nodoc:
|
110
83
|
self.user = user_name || self.user
|
111
84
|
self.repo = repo_name || self.repo
|
@@ -119,45 +92,6 @@ module Github
|
|
119
92
|
{ 'user' => self.user, 'repo' => self.repo }.merge!(params)
|
120
93
|
end
|
121
94
|
|
122
|
-
# Turns any keys from nested hashes including nested arrays into strings
|
123
|
-
def _normalize_params_keys(params) # :nodoc:
|
124
|
-
case params
|
125
|
-
when Hash
|
126
|
-
params.keys.each do |k|
|
127
|
-
params[k.to_s] = params.delete(k)
|
128
|
-
_normalize_params_keys(params[k.to_s])
|
129
|
-
end
|
130
|
-
when Array
|
131
|
-
params.map! do |el|
|
132
|
-
_normalize_params_keys(el)
|
133
|
-
end
|
134
|
-
else
|
135
|
-
params.to_s
|
136
|
-
end
|
137
|
-
return params
|
138
|
-
end
|
139
|
-
|
140
|
-
# Removes any keys from nested hashes that don't match predefiend keys
|
141
|
-
def _filter_params_keys(keys, params) # :nodoc:
|
142
|
-
case params
|
143
|
-
when Hash
|
144
|
-
params.keys.each do |k, v|
|
145
|
-
unless (keys.include?(k) or VALID_API_KEYS.include?(k))
|
146
|
-
params.delete(k)
|
147
|
-
else
|
148
|
-
_filter_params_keys(keys, params[k])
|
149
|
-
end
|
150
|
-
end
|
151
|
-
when Array
|
152
|
-
params.map! do |el|
|
153
|
-
_filter_params_keys(keys, el)
|
154
|
-
end
|
155
|
-
else
|
156
|
-
params
|
157
|
-
end
|
158
|
-
return params
|
159
|
-
end
|
160
|
-
|
161
95
|
def _hash_traverse(hash, &block)
|
162
96
|
hash.each do |key, val|
|
163
97
|
block.call(key)
|
@@ -175,18 +109,6 @@ module Github
|
|
175
109
|
return hash
|
176
110
|
end
|
177
111
|
|
178
|
-
# Ensures that hash values contain predefined values
|
179
|
-
def _validate_params_values(options, params) # :nodoc:
|
180
|
-
params.each do |k, v|
|
181
|
-
next unless options.keys.include?(k)
|
182
|
-
if options[k].is_a?(Array) && !options[k].include?(params[k])
|
183
|
-
raise ArgumentError, "Wrong value for #{k}, allowed: #{options[k].join(', ')}"
|
184
|
-
elsif options[k].is_a?(Regexp) && !(options[k] =~ params[k])
|
185
|
-
raise ArgumentError, "String does not match the parameter value."
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
112
|
def _merge_mime_type(resource, params) # :nodoc:
|
191
113
|
# params['resource'] = resource
|
192
114
|
# params['mime_type'] = params['mime_type'] || :raw
|
@@ -18,8 +18,8 @@ module Github
|
|
18
18
|
|
19
19
|
def api_methods_in(klass)
|
20
20
|
puts "---"
|
21
|
-
(klass.send(:instance_methods, false) - ['actions']).sort.each do |
|
22
|
-
puts "|--> #{
|
21
|
+
(klass.send(:instance_methods, false) - ['actions']).sort.each do |method|
|
22
|
+
puts "|--> #{method}"
|
23
23
|
end
|
24
24
|
klass.included_modules.each do |mod|
|
25
25
|
if mod.to_s =~ /#{klass}/
|
@@ -34,5 +34,17 @@ module Github
|
|
34
34
|
nil
|
35
35
|
end
|
36
36
|
|
37
|
+
def append_arguments(method)
|
38
|
+
_method = self.method(method)
|
39
|
+
if _method.arity == 0
|
40
|
+
args = "()"
|
41
|
+
elsif _method.arity > 0
|
42
|
+
args = "(few)"
|
43
|
+
else
|
44
|
+
args = "(else)"
|
45
|
+
end
|
46
|
+
args
|
47
|
+
end
|
48
|
+
|
37
49
|
end # API
|
38
50
|
end # Github
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'github_api/core_ext/hash'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class ApiFactory
|
7
|
+
|
8
|
+
# Instantiates a new github api object
|
9
|
+
def self.new(klass, options={})
|
10
|
+
return _create_instance(klass, options) if klass
|
11
|
+
raise ArgumentError, 'must provied klass to be instantiated'
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Passes configuration options to instantiated class
|
17
|
+
def self._create_instance(klass, options)
|
18
|
+
options.symbolize_keys!
|
19
|
+
instance = Github.const_get(klass.to_sym).new options
|
20
|
+
Github.api_client = instance
|
21
|
+
instance
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end # Github
|
data/lib/github_api/client.rb
CHANGED
@@ -4,51 +4,51 @@ module Github
|
|
4
4
|
class Client < API
|
5
5
|
|
6
6
|
def gists(options = {})
|
7
|
-
@gists ||=
|
7
|
+
@gists ||= ApiFactory.new 'Gists', options
|
8
8
|
end
|
9
9
|
|
10
10
|
# The Git Database API gives you access to read and write raw Git objects
|
11
11
|
# to your Git database on GitHub and to list and update your references
|
12
12
|
# (branch heads and tags).
|
13
13
|
def git_data(options = {})
|
14
|
-
@git_data ||=
|
14
|
+
@git_data ||= ApiFactory.new 'GitData', options
|
15
15
|
end
|
16
16
|
alias :git :git_data
|
17
17
|
|
18
18
|
def issues(options = {})
|
19
|
-
@issues ||=
|
19
|
+
@issues ||= ApiFactory.new 'Issues', options
|
20
20
|
end
|
21
21
|
|
22
22
|
def orgs(options = {})
|
23
|
-
@orgs ||=
|
23
|
+
@orgs ||= ApiFactory.new 'Orgs', options
|
24
24
|
end
|
25
25
|
alias :organizations :orgs
|
26
26
|
|
27
27
|
def pull_requests(options = {})
|
28
|
-
@pull_requests ||=
|
28
|
+
@pull_requests ||= ApiFactory.new 'PullRequests', options
|
29
29
|
end
|
30
30
|
|
31
31
|
def repos(options = {})
|
32
|
-
@repos ||=
|
32
|
+
@repos ||= ApiFactory.new 'Repos', options
|
33
33
|
end
|
34
34
|
alias :repositories :repos
|
35
35
|
|
36
36
|
# Many of the resources on the users API provide a shortcut for getting
|
37
37
|
# information about the currently authenticated user.
|
38
38
|
def users(options = {})
|
39
|
-
@users ||=
|
39
|
+
@users ||= ApiFactory.new 'Users', options
|
40
40
|
end
|
41
41
|
|
42
42
|
# This is a read-only API to the GitHub events.
|
43
43
|
# These events power the various activity streams on the site.
|
44
44
|
def events(options = {})
|
45
|
-
@events ||=
|
45
|
+
@events ||= ApiFactory.new 'Events', options
|
46
46
|
end
|
47
47
|
|
48
48
|
# An API for users to manage their own tokens. You can only access your own
|
49
49
|
# tokens, and only through Basic Authentication.
|
50
50
|
def oauth(options = {})
|
51
|
-
@oauth ||=
|
51
|
+
@oauth ||= ApiFactory.new 'Authorizations', options
|
52
52
|
end
|
53
53
|
|
54
54
|
end # Client
|