tinybucket 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -5
  3. data/README.md +100 -24
  4. data/lib/tinybucket.rb +1 -0
  5. data/lib/tinybucket/api.rb +1 -0
  6. data/lib/tinybucket/api/build_status_api.rb +55 -0
  7. data/lib/tinybucket/api/helper.rb +1 -0
  8. data/lib/tinybucket/api/helper/build_status_helper.rb +35 -0
  9. data/lib/tinybucket/client.rb +28 -45
  10. data/lib/tinybucket/enumerator.rb +4 -3
  11. data/lib/tinybucket/model.rb +2 -1
  12. data/lib/tinybucket/model/base.rb +1 -17
  13. data/lib/tinybucket/model/build_status.rb +55 -0
  14. data/lib/tinybucket/model/commit.rb +32 -15
  15. data/lib/tinybucket/model/concerns.rb +1 -0
  16. data/lib/tinybucket/model/concerns/api_callable.rb +19 -0
  17. data/lib/tinybucket/model/profile.rb +9 -26
  18. data/lib/tinybucket/model/pull_request.rb +18 -28
  19. data/lib/tinybucket/model/repository.rb +29 -76
  20. data/lib/tinybucket/model/team.rb +9 -34
  21. data/lib/tinybucket/parser.rb +1 -0
  22. data/lib/tinybucket/parser/build_status_parser.rb +9 -0
  23. data/lib/tinybucket/resource.rb +70 -0
  24. data/lib/tinybucket/resource/base.rb +29 -0
  25. data/lib/tinybucket/resource/branch_restrictions.rb +45 -0
  26. data/lib/tinybucket/resource/commit/base.rb +12 -0
  27. data/lib/tinybucket/resource/commit/build_statuses.rb +47 -0
  28. data/lib/tinybucket/resource/commit/comments.rb +32 -0
  29. data/lib/tinybucket/resource/commits.rb +33 -0
  30. data/lib/tinybucket/resource/forks.rb +22 -0
  31. data/lib/tinybucket/resource/pull_request/base.rb +18 -0
  32. data/lib/tinybucket/resource/pull_request/comments.rb +30 -0
  33. data/lib/tinybucket/resource/pull_request/commits.rb +17 -0
  34. data/lib/tinybucket/resource/pull_requests.rb +48 -0
  35. data/lib/tinybucket/resource/repos.rb +38 -0
  36. data/lib/tinybucket/resource/team/base.rb +22 -0
  37. data/lib/tinybucket/resource/team/followers.rb +13 -0
  38. data/lib/tinybucket/resource/team/following.rb +13 -0
  39. data/lib/tinybucket/resource/team/members.rb +13 -0
  40. data/lib/tinybucket/resource/team/repos.rb +13 -0
  41. data/lib/tinybucket/resource/user/base.rb +24 -0
  42. data/lib/tinybucket/resource/user/followers.rb +13 -0
  43. data/lib/tinybucket/resource/user/following.rb +13 -0
  44. data/lib/tinybucket/resource/user/repos.rb +13 -0
  45. data/lib/tinybucket/resource/watchers.rb +22 -0
  46. data/lib/tinybucket/version.rb +1 -1
  47. data/spec/fixtures/build_status.json +16 -0
  48. data/spec/fixtures/repositories/test_owner/get.json +1 -1
  49. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json +16 -0
  50. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json +16 -0
  51. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json +16 -0
  52. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +1 -1
  53. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +1 -1
  54. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +1 -1
  55. data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +1 -1
  56. data/spec/lib/tinybucket/api/build_status_api_spec.rb +65 -0
  57. data/spec/lib/tinybucket/client_spec.rb +8 -4
  58. data/spec/lib/tinybucket/model/build_status_spec.rb +66 -0
  59. data/spec/lib/tinybucket/model/commit_spec.rb +19 -1
  60. data/spec/lib/tinybucket/model/profile_spec.rb +3 -3
  61. data/spec/lib/tinybucket/model/pull_request_spec.rb +3 -15
  62. data/spec/lib/tinybucket/model/repository_spec.rb +14 -20
  63. data/spec/lib/tinybucket/model/team_spec.rb +16 -4
  64. data/spec/lib/tinybucket/resource/branch_restrictions_spec.rb +60 -0
  65. data/spec/lib/tinybucket/resource/commit/build_statuses_spec.rb +50 -0
  66. data/spec/lib/tinybucket/resource/commit/comments_spec.rb +49 -0
  67. data/spec/lib/tinybucket/resource/commits_spec.rb +43 -0
  68. data/spec/lib/tinybucket/resource/forks_spec.rb +36 -0
  69. data/spec/lib/tinybucket/resource/pull_request/comments_spec.rb +41 -0
  70. data/spec/lib/tinybucket/resource/pull_request/commits_spec.rb +41 -0
  71. data/spec/lib/tinybucket/resource/pull_requests_spec.rb +59 -0
  72. data/spec/lib/tinybucket/resource/repos_spec.rb +76 -0
  73. data/spec/lib/tinybucket/resource/team/followers_spec.rb +27 -0
  74. data/spec/lib/tinybucket/resource/team/following_spec.rb +27 -0
  75. data/spec/lib/tinybucket/resource/team/members_spec.rb +27 -0
  76. data/spec/lib/tinybucket/resource/team/repos_spec.rb +27 -0
  77. data/spec/lib/tinybucket/resource/user/followers_spec.rb +27 -0
  78. data/spec/lib/tinybucket/resource/user/following_spec.rb +27 -0
  79. data/spec/lib/tinybucket/resource/user/repos_spec.rb +27 -0
  80. data/spec/lib/tinybucket/resource/watchers_spec.rb +38 -0
  81. data/spec/support/api_response_macros.rb +45 -1
  82. metadata +77 -3
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Tinybucket::Resource::User::Following do
4
+ include ApiResponseMacros
5
+
6
+ let(:owner) { 'test_owner' }
7
+ let(:options) { {} }
8
+ let(:resource) { Tinybucket::Resource::User::Following.new(owner, options) }
9
+
10
+ describe 'Enumerable Methods' do
11
+ let(:request_path) { "/users/#{owner}/following" }
12
+ before { stub_enum_response(:get, request_path) }
13
+
14
+ describe '#take(1)' do
15
+ subject { resource.take(1) }
16
+ it { expect(subject).to be_an_instance_of(Array) }
17
+ end
18
+
19
+ describe '#each' do
20
+ it 'iterate models' do
21
+ resource.each do |m|
22
+ expect(m).to be_an_instance_of(Tinybucket::Model::Profile)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Tinybucket::Resource::User::Repos do
4
+ include ApiResponseMacros
5
+
6
+ let(:owner) { 'test_owner' }
7
+ let(:options) { {} }
8
+ let(:resource) { Tinybucket::Resource::User::Repos.new(owner, options) }
9
+
10
+ describe 'Enumerable Methods' do
11
+ let(:request_path) { "/repositories/#{owner}" }
12
+ before { stub_enum_response(:get, request_path) }
13
+
14
+ describe '#take(1)' do
15
+ subject { resource.take(1) }
16
+ it { expect(subject).to be_an_instance_of(Array) }
17
+ end
18
+
19
+ describe '#each' do
20
+ it 'iterate models' do
21
+ resource.each do |m|
22
+ expect(m).to be_an_instance_of(Tinybucket::Model::Repository)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Tinybucket::Resource::Watchers do
4
+ include ApiResponseMacros
5
+
6
+ let(:owner) { 'test_owner' }
7
+ let(:slug) { 'test_repo' }
8
+ let(:repo) do
9
+ Tinybucket::Model::Repository.new({}).tap do |m|
10
+ m.repo_owner = owner
11
+ m.repo_slug = slug
12
+ end
13
+ end
14
+
15
+ let(:options) { {} }
16
+ let(:resource) { Tinybucket::Resource::Watchers.new(repo, options) }
17
+
18
+ describe 'Enumerable Methods' do
19
+ let(:params) { {} }
20
+ let(:request_path) do
21
+ "/repositories/#{owner}/#{slug}/watchers"
22
+ end
23
+ before { stub_enum_response(:get, request_path) }
24
+
25
+ describe '#take(1)' do
26
+ subject { resource.take(1) }
27
+ it { expect(subject).to be_an_instance_of(Array) }
28
+ end
29
+
30
+ describe '#each' do
31
+ it 'iterate models' do
32
+ resource.each do |m|
33
+ expect(m).to be_an_instance_of(Tinybucket::Model::Profile)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -8,15 +8,48 @@ module ApiResponseMacros
8
8
  else 'json'
9
9
  end
10
10
 
11
- stub_request(method, 'https://api.bitbucket.org/2.0' + path)
11
+ stub_request(method, api_path(path))
12
12
  .to_return(
13
13
  status: (options[:status_code] || 200),
14
14
  body: (options[:message] || fixture_json(method, path, ext)),
15
15
  headers: response_headers)
16
16
  end
17
17
 
18
+ def stub_enum_response(method, path)
19
+ response_headers = { content_type: 'application/json' }
20
+
21
+ first_page_json = fixture_json(method, path, 'json')
22
+
23
+ # stub for first page
24
+ stub_request(method, api_path(path))
25
+ .to_return(
26
+ status: 200,
27
+ body: first_page_json,
28
+ headers: response_headers)
29
+
30
+ # stub for second(last) page
31
+ next_url = JSON.parse(first_page_json)['next'] || api_path(path, page: 2)
32
+ stub_request(method, next_url)
33
+ .to_return(
34
+ status: 200,
35
+ body: last_page_json(api_path(path, page: 1)),
36
+ headers: response_headers)
37
+ end
38
+
18
39
  private
19
40
 
41
+ def api_path(path, params = {})
42
+ 'https://api.bitbucket.org/2.0' + path + query_string(params)
43
+ end
44
+
45
+ def query_string(params)
46
+ return '' if params.empty?
47
+
48
+ '?' + params.each_pair.map do |k, v|
49
+ URI.escape(k.to_s) + '=' + URI.escape(v.to_s)
50
+ end.join('&')
51
+ end
52
+
20
53
  def fixture_json(method, path, ext)
21
54
  parts = path.split('?')
22
55
 
@@ -27,4 +60,15 @@ module ApiResponseMacros
27
60
 
28
61
  File.read(path + '/' + fname)
29
62
  end
63
+
64
+ def last_page_json(prev)
65
+ JSON.generate(
66
+ size: 1,
67
+ page: 2,
68
+ pagelen: 0,
69
+ next: nil,
70
+ previous: prev,
71
+ values: []
72
+ )
73
+ end
30
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinybucket
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hirakiuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -116,12 +116,14 @@ files:
116
116
  - lib/tinybucket/api.rb
117
117
  - lib/tinybucket/api/base_api.rb
118
118
  - lib/tinybucket/api/branch_restrictions_api.rb
119
+ - lib/tinybucket/api/build_status_api.rb
119
120
  - lib/tinybucket/api/comments_api.rb
120
121
  - lib/tinybucket/api/commits_api.rb
121
122
  - lib/tinybucket/api/diff_api.rb
122
123
  - lib/tinybucket/api/helper.rb
123
124
  - lib/tinybucket/api/helper/api_helper.rb
124
125
  - lib/tinybucket/api/helper/branch_restrictions_helper.rb
126
+ - lib/tinybucket/api/helper/build_status_helper.rb
125
127
  - lib/tinybucket/api/helper/comments_helper.rb
126
128
  - lib/tinybucket/api/helper/commits_helper.rb
127
129
  - lib/tinybucket/api/helper/diff_helper.rb
@@ -150,10 +152,12 @@ files:
150
152
  - lib/tinybucket/model.rb
151
153
  - lib/tinybucket/model/base.rb
152
154
  - lib/tinybucket/model/branch_restriction.rb
155
+ - lib/tinybucket/model/build_status.rb
153
156
  - lib/tinybucket/model/comment.rb
154
157
  - lib/tinybucket/model/commit.rb
155
158
  - lib/tinybucket/model/concerns.rb
156
159
  - lib/tinybucket/model/concerns/acceptable_attributes.rb
160
+ - lib/tinybucket/model/concerns/api_callable.rb
157
161
  - lib/tinybucket/model/concerns/enumerable.rb
158
162
  - lib/tinybucket/model/concerns/reloadable.rb
159
163
  - lib/tinybucket/model/concerns/repository_keys.rb
@@ -168,6 +172,7 @@ files:
168
172
  - lib/tinybucket/parser/base_parser.rb
169
173
  - lib/tinybucket/parser/branch_restriction_parser.rb
170
174
  - lib/tinybucket/parser/branch_restrictions_parser.rb
175
+ - lib/tinybucket/parser/build_status_parser.rb
171
176
  - lib/tinybucket/parser/comment_parser.rb
172
177
  - lib/tinybucket/parser/comments_parser.rb
173
178
  - lib/tinybucket/parser/commit_parser.rb
@@ -181,10 +186,34 @@ files:
181
186
  - lib/tinybucket/parser/team_parser.rb
182
187
  - lib/tinybucket/parser/teams_parser.rb
183
188
  - lib/tinybucket/request.rb
189
+ - lib/tinybucket/resource.rb
190
+ - lib/tinybucket/resource/base.rb
191
+ - lib/tinybucket/resource/branch_restrictions.rb
192
+ - lib/tinybucket/resource/commit/base.rb
193
+ - lib/tinybucket/resource/commit/build_statuses.rb
194
+ - lib/tinybucket/resource/commit/comments.rb
195
+ - lib/tinybucket/resource/commits.rb
196
+ - lib/tinybucket/resource/forks.rb
197
+ - lib/tinybucket/resource/pull_request/base.rb
198
+ - lib/tinybucket/resource/pull_request/comments.rb
199
+ - lib/tinybucket/resource/pull_request/commits.rb
200
+ - lib/tinybucket/resource/pull_requests.rb
201
+ - lib/tinybucket/resource/repos.rb
202
+ - lib/tinybucket/resource/team/base.rb
203
+ - lib/tinybucket/resource/team/followers.rb
204
+ - lib/tinybucket/resource/team/following.rb
205
+ - lib/tinybucket/resource/team/members.rb
206
+ - lib/tinybucket/resource/team/repos.rb
207
+ - lib/tinybucket/resource/user/base.rb
208
+ - lib/tinybucket/resource/user/followers.rb
209
+ - lib/tinybucket/resource/user/following.rb
210
+ - lib/tinybucket/resource/user/repos.rb
211
+ - lib/tinybucket/resource/watchers.rb
184
212
  - lib/tinybucket/response.rb
185
213
  - lib/tinybucket/response/handler.rb
186
214
  - lib/tinybucket/version.rb
187
215
  - spec/fixtures/branch_restriction.json
216
+ - spec/fixtures/build_status.json
188
217
  - spec/fixtures/comment.json
189
218
  - spec/fixtures/commit.json
190
219
  - spec/fixtures/profile.json
@@ -197,6 +226,9 @@ files:
197
226
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json
198
227
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json
199
228
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json
229
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json
230
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json
231
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json
200
232
  - spec/fixtures/repositories/test_owner/test_repo/commits/get.json
201
233
  - spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json
202
234
  - spec/fixtures/repositories/test_owner/test_repo/forks/get.json
@@ -227,6 +259,7 @@ files:
227
259
  - spec/fixtures/users/test_owner/following/get.json
228
260
  - spec/fixtures/users/test_owner/get.json
229
261
  - spec/lib/tinybucket/api/branch_restrictions_api_spec.rb
262
+ - spec/lib/tinybucket/api/build_status_api_spec.rb
230
263
  - spec/lib/tinybucket/api/comments_api_spec.rb
231
264
  - spec/lib/tinybucket/api/commits_api_spec.rb
232
265
  - spec/lib/tinybucket/api/diff_api_spec.rb
@@ -240,6 +273,7 @@ files:
240
273
  - spec/lib/tinybucket/connection_spec.rb
241
274
  - spec/lib/tinybucket/error/service_error_spec.rb
242
275
  - spec/lib/tinybucket/model/branch_restriction_spec.rb
276
+ - spec/lib/tinybucket/model/build_status_spec.rb
243
277
  - spec/lib/tinybucket/model/comment_spec.rb
244
278
  - spec/lib/tinybucket/model/commit_spec.rb
245
279
  - spec/lib/tinybucket/model/page_spec.rb
@@ -248,6 +282,23 @@ files:
248
282
  - spec/lib/tinybucket/model/repository_spec.rb
249
283
  - spec/lib/tinybucket/model/team_spec.rb
250
284
  - spec/lib/tinybucket/null_logger_spec.rb
285
+ - spec/lib/tinybucket/resource/branch_restrictions_spec.rb
286
+ - spec/lib/tinybucket/resource/commit/build_statuses_spec.rb
287
+ - spec/lib/tinybucket/resource/commit/comments_spec.rb
288
+ - spec/lib/tinybucket/resource/commits_spec.rb
289
+ - spec/lib/tinybucket/resource/forks_spec.rb
290
+ - spec/lib/tinybucket/resource/pull_request/comments_spec.rb
291
+ - spec/lib/tinybucket/resource/pull_request/commits_spec.rb
292
+ - spec/lib/tinybucket/resource/pull_requests_spec.rb
293
+ - spec/lib/tinybucket/resource/repos_spec.rb
294
+ - spec/lib/tinybucket/resource/team/followers_spec.rb
295
+ - spec/lib/tinybucket/resource/team/following_spec.rb
296
+ - spec/lib/tinybucket/resource/team/members_spec.rb
297
+ - spec/lib/tinybucket/resource/team/repos_spec.rb
298
+ - spec/lib/tinybucket/resource/user/followers_spec.rb
299
+ - spec/lib/tinybucket/resource/user/following_spec.rb
300
+ - spec/lib/tinybucket/resource/user/repos_spec.rb
301
+ - spec/lib/tinybucket/resource/watchers_spec.rb
251
302
  - spec/lib/tinybucket_spec.rb
252
303
  - spec/spec_helper.rb
253
304
  - spec/support/api_response_macros.rb
@@ -274,12 +325,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
325
  version: '0'
275
326
  requirements: []
276
327
  rubyforge_project:
277
- rubygems_version: 2.5.1
328
+ rubygems_version: 2.4.5.1
278
329
  signing_key:
279
330
  specification_version: 4
280
331
  summary: ruby wrapper for the Bitbucket REST API (v2) with oauth
281
332
  test_files:
282
333
  - spec/fixtures/branch_restriction.json
334
+ - spec/fixtures/build_status.json
283
335
  - spec/fixtures/comment.json
284
336
  - spec/fixtures/commit.json
285
337
  - spec/fixtures/profile.json
@@ -292,6 +344,9 @@ test_files:
292
344
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json
293
345
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json
294
346
  - spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json
347
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json
348
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json
349
+ - spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json
295
350
  - spec/fixtures/repositories/test_owner/test_repo/commits/get.json
296
351
  - spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json
297
352
  - spec/fixtures/repositories/test_owner/test_repo/forks/get.json
@@ -322,6 +377,7 @@ test_files:
322
377
  - spec/fixtures/users/test_owner/following/get.json
323
378
  - spec/fixtures/users/test_owner/get.json
324
379
  - spec/lib/tinybucket/api/branch_restrictions_api_spec.rb
380
+ - spec/lib/tinybucket/api/build_status_api_spec.rb
325
381
  - spec/lib/tinybucket/api/comments_api_spec.rb
326
382
  - spec/lib/tinybucket/api/commits_api_spec.rb
327
383
  - spec/lib/tinybucket/api/diff_api_spec.rb
@@ -335,6 +391,7 @@ test_files:
335
391
  - spec/lib/tinybucket/connection_spec.rb
336
392
  - spec/lib/tinybucket/error/service_error_spec.rb
337
393
  - spec/lib/tinybucket/model/branch_restriction_spec.rb
394
+ - spec/lib/tinybucket/model/build_status_spec.rb
338
395
  - spec/lib/tinybucket/model/comment_spec.rb
339
396
  - spec/lib/tinybucket/model/commit_spec.rb
340
397
  - spec/lib/tinybucket/model/page_spec.rb
@@ -343,6 +400,23 @@ test_files:
343
400
  - spec/lib/tinybucket/model/repository_spec.rb
344
401
  - spec/lib/tinybucket/model/team_spec.rb
345
402
  - spec/lib/tinybucket/null_logger_spec.rb
403
+ - spec/lib/tinybucket/resource/branch_restrictions_spec.rb
404
+ - spec/lib/tinybucket/resource/commit/build_statuses_spec.rb
405
+ - spec/lib/tinybucket/resource/commit/comments_spec.rb
406
+ - spec/lib/tinybucket/resource/commits_spec.rb
407
+ - spec/lib/tinybucket/resource/forks_spec.rb
408
+ - spec/lib/tinybucket/resource/pull_request/comments_spec.rb
409
+ - spec/lib/tinybucket/resource/pull_request/commits_spec.rb
410
+ - spec/lib/tinybucket/resource/pull_requests_spec.rb
411
+ - spec/lib/tinybucket/resource/repos_spec.rb
412
+ - spec/lib/tinybucket/resource/team/followers_spec.rb
413
+ - spec/lib/tinybucket/resource/team/following_spec.rb
414
+ - spec/lib/tinybucket/resource/team/members_spec.rb
415
+ - spec/lib/tinybucket/resource/team/repos_spec.rb
416
+ - spec/lib/tinybucket/resource/user/followers_spec.rb
417
+ - spec/lib/tinybucket/resource/user/following_spec.rb
418
+ - spec/lib/tinybucket/resource/user/repos_spec.rb
419
+ - spec/lib/tinybucket/resource/watchers_spec.rb
346
420
  - spec/lib/tinybucket_spec.rb
347
421
  - spec/spec_helper.rb
348
422
  - spec/support/api_response_macros.rb