bandiera-client 3.0.4 → 3.1.0

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: 0231e248ad75e4dd5762406ce09fbb937853babf
4
- data.tar.gz: cfacb3426cc40e772fc2e357f4ff870c99412f60
3
+ metadata.gz: af9fac1412763441ed0e77c4373acda416c2eb11
4
+ data.tar.gz: 4afd81a7571125fecff204ab9e7f35689e05f325
5
5
  SHA512:
6
- metadata.gz: 9e4dfec63215c440d81ebe4f1cbdbe5f7465cd36340b1fa27cfa72f3577f51fb04fc55ee6048a5b660637b8dcbc146f561df640fa177cf0bba3bbf9e94bb6f49
7
- data.tar.gz: ec1efc0dd1c3cf895515c1481ed8bdcf6311db2b3034e093524043e9041e3776ef42e6e1c766ddafb2732a9341092eb414de4dd0ced9c8fdc75ec97890ed0165
6
+ metadata.gz: 58d25b937aeebbd0a6dcf6eb6eb72cf8a1dbf1c1a7f7e252a82d9e2fce7a1c9daa8f5b07f073aa93ebfc88fefc1933290583958af7f7a00cd783ec40fbd5e539
7
+ data.tar.gz: 8603383f510a8ee339b8773d6919509d3083c988f02ed41a0b588021cdada2dbfccff5584199d75133b3834380b9ebdcce4606cf8d94d2772e3397310c59ff57
@@ -0,0 +1 @@
1
+ ./.rubocop.yml
@@ -1,28 +1,61 @@
1
+ AllCops:
2
+ StyleGuideCopsOnly: true
3
+
1
4
  Metrics/LineLength:
2
5
  Description: 'Limit lines to 120 characters.'
3
6
  Max: 120
7
+ Enabled: true
8
+
9
+ Metrics/BlockLength:
10
+ ExcludedMethods:
11
+ - describe
12
+ - context
13
+ Enabled: true
14
+
15
+ Metrics/MethodLength:
16
+ CountComments: false
17
+ Max: 20
18
+ Enabled: true
19
+
20
+ Metrics/AbcSize:
21
+ Max: 40
22
+ Enabled: true
4
23
 
5
24
  Style/Documentation:
6
25
  Enabled: false
7
26
 
8
- Style/SpaceBeforeFirstArg:
27
+ Layout/SpaceBeforeFirstArg:
9
28
  Enabled: false
10
29
 
11
30
  Style/BracesAroundHashParameters:
12
31
  Enabled: false
13
32
 
14
- Style/IndentHash:
33
+ Style/CaseEquality:
34
+ Enabled: false
35
+
36
+ Style/GuardClause:
37
+ Enabled: false
38
+
39
+ Style/ConditionalAssignment:
40
+ Enabled: false
41
+
42
+ Layout/IndentHash:
15
43
  EnforcedStyle: consistent
44
+ Enabled: true
16
45
 
17
- Style/AlignHash:
46
+ Layout/AlignHash:
47
+ Severity: fatal
48
+ Enabled: true
18
49
  EnforcedHashRocketStyle: table
19
50
  EnforcedColonStyle: table
20
51
 
21
- Style/AlignParameters:
52
+ Layout/AlignParameters:
22
53
  EnforcedStyle: with_fixed_indentation
54
+ Enabled: true
23
55
 
24
56
  Style/StringLiterals:
25
57
  EnforcedStyle: single_quotes
58
+ Enabled: true
26
59
 
27
60
  Style/CollectionMethods:
28
61
  PreferredMethods:
@@ -31,9 +64,41 @@ Style/CollectionMethods:
31
64
  inject: 'reduce'
32
65
  detect: 'find'
33
66
  find_all: 'select'
67
+ Enabled: true
34
68
 
35
- Style/DotPosition:
69
+ Layout/DotPosition:
36
70
  EnforcedStyle: leading
71
+ Enabled: true
37
72
 
38
73
  Style/DoubleNegation:
39
74
  Enabled: false
75
+
76
+ Style/Alias:
77
+ # I like alias_method with symbol parameters
78
+ Enabled: false
79
+
80
+ Layout/SpaceAroundOperators:
81
+ # When true, allows most uses of extra spacing if the intent is to align
82
+ # with an operator on the previous or next line, not counting empty lines
83
+ # or comment lines.
84
+ AllowForAlignment: true
85
+ Enabled: true
86
+
87
+ Style/SymbolArray:
88
+ # Turned off because the associated auto-correct makes a real mess
89
+ Enabled: false
90
+
91
+ Style/FrozenStringLiteralComment:
92
+ # An 'every file in the repo' recommendation.
93
+ Enabled: false
94
+ Severity: warning
95
+
96
+ Layout/EmptyLineAfterMagicComment:
97
+ # Nooo not another 'every file in the repo' recommendation.
98
+ Enabled: false
99
+ Severity: warning
100
+
101
+ Style/GlobalVars:
102
+ # Doesn't justify a critical
103
+ Enabled: true
104
+ Severity: warning
@@ -7,7 +7,9 @@ rvm:
7
7
  - 2.0
8
8
  - 2.1
9
9
  - 2.2
10
- - 2.3.0
10
+ - 2.3
11
+ - 2.4
12
+ - 2.5
11
13
  - jruby-9.0.0.0
12
14
 
13
15
  # Ensure we don't build for *every* commit (doesn't apply to PR builds)
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ = 3.1.0 / 19-March-2017
2
+
3
+ * Use Typhoeus as the HTTP library of choice. Thanks @mattrayner!
4
+
1
5
  = 3.0.3 / 11-April-2016
2
6
 
3
7
  * Stop the client from logging warnings
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'pry'
29
29
 
30
- spec.add_dependency 'rest-client'
30
+ spec.add_dependency 'typhoeus'
31
31
  spec.add_dependency 'macmillan-utils'
32
32
  end
@@ -1,6 +1,7 @@
1
- require 'rest_client'
1
+ require 'typhoeus'
2
2
  require 'json'
3
3
  require 'logger'
4
+ require 'bandiera/client/errors'
4
5
 
5
6
  module Bandiera
6
7
  ##
@@ -25,11 +26,11 @@ module Bandiera
25
26
  # @param [String] client_name A client name to pass through along with the HTTP requests
26
27
  #
27
28
  def initialize(base_uri = 'http://localhost', logger = Logger.new($stdout), client_name = nil)
28
- @base_uri = base_uri
29
- @base_uri << '/api' unless @base_uri.match(/\/api$/)
30
- @logger = logger
31
- @timeout = 0.2 # 0.4s (0.2 + 0.2) default timeout
32
- @client_name = client_name
29
+ @base_uri = base_uri
30
+ @base_uri << '/api' unless @base_uri.match(/\/api$/)
31
+ @logger = logger
32
+ @timeout = 0.2 # 0.4s (0.2 + 0.2) default timeout
33
+ @client_name = client_name
33
34
  end
34
35
 
35
36
  # @deprecated This functionality was deprecated/removed in 3.0.0
@@ -108,7 +109,7 @@ module Bandiera
108
109
  end
109
110
 
110
111
  EXCEPTIONS_TO_HANDLE = (
111
- Errno.constants.map { |cla| Errno.const_get(cla) } + [RestClient::Exception, JSON::ParserError, SocketError]
112
+ Errno.constants.map { |cla| Errno.const_get(cla) } + [Bandiera::Client::Error, JSON::ParserError, SocketError]
112
113
  ).flatten
113
114
 
114
115
  def get_and_handle_exceptions(path, params, http_opts, return_upon_error, error_msg_prefix, &block)
@@ -127,11 +128,19 @@ module Bandiera
127
128
  end
128
129
 
129
130
  def get(path, params, passed_http_opts)
130
- default_http_opts = { method: :get, timeout: timeout, open_timeout: timeout, headers: headers }
131
- resource = RestClient::Resource.new(@base_uri, default_http_opts.merge(passed_http_opts))
132
- response = resource[path].get(params: clean_params(params))
133
-
134
- JSON.parse(response.body)
131
+ default_http_opts = { method: :get, timeout: timeout, headers: headers, params: clean_params(params) }
132
+ resource = Typhoeus::Request.new("#{@base_uri}#{path}", default_http_opts.merge(passed_http_opts))
133
+ response = resource.run
134
+
135
+ if response.success?
136
+ JSON.parse(response.body)
137
+ elsif response.timed_out?
138
+ raise Bandiera::Client::TimeoutError, 'Connection timed out'
139
+ elsif response.code == 0
140
+ raise Bandiera::Client::Error, response.return_message
141
+ else
142
+ raise Bandiera::Client::ResponseError, "HTTP request failed: " + response.code.to_s
143
+ end
135
144
  end
136
145
 
137
146
  def clean_params(passed_params)
@@ -0,0 +1,12 @@
1
+ module Bandiera
2
+ class Client
3
+ class Error < StandardError
4
+ end
5
+
6
+ class TimeoutError < Bandiera::Client::Error
7
+ end
8
+
9
+ class ResponseError < Bandiera::Client::Error
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Bandiera
2
2
  class Client
3
- VERSION = '3.0.4'.freeze
3
+ VERSION = '3.1.0'.freeze
4
4
  end
5
5
  end
@@ -53,16 +53,16 @@ describe Bandiera::Client do
53
53
  end
54
54
  end
55
55
 
56
- context 'when some RestClient::Resource options are passed' do
57
- it 'passes them onto the RestClient::Resource' do
56
+ context 'when some Typhoeus::Request options are passed' do
57
+ it 'passes them onto the Typhoeus::Resource' do
58
58
  params = {}
59
59
  options = { timeout: 24, open_timeout: 24 }
60
- response = double(:response, body: JSON.generate({ response: {} }))
61
- resource = double(:resource, '[]' => double(get: response))
60
+ response = double(:response, body: JSON.generate({ response: {} }), success?: true)
61
+ resource = double(:resource, run: response)
62
62
 
63
- expect(RestClient::Resource)
63
+ expect(Typhoeus::Request)
64
64
  .to receive(:new)
65
- .with(api_uri, method: :get, timeout: 24, open_timeout: 24, headers: anything)
65
+ .with("#{api_uri}/v2/groups/foo/features/bar", method: :get, timeout: 24, open_timeout: 24, headers: {"User-Agent"=>"Bandiera Ruby Client / #{Bandiera::Client::VERSION}"}, params: {})
66
66
  .once
67
67
  .and_return(resource)
68
68
 
@@ -70,6 +70,47 @@ describe Bandiera::Client do
70
70
  end
71
71
  end
72
72
 
73
+ context 'raises a Bandiera::Client::Error, Bandiera::Client::TimeoutError or Bandiera::Client::ResponseError if there is a problem' do
74
+ context 'Bandiera::Client::Error' do
75
+ it 'is raised if the response code is 0' do
76
+ params = {}
77
+ response = double(:response, body: JSON.generate({ response: {} }), success?: false, timed_out?: false, code: 0, return_message: 'test')
78
+ resource = double(:resource, run: response)
79
+
80
+ allow(Typhoeus::Request).to receive(:new).and_return(resource)
81
+ expect(logger).to receive(:warn).with('Bandiera::Client - HANDLED EXCEPTION #<Bandiera::Client::Error: test> - CLASS Bandiera::Client::Error')
82
+
83
+ subject.enabled?('foo', 'bar', params)
84
+ end
85
+ end
86
+
87
+ context 'Bandiera::Client::TimeoutError' do
88
+ it 'is raised if the response is flagged as timed out' do
89
+ params = {}
90
+ response = double(:response, body: JSON.generate({ response: {} }), success?: false, timed_out?: true)
91
+ resource = double(:resource, run: response)
92
+
93
+ allow(Typhoeus::Request).to receive(:new).and_return(resource)
94
+ expect(logger).to receive(:warn).with('Bandiera::Client - HANDLED EXCEPTION #<Bandiera::Client::TimeoutError: Connection timed out> - CLASS Bandiera::Client::TimeoutError')
95
+
96
+ subject.enabled?('foo', 'bar', params)
97
+ end
98
+ end
99
+
100
+ context 'Bandiera::Client::ResponseError' do
101
+ it 'is raised if the response is flagged as timed out' do
102
+ params = {}
103
+ response = double(:response, body: JSON.generate({ response: {} }), success?: false, timed_out?: false, code: 404)
104
+ resource = double(:resource, run: response)
105
+
106
+ allow(Typhoeus::Request).to receive(:new).and_return(resource)
107
+ expect(logger).to receive(:warn).with('Bandiera::Client - HANDLED EXCEPTION #<Bandiera::Client::ResponseError: HTTP request failed: 404> - CLASS Bandiera::Client::ResponseError')
108
+
109
+ subject.enabled?('foo', 'bar', params)
110
+ end
111
+ end
112
+ end
113
+
73
114
  describe '#get_feature' do
74
115
  let(:group) { 'pubserv' }
75
116
  let(:feature) { 'log-stats' }
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.4
4
+ version: 3.1.0
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-07-12 00:00:00.000000000 Z
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rest-client
112
+ name: typhoeus
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -157,6 +157,7 @@ files:
157
157
  - Rakefile
158
158
  - bandiera-client.gemspec
159
159
  - lib/bandiera/client.rb
160
+ - lib/bandiera/client/errors.rb
160
161
  - lib/bandiera/client/version.rb
161
162
  - lib/bandiera/middleware.rb
162
163
  - spec/lib/bandiera/client_spec.rb
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.4.3
186
+ rubygems_version: 2.6.13
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Simple feature flagging API client.
data/.hound.yml DELETED
@@ -1,39 +0,0 @@
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