github_api 0.8.11 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/README.md +21 -14
  2. data/features/activity/notifications.feature +15 -0
  3. data/features/cassettes/activity/notifications/list_user.yml +54 -0
  4. data/features/step_definitions/common_steps.rb +8 -9
  5. data/lib/github_api.rb +3 -4
  6. data/lib/github_api/activity.rb +8 -13
  7. data/lib/github_api/activity/events.rb +0 -5
  8. data/lib/github_api/activity/notifications.rb +0 -5
  9. data/lib/github_api/api.rb +27 -22
  10. data/lib/github_api/api_factory.rb +13 -12
  11. data/lib/github_api/authorizations.rb +0 -5
  12. data/lib/github_api/client.rb +33 -33
  13. data/lib/github_api/configuration.rb +10 -2
  14. data/lib/github_api/connection.rb +2 -3
  15. data/lib/github_api/constants.rb +0 -3
  16. data/lib/github_api/gists.rb +2 -7
  17. data/lib/github_api/git_data.rb +10 -15
  18. data/lib/github_api/git_data/blobs.rb +0 -5
  19. data/lib/github_api/git_data/commits.rb +0 -5
  20. data/lib/github_api/git_data/references.rb +3 -7
  21. data/lib/github_api/git_data/tags.rb +0 -5
  22. data/lib/github_api/git_data/trees.rb +0 -5
  23. data/lib/github_api/gitignore.rb +0 -5
  24. data/lib/github_api/issues.rb +10 -15
  25. data/lib/github_api/issues/comments.rb +0 -5
  26. data/lib/github_api/issues/events.rb +0 -5
  27. data/lib/github_api/issues/labels.rb +0 -5
  28. data/lib/github_api/issues/milestones.rb +0 -5
  29. data/lib/github_api/markdown.rb +0 -5
  30. data/lib/github_api/meta.rb +0 -5
  31. data/lib/github_api/orgs.rb +4 -9
  32. data/lib/github_api/page_iterator.rb +44 -29
  33. data/lib/github_api/paged_request.rb +12 -12
  34. data/lib/github_api/{result.rb → pagination.rb} +19 -86
  35. data/lib/github_api/params_hash.rb +1 -1
  36. data/lib/github_api/pull_requests.rb +2 -7
  37. data/lib/github_api/repos.rb +22 -27
  38. data/lib/github_api/request.rb +7 -4
  39. data/lib/github_api/response/header.rb +76 -0
  40. data/lib/github_api/response_wrapper.rb +126 -0
  41. data/lib/github_api/scopes.rb +1 -1
  42. data/lib/github_api/search.rb +0 -5
  43. data/lib/github_api/users.rb +6 -11
  44. data/lib/github_api/version.rb +2 -2
  45. data/spec/github/activity/notifications/get_spec.rb +1 -1
  46. data/spec/github/activity/starring/starred_spec.rb +1 -1
  47. data/spec/github/activity/watching/watched_spec.rb +1 -1
  48. data/spec/github/api_factory_spec.rb +7 -8
  49. data/spec/github/api_spec.rb +0 -7
  50. data/spec/github/authorization_spec.rb +22 -32
  51. data/spec/github/authorizations/create_spec.rb +49 -0
  52. data/spec/github/authorizations/delete_spec.rb +39 -0
  53. data/spec/github/authorizations/get_spec.rb +49 -0
  54. data/spec/github/authorizations/list_spec.rb +55 -0
  55. data/spec/github/authorizations/update_spec.rb +50 -0
  56. data/spec/github/authorizations_spec.rb +2 -236
  57. data/spec/github/gists/comments/create_spec.rb +1 -1
  58. data/spec/github/gists/comments/edit_spec.rb +1 -1
  59. data/spec/github/gists/comments/get_spec.rb +1 -1
  60. data/spec/github/gists/create_spec.rb +1 -1
  61. data/spec/github/gists/edit_spec.rb +1 -1
  62. data/spec/github/gists/fork_spec.rb +1 -1
  63. data/spec/github/gists/get_spec.rb +1 -1
  64. data/spec/github/git_data/blobs/create_spec.rb +1 -1
  65. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  66. data/spec/github/git_data/commits/create_spec.rb +1 -1
  67. data/spec/github/git_data/commits/get_spec.rb +1 -1
  68. data/spec/github/git_data/references/create_spec.rb +2 -2
  69. data/spec/github/git_data/references/get_spec.rb +1 -1
  70. data/spec/github/git_data/references/list_spec.rb +16 -6
  71. data/spec/github/git_data/tags/create_spec.rb +1 -1
  72. data/spec/github/git_data/tags/get_spec.rb +1 -1
  73. data/spec/github/git_data/trees/create_spec.rb +1 -1
  74. data/spec/github/git_data/trees/get_spec.rb +4 -4
  75. data/spec/github/issues/comments/create_spec.rb +1 -1
  76. data/spec/github/issues/comments/edit_spec.rb +1 -1
  77. data/spec/github/issues/comments/get_spec.rb +1 -1
  78. data/spec/github/issues/create_spec.rb +1 -1
  79. data/spec/github/issues/edit_spec.rb +1 -1
  80. data/spec/github/issues/events/get_spec.rb +1 -1
  81. data/spec/github/issues/get_spec.rb +1 -1
  82. data/spec/github/issues/labels/create_spec.rb +1 -1
  83. data/spec/github/issues/labels/get_spec.rb +1 -1
  84. data/spec/github/issues/labels/update_spec.rb +1 -1
  85. data/spec/github/issues/milestones/create_spec.rb +1 -1
  86. data/spec/github/issues/milestones/delete_spec.rb +1 -1
  87. data/spec/github/issues/milestones/get_spec.rb +1 -1
  88. data/spec/github/issues/milestones/update_spec.rb +1 -1
  89. data/spec/github/orgs/edit_spec.rb +1 -1
  90. data/spec/github/orgs/get_spec.rb +1 -1
  91. data/spec/github/orgs/teams/create_spec.rb +1 -1
  92. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  93. data/spec/github/orgs/teams/get_spec.rb +1 -1
  94. data/spec/github/paged_request_spec.rb +34 -29
  95. data/spec/github/pagination/iterator/number_spec.rb +118 -0
  96. data/spec/github/pagination/iterator/sha_spec.rb +67 -0
  97. data/spec/github/pull_requests/comments/create_spec.rb +1 -1
  98. data/spec/github/pull_requests/comments/edit_spec.rb +1 -1
  99. data/spec/github/pull_requests/comments/get_spec.rb +1 -1
  100. data/spec/github/pull_requests/create_spec.rb +1 -1
  101. data/spec/github/pull_requests/get_spec.rb +1 -1
  102. data/spec/github/pull_requests/update_spec.rb +1 -1
  103. data/spec/github/repos/branch_spec.rb +1 -1
  104. data/spec/github/repos/comments/create_spec.rb +1 -1
  105. data/spec/github/repos/comments/get_spec.rb +1 -1
  106. data/spec/github/repos/comments/update_spec.rb +1 -1
  107. data/spec/github/repos/commits/get_spec.rb +1 -1
  108. data/spec/github/repos/create_spec.rb +1 -1
  109. data/spec/github/repos/downloads/create_spec.rb +1 -1
  110. data/spec/github/repos/downloads/get_spec.rb +1 -1
  111. data/spec/github/repos/edit_spec.rb +1 -1
  112. data/spec/github/repos/forks/create_spec.rb +1 -1
  113. data/spec/github/repos/get_spec.rb +1 -1
  114. data/spec/github/repos/hooks/create_spec.rb +1 -1
  115. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  116. data/spec/github/repos/hooks/get_spec.rb +1 -1
  117. data/spec/github/repos/languages_spec.rb +1 -1
  118. data/spec/github/repos/merging/merge_spec.rb +1 -1
  119. data/spec/github/repos/statuses/create_spec.rb +1 -1
  120. data/spec/github/repos/tags_spec.rb +1 -1
  121. data/spec/github/repos/teams_spec.rb +1 -1
  122. data/spec/github/request/endpoint_spec.rb +24 -0
  123. data/spec/github/request/request_spec.rb +38 -0
  124. data/spec/github/{result_spec.rb → response_wrapper_spec.rb} +14 -13
  125. data/spec/github/users/emails/list_spec.rb +1 -1
  126. data/spec/github/users/get_spec.rb +2 -7
  127. data/spec/github/users/keys/create_spec.rb +1 -1
  128. data/spec/github/users/keys/get_spec.rb +1 -1
  129. data/spec/github/users/keys/update_spec.rb +1 -1
  130. data/spec/github/users/update_spec.rb +1 -1
  131. data/spec/github_spec.rb +1 -6
  132. data/spec/{github/activity → integration}/activity_spec.rb +0 -0
  133. data/spec/{github/gists → integration}/gists_spec.rb +2 -0
  134. data/spec/{github/git_data → integration}/git_data_spec.rb +0 -0
  135. data/spec/{github/issues → integration}/issues_spec.rb +2 -0
  136. data/spec/integration/options_spec.rb +103 -23
  137. data/spec/{github/orgs → integration}/orgs_spec.rb +0 -0
  138. data/spec/{github/pull_requests → integration}/pull_requests_spec.rb +0 -0
  139. data/spec/{github → integration}/repos_spec.rb +2 -0
  140. data/spec/{github/users → integration}/users_spec.rb +0 -0
  141. data/spec/shared/array_of_resources_behaviour.rb +1 -1
  142. metadata +55 -46
  143. data/lib/github_api/page_uri_processor.rb +0 -25
  144. data/lib/github_api/response/helpers.rb +0 -21
  145. data/spec/github/page_iterator_spec.rb +0 -260
  146. data/spec/github/response/helpers_spec.rb +0 -16
@@ -1,25 +0,0 @@
1
- module Github
2
- class PageUriProcessor
3
- include Github::Constants
4
- include Github::Utils::Url
5
-
6
- attr_reader :link, :query_string
7
-
8
- def initialize(uri)
9
- @link = uri.split(QUERY_STR_SEP).first
10
- @query_string = uri.split(QUERY_STR_SEP).last
11
- end
12
-
13
- def resource_link
14
- link
15
- end
16
-
17
- def query_hash
18
- parsed_query = parse_query(query_string)
19
- params = {}
20
- if parsed_query.include? :last_sha
21
- params[:sha] = parsed_query[:last_sha]
22
-
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'faraday'
4
-
5
- module Github
6
- class Response::Helpers < Response
7
-
8
- def on_complete(env)
9
- env[:body].class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
10
- include Github::Result
11
-
12
- def env
13
- @env
14
- end
15
-
16
- RUBY_EVAL
17
- env[:body].instance_eval { @env = env }
18
- end
19
-
20
- end # Response::Helpers
21
- end # Github
@@ -1,260 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Github::PageIterator do
6
- let(:link) {
7
- "<https://api.github.com/users/wycats/repos?page=4&per_page=20>; rel=\"next\", <https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\", <https://api.github.com/users/wycats/repos?page=2&per_page=20>; rel=\"prev\""
8
- }
9
- let(:sha_link) {
10
- "<https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"next\", <https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"first\""
11
- }
12
- let(:env) { { :response_headers => {'Link' => link } } }
13
- let(:sha_env) { { :response_headers => {'Link' => sha_link } } }
14
- let(:first) { "https://api.github.com/users/wycats/repos?page=1&per_page=20" }
15
- let(:nexxt) { "https://api.github.com/users/wycats/repos?page=4&per_page=20" }
16
- let(:prev) { "https://api.github.com/users/wycats/repos?page=2&per_page=20" }
17
- let(:last) { "https://api.github.com/users/wycats/repos?page=6&per_page=20" }
18
- let(:user) { 'wycats' }
19
- let(:last_sha) { "d1e503c02fa770859895dd0d12aedefa28b95723"}
20
-
21
- let(:instance) { Github::PageIterator.new(env) }
22
- let(:sha_instance) { Github::PageIterator.new(sha_env) }
23
- let(:sha_links) { Github::PageLinks.new(sha_env)}
24
- let(:sha_first) { "https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
25
- let(:sha_next) { "https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd"}
26
- let(:top_sha) { '801d80dfd59bf1d2cb30a243799953ab683a3abd' }
27
- let(:sha) { '801d80dfd59bf1d2cb30a243799953ab683a3abd' }
28
-
29
- it { described_class::ATTRIBUTES.should_not be_nil }
30
-
31
- context 'initialization' do
32
-
33
- it { instance.first_page.should eq 1 }
34
- it { instance.first_page_uri.should eq first }
35
- it { instance.next_page.should eq 4 }
36
- it { instance.next_page_uri.should eq nexxt }
37
- it { instance.prev_page.should eq 2 }
38
- it { instance.prev_page_uri.should eq prev }
39
- it { instance.last_page.should eql 6 }
40
- it { instance.last_page_uri.should eq last }
41
-
42
- it { sha_instance.first_page.should eq -1 }
43
- it { sha_instance.first_page_uri.should eq sha_first }
44
- it { sha_instance.next_page.should eq -1 }
45
- it { sha_instance.next_page_uri.should eq sha_next }
46
- it { sha_instance.prev_page.should eq -1 }
47
- it { sha_instance.prev_page_uri.should be_nil }
48
- it { sha_instance.last_page.should eql -1 }
49
- it { sha_instance.last_page_uri.should be_nil }
50
-
51
- end
52
-
53
- context 'has_next?' do
54
- it "return true when next_page_uri is present" do
55
- instance.has_next?.should be_true
56
- end
57
-
58
- it "returns false when next_page_uri is nil" do
59
- instance.should_receive(:next_page_uri).and_return nil
60
- instance.has_next?.should be_false
61
- end
62
- end
63
-
64
- context 'first' do
65
- before do
66
- Github.new
67
- instance.stub(:has_next?).and_return true
68
- stub_get("/users/#{user}/repos").
69
- with(:query => { 'per_page' => '20'}).
70
- to_return(:body => '', :status => 200,
71
- :headers => {
72
- :content_type => "application/json; charset=utf-8",
73
- 'Link' => link
74
- }
75
- )
76
- end
77
-
78
- it 'returns nil if there are no more pages' do
79
- instance.stub(:first_page_uri).and_return false
80
- instance.first.should be_nil
81
- end
82
-
83
- it 'performs request' do
84
- link.stub(:links).and_return link
85
- instance.stub(:update_page_links)
86
- instance.should_receive(:page_request).
87
- with("https://api.github.com/users/#{user}/repos", 'per_page' => 20).
88
- and_return link
89
- instance.first
90
- end
91
-
92
- context 'no pagination params' do
93
- before do
94
- Github.new
95
- sha_instance.stub(:has_next?).and_return true
96
- sha_instance.stub(:next_page).and_return -1
97
-
98
- stub_get("/repos/peter-murach/github/commits").
99
- to_return(:body => '', :status => 200,
100
- :headers => {
101
- :content_type => "application/json; charset=utf-8",
102
- 'Link' => sha_link
103
- }
104
- )
105
- end
106
-
107
- it 'receives sha params' do
108
- sha_link.stub(:links).and_return sha_links
109
- sha_instance.stub(:udpate_page_links)
110
- sha_instance.should_receive(:page_request).
111
- with("https://api.github.com/repos/peter-murach/github/commits",
112
- 'sha' => 'master', 'per_page' => 30).and_return sha_link
113
- sha_instance.first
114
- end
115
- end
116
- end # first
117
-
118
- context 'next' do
119
- before do
120
- Github.new
121
- instance.stub(:has_next?).and_return true
122
- stub_get("/users/#{user}/repos").
123
- with(:query => { 'page' => '4', 'per_page' => '20'}).
124
- to_return(:body => '', :status => 200,
125
- :headers => {
126
- :content_type => "application/json; charset=utf-8",
127
- 'Link' => link
128
- }
129
- )
130
- end
131
-
132
- it 'returns nil if there are no more pages' do
133
- instance.stub(:has_next?).and_return false
134
- instance.next.should be_nil
135
- end
136
-
137
- it 'performs request' do
138
- link.stub(:links).and_return link
139
- instance.stub(:update_page_links)
140
- instance.should_receive(:page_request).
141
- with("https://api.github.com/users/#{user}/repos",
142
- 'page' => 4,'per_page' => 20).and_return link
143
- instance.next
144
- end
145
-
146
- context 'no pagination params' do
147
- before do
148
- Github.new
149
- sha_instance.stub(:has_next?).and_return true
150
- sha_instance.stub(:next_page).and_return -1
151
-
152
- stub_get("/repos/peter-murach/github/commits").
153
- to_return(:body => '', :status => 200,
154
- :headers => {
155
- :content_type => "application/json; charset=utf-8",
156
- 'Link' => sha_link
157
- }
158
- )
159
- end
160
-
161
- it 'receives sha params' do
162
- sha_link.stub(:links).and_return sha_links
163
- sha_instance.stub(:udpate_page_links)
164
- sha_instance.should_receive(:page_request).
165
- with("https://api.github.com/repos/peter-murach/github/commits",
166
- 'last_sha' => last_sha, 'sha' => last_sha, 'per_page' => 30, 'top' => top_sha).and_return sha_link
167
- sha_instance.next
168
- end
169
- end
170
- end # next
171
-
172
- context 'prev' do
173
- before do
174
- Github.new
175
- instance.stub(:has_next?).and_return true
176
- stub_get("/users/#{user}/repos").
177
- with(:query => { 'page' => '2', 'per_page' => '20'}).
178
- to_return(:body => '', :status => 200,
179
- :headers => {
180
- :content_type => "application/json; charset=utf-8",
181
- 'Link' => link
182
- }
183
- )
184
- end
185
-
186
- it 'returns nil if there are no previous pages' do
187
- instance.stub(:prev_page_uri).and_return false
188
- instance.prev.should be_nil
189
- end
190
-
191
- it 'performs request' do
192
- link.stub(:links).and_return link
193
- instance.stub(:update_page_links)
194
- instance.should_receive(:page_request).
195
- with("https://api.github.com/users/#{user}/repos",
196
- 'page' => 2,'per_page' => 20).and_return link
197
- instance.prev
198
- end
199
- end # prev
200
-
201
- context 'last' do
202
- before do
203
- Github.new
204
- instance.stub(:has_next?).and_return true
205
- stub_get("/users/#{user}/repos").
206
- with(:query => { 'page' => '6', 'per_page' => '20'}).
207
- to_return(:body => '', :status => 200,
208
- :headers => {
209
- :content_type => "application/json; charset=utf-8",
210
- 'Link' => link
211
- }
212
- )
213
- end
214
-
215
- it 'returns nil if there is not last page' do
216
- instance.stub(:last_page_uri).and_return false
217
- instance.last.should be_nil
218
- end
219
-
220
- it 'performs request' do
221
- link.stub(:links).and_return link
222
- instance.stub(:update_page_links)
223
- instance.should_receive(:page_request).
224
- with("https://api.github.com/users/#{user}/repos",
225
- 'page' => 6,'per_page' => 20).and_return link
226
- instance.last
227
- end
228
- end # last
229
-
230
- context 'get_page' do
231
- before do
232
- Github.new
233
- instance.stub(:has_next?).and_return true
234
- stub_get("/users/#{user}/repos").
235
- with(:query => { 'page' => '6', 'per_page' => '20'}).
236
- to_return(:body => '', :status => 200,
237
- :headers => {
238
- :content_type => "application/json; charset=utf-8",
239
- 'Link' => link
240
- }
241
- )
242
- end
243
-
244
- it 'returns nil if there are no pages' do
245
- instance.stub(:first_page_uri).and_return nil
246
- instance.stub(:last_page_uri).and_return nil
247
- instance.get_page(5).should be_nil
248
- end
249
-
250
- it 'finds a single page' do
251
- instance.should_receive(:update_page_links)
252
- instance.should_receive(:page_request).
253
- with("https://api.github.com/users/#{user}/repos",
254
- 'page' => 2, 'per_page' => 20).and_return link
255
- link.stub(:links).and_return link
256
- instance.get_page(2)
257
- end
258
- end # get_page
259
-
260
- end # Github::PageIterator
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::Response::Helpers do
4
- let(:env) { { :body => [1,2,3] } }
5
- let(:instance) { described_class.new }
6
-
7
- it 'includes result helper methods' do
8
- res = instance.on_complete(env)
9
- res[:body].class.included_modules.should include Github::Result
10
- end
11
-
12
- it 'should extend result with environemnt getter' do
13
- res = instance.on_complete(env)
14
- res[:body].should respond_to :env
15
- end
16
- end # Github::Response::Helpers