bandiera-client 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d59a3e5cb3cf23e4137715345e15df7499e00e48
4
- data.tar.gz: 1165f18f168f53e8695c575859b0ae841d9ac789
3
+ metadata.gz: 0231e248ad75e4dd5762406ce09fbb937853babf
4
+ data.tar.gz: cfacb3426cc40e772fc2e357f4ff870c99412f60
5
5
  SHA512:
6
- metadata.gz: e7b6ace839926487e8f938c4511e71ee7e96aaf69521094187e4005e73d548ffe6c1ce5dcd51f1a66309b199c15a573011abc84ed28abda38a36f61ce1e38bc0
7
- data.tar.gz: ae4a2f37b35d439ede1d9de7965665d6ddd443f544efb5c3ffa3549faba78c204f33ccb1b40461f6a2556b7b3ae991517cba8714cf78793efb735eaf3ee9d3e8
6
+ metadata.gz: 9e4dfec63215c440d81ebe4f1cbdbe5f7465cd36340b1fa27cfa72f3577f51fb04fc55ee6048a5b660637b8dcbc146f561df640fa177cf0bba3bbf9e94bb6f49
7
+ data.tar.gz: ec1efc0dd1c3cf895515c1481ed8bdcf6311db2b3034e093524043e9041e3776ef42e6e1c766ddafb2732a9341092eb414de4dd0ced9c8fdc75ec97890ed0165
@@ -0,0 +1,39 @@
1
+ Metrics/LineLength:
2
+ Description: 'Limit lines to 120 characters.'
3
+ Max: 120
4
+
5
+ Style/Documentation:
6
+ Enabled: false
7
+
8
+ Style/SpaceBeforeFirstArg:
9
+ Enabled: false
10
+
11
+ Style/BracesAroundHashParameters:
12
+ Enabled: false
13
+
14
+ Style/IndentHash:
15
+ EnforcedStyle: consistent
16
+
17
+ Style/AlignHash:
18
+ EnforcedHashRocketStyle: table
19
+ EnforcedColonStyle: table
20
+
21
+ Style/AlignParameters:
22
+ EnforcedStyle: with_fixed_indentation
23
+
24
+ Style/StringLiterals:
25
+ EnforcedStyle: single_quotes
26
+
27
+ Style/CollectionMethods:
28
+ PreferredMethods:
29
+ collect: 'map'
30
+ collect!: 'map!'
31
+ inject: 'reduce'
32
+ detect: 'find'
33
+ find_all: 'select'
34
+
35
+ Style/DotPosition:
36
+ EnforcedStyle: leading
37
+
38
+ Style/DoubleNegation:
39
+ Enabled: false
@@ -8,8 +8,7 @@ rvm:
8
8
  - 2.1
9
9
  - 2.2
10
10
  - 2.3.0
11
- - ruby
12
- - jruby
11
+ - jruby-9.0.0.0
13
12
 
14
13
  # Ensure we don't build for *every* commit (doesn't apply to PR builds)
15
14
  branches:
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rspec'
24
24
  spec.add_development_dependency 'webmock'
25
25
  spec.add_development_dependency 'rack-test'
26
+ spec.add_development_dependency 'rack', '< 2.0.0' # NOTE for the time being, don't force us to use ruby 2.2.2 please.
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'pry'
28
29
 
@@ -108,7 +108,7 @@ module Bandiera
108
108
  end
109
109
 
110
110
  EXCEPTIONS_TO_HANDLE = (
111
- Errno.constants.map { |cla| Errno.const_get(cla) } + [RestClient::Exception, JSON::ParserError]
111
+ Errno.constants.map { |cla| Errno.const_get(cla) } + [RestClient::Exception, JSON::ParserError, SocketError]
112
112
  ).flatten
113
113
 
114
114
  def get_and_handle_exceptions(path, params, http_opts, return_upon_error, error_msg_prefix, &block)
@@ -116,8 +116,14 @@ module Bandiera
116
116
  logger.debug("#{error_msg_prefix} - #{res['warning']}") if res['warning']
117
117
  block.call(res['response']) if block
118
118
  res['response']
119
- rescue *EXCEPTIONS_TO_HANDLE
119
+ rescue *EXCEPTIONS_TO_HANDLE => e
120
+ message = "Bandiera::Client - HANDLED EXCEPTION #{e.inspect} - CLASS #{e.class.name}"
121
+ logger.warn(message)
120
122
  return_upon_error
123
+ rescue => e
124
+ message = "Bandiera::Client - UNHANDLED EXCEPTION #{e.inspect} - CLASS #{e.class.name}"
125
+ logger.error(message)
126
+ raise
121
127
  end
122
128
 
123
129
  def get(path, params, passed_http_opts)
@@ -1,5 +1,5 @@
1
1
  module Bandiera
2
2
  class Client
3
- VERSION = '3.0.3'.freeze
3
+ VERSION = '3.0.4'.freeze
4
4
  end
5
5
  end
@@ -6,6 +6,40 @@ describe Bandiera::Client do
6
6
  let(:logger) { double.as_null_object }
7
7
  subject { Bandiera::Client.new(api_uri, logger) }
8
8
 
9
+ shared_examples_for 'a robust request' do
10
+ context 'bandiera is down' do
11
+ it 'returns a default response' do
12
+ stub_request(:get, url).to_return(status: [0, ''])
13
+
14
+ expect(response).to eq expected_error_response
15
+ end
16
+ end
17
+
18
+ context 'bandiera is having some problems' do
19
+ it 'returns a default response' do
20
+ stub_request(:get, url).to_return(status: 500, body: '')
21
+
22
+ expect(response).to eq expected_error_response
23
+ end
24
+ end
25
+
26
+ context 'bandiera times out' do
27
+ it 'returns a default response' do
28
+ stub_request(:get, url).to_timeout
29
+
30
+ expect(response).to eq expected_error_response
31
+ end
32
+ end
33
+
34
+ context 'bandiera cannot be contacted' do
35
+ it 'returns a default response' do
36
+ stub_request(:get, url).to_raise(::SocketError)
37
+
38
+ expect(response).to eq expected_error_response
39
+ end
40
+ end
41
+ end
42
+
9
43
  context 'when a client name is provided' do
10
44
  let(:group) { 'pubserv' }
11
45
  let(:feature) { 'log-stats' }
@@ -40,11 +74,12 @@ describe Bandiera::Client do
40
74
  let(:group) { 'pubserv' }
41
75
  let(:feature) { 'log-stats' }
42
76
  let(:url) { "#{api_uri}/v2/groups/#{group}/features/#{feature}" }
77
+ let(:response) { subject.get_feature(group, feature) }
78
+ let(:expected_error_response) { false }
43
79
 
44
80
  context 'all is ok' do
45
81
  it 'returns the bandiera response' do
46
82
  stub = stub_api_request(url, 'response' => true)
47
- response = subject.get_feature(group, feature)
48
83
 
49
84
  expect(response).to be true
50
85
  expect(stub).to have_been_requested
@@ -72,54 +107,26 @@ describe Bandiera::Client do
72
107
  # 2 calls - one for the request, one for the warning
73
108
  expect(logger).to receive(:debug).twice
74
109
 
75
- response = subject.get_feature(group, feature)
76
-
77
110
  expect(response).to be false
78
111
  expect(stub).to have_been_requested
79
112
  end
80
113
  end
81
114
  end
82
115
 
83
- context 'bandiera is down' do
84
- it 'returns a default response' do
85
- stub_request(:get, url).to_return(status: [0, ''])
86
-
87
- response = subject.get_feature(group, feature)
88
-
89
- expect(response).to be false
90
- end
91
- end
92
-
93
- context 'bandiera is having some problems' do
94
- it 'returns a default response' do
95
- stub_request(:get, url).to_return(status: 500, body: '')
96
-
97
- response = subject.get_feature(group, feature)
98
-
99
- expect(response).to be false
100
- end
101
- end
102
-
103
- context 'bandiera times out' do
104
- it 'returns a default response' do
105
- stub_request(:get, url).to_timeout
106
-
107
- response = subject.get_feature(group, feature)
116
+ it_behaves_like 'a robust request'
108
117
 
109
- expect(response).to be false
110
- end
111
- end
112
118
  end
113
119
 
114
120
  describe '#get_features_for_group' do
115
121
  let(:group) { 'pubserv' }
116
122
  let(:url) { "#{api_uri}/v2/groups/#{group}/features" }
123
+ let(:response) { subject.get_features_for_group(group) }
124
+ let(:expected_error_response) { {} }
117
125
 
118
126
  context 'all is ok' do
119
127
  it 'returns the bandiera response' do
120
128
  feature_hash = { 'show-stuff' => true, 'show-other-stuff' => false }
121
129
  stub = stub_api_request(url, 'response' => feature_hash)
122
- response = subject.get_features_for_group(group)
123
130
 
124
131
  expect(response).to eq(feature_hash)
125
132
  expect(stub).to have_been_requested
@@ -147,53 +154,24 @@ describe Bandiera::Client do
147
154
  # 2 calls - one for the request, one for the warning
148
155
  expect(logger).to receive(:debug).twice
149
156
 
150
- response = subject.get_features_for_group(group)
151
-
152
157
  expect(response).to be {}
153
158
  expect(stub).to have_been_requested
154
159
  end
155
160
  end
156
161
  end
157
162
 
158
- context 'bandiera is down' do
159
- it 'returns a default response' do
160
- stub_request(:get, url).to_return(status: [0, ''])
161
-
162
- response = subject.get_features_for_group(group)
163
-
164
- expect(response).to be {}
165
- end
166
- end
167
-
168
- context 'bandiera is having some problems' do
169
- it 'returns a default response' do
170
- stub_request(:get, url).to_return(status: 500, body: '')
171
-
172
- response = subject.get_features_for_group(group)
173
-
174
- expect(response).to be {}
175
- end
176
- end
177
-
178
- context 'bandiera times out' do
179
- it 'returns a default response' do
180
- stub_request(:get, url).to_timeout
181
-
182
- response = subject.get_features_for_group(group)
183
-
184
- expect(response).to be {}
185
- end
186
- end
163
+ it_behaves_like 'a robust request'
187
164
  end
188
165
 
189
166
  describe '#get_all' do
190
167
  let(:url) { "#{api_uri}/v2/all" }
168
+ let(:response) { subject.get_all }
169
+ let(:expected_error_response) { {} }
191
170
 
192
171
  context 'all is ok' do
193
172
  it 'returns the bandiera response' do
194
173
  feature_hash = { 'pubserv' => { 'show-stuff' => true, 'show-other-stuff' => false } }
195
174
  stub = stub_api_request(url, 'response' => feature_hash)
196
- response = subject.get_all
197
175
 
198
176
  expect(response).to eq(feature_hash)
199
177
  expect(stub).to have_been_requested
@@ -221,43 +199,13 @@ describe Bandiera::Client do
221
199
  # 2 calls - one for the request, one for the warning
222
200
  expect(logger).to receive(:debug).twice
223
201
 
224
- response = subject.get_all
225
-
226
202
  expect(response).to be {}
227
203
  expect(stub).to have_been_requested
228
204
  end
229
205
  end
230
206
  end
231
207
 
232
- context 'bandiera is down' do
233
- it 'returns a default response' do
234
- stub_request(:get, url).to_return(status: [0, ''])
235
-
236
- response = subject.get_all
237
-
238
- expect(response).to be {}
239
- end
240
- end
241
-
242
- context 'bandiera is having some problems' do
243
- it 'returns a default response' do
244
- stub_request(:get, url).to_return(status: 200, body: '<html></html>')
245
-
246
- response = subject.get_all
247
-
248
- expect(response).to be {}
249
- end
250
- end
251
-
252
- context 'bandiera times out' do
253
- it 'returns a default response' do
254
- stub_request(:get, url).to_timeout
255
-
256
- response = subject.get_all
257
-
258
- expect(response).to be {}
259
- end
260
- end
208
+ it_behaves_like 'a robust request'
261
209
  end
262
210
 
263
211
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandiera-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Springer Nature
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -168,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
182
  version: '0'
169
183
  requirements: []
170
184
  rubyforge_project:
171
- rubygems_version: 2.5.1
185
+ rubygems_version: 2.4.3
172
186
  signing_key:
173
187
  specification_version: 4
174
188
  summary: Simple feature flagging API client.
data/.hound.yml DELETED
@@ -1 +0,0 @@
1
- .rubocop.yml