tinybucket 0.1.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +2 -1
- data/Gemfile +4 -4
- data/README.md +48 -20
- data/Rakefile +7 -0
- data/lib/tinybucket.rb +7 -4
- data/lib/tinybucket/api/base_api.rb +2 -19
- data/lib/tinybucket/api/branch_restrictions_api.rb +35 -11
- data/lib/tinybucket/api/comments_api.rb +38 -4
- data/lib/tinybucket/api/commits_api.rb +60 -10
- data/lib/tinybucket/api/diff_api.rb +22 -0
- data/lib/tinybucket/api/helper/api_helper.rb +0 -11
- data/lib/tinybucket/api/helper/commits_helper.rb +7 -0
- data/lib/tinybucket/api/pull_requests_api.rb +79 -22
- data/lib/tinybucket/api/repo_api.rb +37 -17
- data/lib/tinybucket/api/repos_api.rb +13 -6
- data/lib/tinybucket/api/team_api.rb +54 -29
- data/lib/tinybucket/api/user_api.rb +43 -23
- data/lib/tinybucket/api_factory.rb +2 -4
- data/lib/tinybucket/client.rb +39 -20
- data/lib/tinybucket/config.rb +1 -1
- data/lib/tinybucket/connection.rb +3 -3
- data/lib/tinybucket/enumerator.rb +44 -0
- data/lib/tinybucket/error.rb +2 -0
- data/lib/tinybucket/error/conflict.rb +6 -0
- data/lib/tinybucket/error/not_found.rb +6 -0
- data/lib/tinybucket/error/service_error.rb +8 -4
- data/lib/tinybucket/iterator.rb +77 -0
- data/lib/tinybucket/model/base.rb +6 -6
- data/lib/tinybucket/model/branch_restriction.rb +27 -0
- data/lib/tinybucket/model/comment.rb +32 -6
- data/lib/tinybucket/model/commit.rb +63 -9
- data/lib/tinybucket/model/concerns.rb +1 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +18 -0
- data/lib/tinybucket/model/error_response.rb +16 -1
- data/lib/tinybucket/model/page.rb +25 -49
- data/lib/tinybucket/model/profile.rb +56 -8
- data/lib/tinybucket/model/pull_request.rb +114 -18
- data/lib/tinybucket/model/repository.rb +177 -36
- data/lib/tinybucket/model/team.rb +70 -10
- data/lib/tinybucket/request.rb +2 -0
- data/lib/tinybucket/response.rb +1 -1
- data/lib/tinybucket/response/handler.rb +21 -0
- data/lib/tinybucket/version.rb +1 -1
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json +16 -0
- data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/comments_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/commits_api_spec.rb +92 -3
- data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +34 -4
- data/spec/lib/tinybucket/api/repo_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/repos_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/team_api_spec.rb +1 -6
- data/spec/lib/tinybucket/api/user_api_spec.rb +15 -2
- data/spec/lib/tinybucket/api_factory_spec.rb +2 -7
- data/spec/lib/tinybucket/client_spec.rb +10 -25
- data/spec/lib/tinybucket/error/service_error_spec.rb +23 -0
- data/spec/lib/tinybucket/model/commit_spec.rb +27 -4
- data/spec/lib/tinybucket/model/page_spec.rb +0 -30
- data/spec/lib/tinybucket/model/profile_spec.rb +3 -3
- data/spec/lib/tinybucket/model/pull_request_spec.rb +11 -5
- data/spec/lib/tinybucket/model/repository_spec.rb +5 -5
- data/spec/lib/tinybucket/model/team_spec.rb +4 -4
- data/spec/lib/tinybucket_spec.rb +10 -27
- data/spec/spec_helper.rb +3 -2
- data/spec/support/api_response_macros.rb +2 -2
- metadata +12 -3
- data/lib/tinybucket/response/error_handler.rb +0 -14
@@ -35,18 +35,18 @@ RSpec.describe Tinybucket::Model::Profile do
|
|
35
35
|
describe 'followers' do
|
36
36
|
let(:request_path) { "/users/#{username}/followers" }
|
37
37
|
subject { model.followers() }
|
38
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
38
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'following' do
|
42
42
|
let(:request_path) { "/users/#{username}/following" }
|
43
43
|
subject { model.following }
|
44
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
44
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
45
45
|
end
|
46
46
|
|
47
47
|
describe 'repos' do
|
48
48
|
let(:request_path) { "/repositories/#{username}" }
|
49
49
|
subject { model.repos }
|
50
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
50
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
51
51
|
end
|
52
52
|
end
|
@@ -94,7 +94,7 @@ RSpec.describe Tinybucket::Model::PullRequest do
|
|
94
94
|
|
95
95
|
subject { model.commits() }
|
96
96
|
|
97
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
97
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
98
98
|
end
|
99
99
|
|
100
100
|
describe 'comments' do
|
@@ -104,9 +104,15 @@ RSpec.describe Tinybucket::Model::PullRequest do
|
|
104
104
|
|
105
105
|
subject { model.comments }
|
106
106
|
|
107
|
-
it
|
108
|
-
|
109
|
-
|
107
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
108
|
+
it 'return comments which associate with this pull request' do
|
109
|
+
# extract iterator from enumerator.
|
110
|
+
iterator = subject.instance_variable_get(:@iterator)
|
111
|
+
# extract values from iterator.
|
112
|
+
values = iterator.instance_variable_get(:@values)
|
113
|
+
|
114
|
+
values.each do |comment|
|
115
|
+
expect(comment).to be_an_instance_of(Tinybucket::Model::Comment)
|
110
116
|
expect(comment.commented_to).to eq(model)
|
111
117
|
end
|
112
118
|
end
|
@@ -144,4 +150,4 @@ RSpec.describe Tinybucket::Model::PullRequest do
|
|
144
150
|
|
145
151
|
it { expect(subject).to be_truthy }
|
146
152
|
end
|
147
|
-
end
|
153
|
+
end
|
@@ -52,7 +52,7 @@ RSpec.describe Tinybucket::Model::Repository do
|
|
52
52
|
|
53
53
|
subject { model.pull_requests() }
|
54
54
|
|
55
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
55
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
56
56
|
end
|
57
57
|
|
58
58
|
describe '#pull_request' do
|
@@ -80,19 +80,19 @@ RSpec.describe Tinybucket::Model::Repository do
|
|
80
80
|
describe '#watchers' do
|
81
81
|
let(:request_path) { "/repositories/#{owner}/#{slug}/watchers" }
|
82
82
|
subject { model.watchers }
|
83
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
83
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
84
84
|
end
|
85
85
|
|
86
86
|
describe '#forks' do
|
87
87
|
let(:request_path) { "/repositories/#{owner}/#{slug}/forks" }
|
88
88
|
subject { model.forks }
|
89
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
89
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
90
90
|
end
|
91
91
|
|
92
92
|
describe '#commits' do
|
93
93
|
let(:request_path) { "/repositories/#{owner}/#{slug}/commits" }
|
94
94
|
subject { model.commits }
|
95
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
95
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
96
96
|
end
|
97
97
|
|
98
98
|
describe '#commit' do
|
@@ -105,7 +105,7 @@ RSpec.describe Tinybucket::Model::Repository do
|
|
105
105
|
describe '#branch_restrictions' do
|
106
106
|
let(:request_path) { "/repositories/#{owner}/#{slug}/branch-restrictions" }
|
107
107
|
subject { model.branch_restrictions }
|
108
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
108
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
109
109
|
end
|
110
110
|
|
111
111
|
describe '#branch_restriction' do
|
@@ -35,24 +35,24 @@ RSpec.describe Tinybucket::Model::Team do
|
|
35
35
|
describe '#members' do
|
36
36
|
let(:request_path) { "/teams/#{teamname}/members" }
|
37
37
|
subject { model.members }
|
38
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
38
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#followers' do
|
42
42
|
let(:request_path) { "/teams/#{teamname}/followers" }
|
43
43
|
subject { model.followers() }
|
44
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
44
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '#following' do
|
48
48
|
let(:request_path) { "/teams/#{teamname}/following" }
|
49
49
|
subject { model.following }
|
50
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
50
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
51
51
|
end
|
52
52
|
|
53
53
|
describe '#repos' do
|
54
54
|
let(:request_path) { "/teams/#{teamname}/repositories" }
|
55
55
|
subject { model.repos }
|
56
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::
|
56
|
+
it { expect(subject).to be_an_instance_of(Tinybucket::Enumerator) }
|
57
57
|
end
|
58
58
|
end
|
data/spec/lib/tinybucket_spec.rb
CHANGED
@@ -3,31 +3,8 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe Tinybucket do
|
4
4
|
|
5
5
|
describe 'new' do
|
6
|
-
|
7
|
-
|
8
|
-
shared_examples_for 'return client which configured with options' do
|
9
|
-
it 'return client instance which configured with options' do
|
10
|
-
expect(subject).to be_instance_of(Tinybucket::Client)
|
11
|
-
expect(subject.config).to eq(options)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when options passed' do
|
16
|
-
subject { Tinybucket.new(options) }
|
17
|
-
it_behaves_like 'return client which configured with options'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when block given' do
|
21
|
-
subject { Tinybucket.new(&block) }
|
22
|
-
let(:block) do
|
23
|
-
lambda do |config|
|
24
|
-
options.each_pair do |key, value|
|
25
|
-
config.send("#{key}=", value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
it_behaves_like 'return client which configured with options'
|
30
|
-
end
|
6
|
+
subject { Tinybucket.new }
|
7
|
+
it { expect(subject).to be_instance_of(Tinybucket::Client) }
|
31
8
|
end
|
32
9
|
|
33
10
|
describe 'config' do
|
@@ -38,19 +15,25 @@ RSpec.describe Tinybucket do
|
|
38
15
|
describe 'configure' do
|
39
16
|
subject(:config) { Tinybucket.config }
|
40
17
|
let(:logger) { Logger.new($stdout) }
|
18
|
+
let(:oauth_token) { 'test_oauth_token' }
|
19
|
+
let(:oauth_secret) { 'test_oauth_secret' }
|
41
20
|
|
42
|
-
it '
|
21
|
+
it 'is configurable' do
|
43
22
|
expect(config.logger).to be_nil
|
44
23
|
|
45
24
|
expect do
|
46
25
|
Tinybucket.configure do |config|
|
47
26
|
config.logger = logger
|
27
|
+
config.oauth_token = oauth_token
|
28
|
+
config.oauth_secret = oauth_secret
|
48
29
|
end
|
49
30
|
end.not_to raise_error
|
50
31
|
|
51
32
|
expect(config.logger).to eq(logger)
|
33
|
+
expect(config.oauth_token).to eq(oauth_token)
|
34
|
+
expect(config.oauth_secret).to eq(oauth_secret)
|
52
35
|
end
|
53
36
|
|
54
|
-
after { Tinybucket.
|
37
|
+
after { Tinybucket.instance_variable_set(:@config, nil) }
|
55
38
|
end
|
56
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,13 +10,14 @@ require 'coveralls'
|
|
10
10
|
require 'simplecov'
|
11
11
|
Coveralls.wear!
|
12
12
|
|
13
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
13
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
14
14
|
SimpleCov::Formatter::HTMLFormatter,
|
15
15
|
Coveralls::SimpleCov::Formatter
|
16
|
-
]
|
16
|
+
])
|
17
17
|
SimpleCov.start do
|
18
18
|
add_filter '.bundle/'
|
19
19
|
add_filter 'spec'
|
20
|
+
add_filter 'features'
|
20
21
|
end
|
21
22
|
|
22
23
|
if ENV['CODECLIMATE_REPORT']
|
@@ -10,8 +10,8 @@ module ApiResponseMacros
|
|
10
10
|
|
11
11
|
stub_request(method, 'https://bitbucket.org/api/2.0' + path)
|
12
12
|
.to_return(
|
13
|
-
status: 200,
|
14
|
-
body: fixture_json(method, path, ext),
|
13
|
+
status: (options[:status_code] || 200),
|
14
|
+
body: (options[:message] || fixture_json(method, path, ext)),
|
15
15
|
headers: response_headers)
|
16
16
|
end
|
17
17
|
|
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: 0.
|
4
|
+
version: 1.0.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-03-
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -140,9 +140,13 @@ files:
|
|
140
140
|
- lib/tinybucket/config.rb
|
141
141
|
- lib/tinybucket/connection.rb
|
142
142
|
- lib/tinybucket/constants.rb
|
143
|
+
- lib/tinybucket/enumerator.rb
|
143
144
|
- lib/tinybucket/error.rb
|
144
145
|
- lib/tinybucket/error/base_error.rb
|
146
|
+
- lib/tinybucket/error/conflict.rb
|
147
|
+
- lib/tinybucket/error/not_found.rb
|
145
148
|
- lib/tinybucket/error/service_error.rb
|
149
|
+
- lib/tinybucket/iterator.rb
|
146
150
|
- lib/tinybucket/model.rb
|
147
151
|
- lib/tinybucket/model/base.rb
|
148
152
|
- lib/tinybucket/model/branch_restriction.rb
|
@@ -150,6 +154,7 @@ files:
|
|
150
154
|
- lib/tinybucket/model/commit.rb
|
151
155
|
- lib/tinybucket/model/concerns.rb
|
152
156
|
- lib/tinybucket/model/concerns/acceptable_attributes.rb
|
157
|
+
- lib/tinybucket/model/concerns/enumerable.rb
|
153
158
|
- lib/tinybucket/model/concerns/reloadable.rb
|
154
159
|
- lib/tinybucket/model/concerns/repository_keys.rb
|
155
160
|
- lib/tinybucket/model/error_response.rb
|
@@ -177,7 +182,7 @@ files:
|
|
177
182
|
- lib/tinybucket/parser/teams_parser.rb
|
178
183
|
- lib/tinybucket/request.rb
|
179
184
|
- lib/tinybucket/response.rb
|
180
|
-
- lib/tinybucket/response/
|
185
|
+
- lib/tinybucket/response/handler.rb
|
181
186
|
- lib/tinybucket/version.rb
|
182
187
|
- spec/fixtures/branch_restriction.json
|
183
188
|
- spec/fixtures/comment.json
|
@@ -188,6 +193,7 @@ files:
|
|
188
193
|
- spec/fixtures/repositories/test_owner/get.json
|
189
194
|
- spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json
|
190
195
|
- spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json
|
196
|
+
- spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json
|
191
197
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json
|
192
198
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json
|
193
199
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json
|
@@ -232,6 +238,7 @@ files:
|
|
232
238
|
- spec/lib/tinybucket/api_factory_spec.rb
|
233
239
|
- spec/lib/tinybucket/client_spec.rb
|
234
240
|
- spec/lib/tinybucket/connection_spec.rb
|
241
|
+
- spec/lib/tinybucket/error/service_error_spec.rb
|
235
242
|
- spec/lib/tinybucket/model/branch_restriction_spec.rb
|
236
243
|
- spec/lib/tinybucket/model/comment_spec.rb
|
237
244
|
- spec/lib/tinybucket/model/commit_spec.rb
|
@@ -281,6 +288,7 @@ test_files:
|
|
281
288
|
- spec/fixtures/repositories/test_owner/get.json
|
282
289
|
- spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json
|
283
290
|
- spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json
|
291
|
+
- spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json
|
284
292
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json
|
285
293
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json
|
286
294
|
- spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json
|
@@ -325,6 +333,7 @@ test_files:
|
|
325
333
|
- spec/lib/tinybucket/api_factory_spec.rb
|
326
334
|
- spec/lib/tinybucket/client_spec.rb
|
327
335
|
- spec/lib/tinybucket/connection_spec.rb
|
336
|
+
- spec/lib/tinybucket/error/service_error_spec.rb
|
328
337
|
- spec/lib/tinybucket/model/branch_restriction_spec.rb
|
329
338
|
- spec/lib/tinybucket/model/comment_spec.rb
|
330
339
|
- spec/lib/tinybucket/model/commit_spec.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Tinybucket
|
2
|
-
module Response
|
3
|
-
class ErrorHandler < Faraday::Response::Middleware
|
4
|
-
def on_complete(env)
|
5
|
-
status_code = env[:status].to_i
|
6
|
-
|
7
|
-
return if status_code < 400
|
8
|
-
|
9
|
-
Tinybucket.logger.error "Invalid response code:#{status_code}"
|
10
|
-
raise Tinybucket::Error::ServiceError.new(env)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|