restful_client 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +5 -5
- data/lib/restful_client.rb +3 -13
- data/restful_client.gemspec +4 -6
- data/spec/config/restful_services.yml +3 -3
- data/spec/restful_client_spec.rb +32 -12
- data/spec/spec_helper.rb +2 -1
- data/spec/support/test_server.rb +2 -0
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf0ae7f87f8677979aa4e68a1722c8d9f5d027a2
|
4
|
+
data.tar.gz: d63577ee4253c7db5778cd350e42dd6eb14b053d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9346c6b5595c4d02e5740c0309358c6bb07dfc96633ffc23235fe3d8f4ba1108dd9ec3234cb6723a922493b6a754f032717b1995aa8bc5e2df1a1f22a57fe1ae
|
7
|
+
data.tar.gz: 923fd5bce06ece481dce25caf498eae2a851e2b097ad7a1a83f8117c0179aa50eb9500e2a02f8091a8bffd660355b5a753983136f94947fc506b148fd958ece7
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.2.
|
1
|
+
ruby-2.2.3
|
data/Gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'thin', '~> 1.
|
4
|
-
|
5
|
-
gem 'pry-byebug', '~> 3.
|
6
|
-
gem 'rspec', '~> 3.
|
7
|
-
gem 'rspec-its', '~> 1.
|
3
|
+
gem 'thin', '~> 1.7'
|
4
|
+
gem 'simplecov', '~> 0.12', require: false
|
5
|
+
gem 'pry-byebug', '~> 3.4', {}.merge(ENV['RM_INFO'] ? { require: false } : {})
|
6
|
+
gem 'rspec', '~> 3.5'
|
7
|
+
gem 'rspec-its', '~> 1.2'
|
8
8
|
gem 'rubocop', '~> 0.35.1'
|
9
9
|
|
10
10
|
gemspec
|
data/lib/restful_client.rb
CHANGED
@@ -11,15 +11,12 @@ module RestfulClient
|
|
11
11
|
|
12
12
|
class RestError < StandardError; end
|
13
13
|
|
14
|
-
class << self
|
15
|
-
attr_writer :configuration, :logger, :timeout_occured_count
|
16
|
-
end
|
17
14
|
@@configuration = nil
|
18
15
|
@@logger = nil
|
19
16
|
@@timeout_occured_count = 0
|
20
17
|
|
21
|
-
SERVER_SIDE_ERRORS_RANGE = 500
|
22
|
-
CLIENT_SIDE_ERRORS_RANGE = 400
|
18
|
+
SERVER_SIDE_ERRORS_RANGE = 500 unless defined?(SERVER_SIDE_ERRORS_RANGE)
|
19
|
+
CLIENT_SIDE_ERRORS_RANGE = 400 unless defined?(CLIENT_SIDE_ERRORS_RANGE)
|
23
20
|
|
24
21
|
def self.configure
|
25
22
|
@@configuration ||= RestfulClientConfiguration.new
|
@@ -57,12 +54,6 @@ module RestfulClient
|
|
57
54
|
run_safe_request(caller, request, false, &on_error_block)
|
58
55
|
end
|
59
56
|
|
60
|
-
def post_raw(caller, path, payload, custom_timeout = timeout, &on_error_block)
|
61
|
-
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
62
|
-
request = Typhoeus::Request.new(url, method: 'POST', body: payload, timeout: custom_timeout)
|
63
|
-
run_safe_request(caller, request, false, &on_error_block)
|
64
|
-
end
|
65
|
-
|
66
57
|
def delete(caller, path, payload = {}, extra = {}, &on_error_block)
|
67
58
|
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
68
59
|
headers, payload_as_str = prepare_payload_with_headers(payload, extra.fetch('headers', {}))
|
@@ -116,7 +107,7 @@ module RestfulClient
|
|
116
107
|
# 200, OK
|
117
108
|
if response.success?
|
118
109
|
logger.debug { "Success in #{method} :: Code: #{response.response_code}, #{response.body}" }
|
119
|
-
return '' if response.body.empty?
|
110
|
+
return '' if response.body.empty? || response.body == ' '
|
120
111
|
begin
|
121
112
|
return JSON.parse(response.body)
|
122
113
|
rescue => e
|
@@ -164,7 +155,6 @@ module RestfulClient
|
|
164
155
|
logger.error { "#{error_type} #{response.code}/#{response.return_code} for: #{error_description}" }
|
165
156
|
return ''
|
166
157
|
else
|
167
|
-
|
168
158
|
fail RestError.new(:BadReturnCode)
|
169
159
|
end
|
170
160
|
end
|
data/restful_client.gemspec
CHANGED
@@ -3,12 +3,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'restful_client'
|
6
|
-
spec.version = '0.
|
6
|
+
spec.version = '1.0.0'
|
7
7
|
spec.authors = ['Avner Cohen']
|
8
8
|
spec.email = ['israbirding@gmail.com']
|
9
9
|
spec.description = 'An HTTP framework for micro-services based environment, build on top of Typheous and Service Jynx'
|
10
10
|
spec.summary = 'An HTTP framework for micro-services based environment'
|
11
|
-
spec.homepage = 'https://github.com/AvnerCohen/
|
11
|
+
spec.homepage = 'https://github.com/AvnerCohen/restful-client'
|
12
12
|
spec.license = 'MIT'
|
13
13
|
|
14
14
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -16,8 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.
|
20
|
-
|
21
|
-
spec.add_runtime_dependency 'service_jynx'
|
22
|
-
spec.add_runtime_dependency 'typhoeus'
|
19
|
+
spec.add_runtime_dependency 'service_jynx', '~> 0'
|
20
|
+
spec.add_runtime_dependency 'typhoeus', '~> 0'
|
23
21
|
end
|
@@ -4,9 +4,9 @@ default: &default
|
|
4
4
|
posts:
|
5
5
|
url: http://1.2.3.4:8383/api/v1/
|
6
6
|
locally:
|
7
|
-
url: http://
|
7
|
+
url: http://localhost:8383/api/v1/
|
8
8
|
pompa_service:
|
9
|
-
url: http://
|
9
|
+
url: http://localhost:8383/api/v1/
|
10
10
|
|
11
11
|
|
12
12
|
development: &development
|
@@ -19,4 +19,4 @@ production: &production
|
|
19
19
|
posts:
|
20
20
|
url: http://1.2.3.4:8383/api/v0/
|
21
21
|
locally:
|
22
|
-
url: http://
|
22
|
+
url: http://localhost:8383/api/v0/
|
data/spec/restful_client_spec.rb
CHANGED
@@ -201,10 +201,6 @@ describe :RestfulClient do
|
|
201
201
|
RestfulClient.configure do |config|
|
202
202
|
config.env_name = 'production'
|
203
203
|
config.config_folder = 'spec/config'
|
204
|
-
config.report_method = proc do |*args|
|
205
|
-
klass = args.first
|
206
|
-
set_global(klass)
|
207
|
-
end
|
208
204
|
end
|
209
205
|
RestfulClient.get('locally', '/client_error') { nil }
|
210
206
|
|
@@ -215,10 +211,6 @@ describe :RestfulClient do
|
|
215
211
|
RestfulClient.configure do |config|
|
216
212
|
config.env_name = 'production'
|
217
213
|
config.config_folder = 'spec/config'
|
218
|
-
config.report_method = proc do |*args|
|
219
|
-
klass = args.first
|
220
|
-
set_global(klass)
|
221
|
-
end
|
222
214
|
end
|
223
215
|
|
224
216
|
RestfulClient.get('locally', '/non_existing') { nil }
|
@@ -231,11 +223,8 @@ describe :RestfulClient do
|
|
231
223
|
RestfulClient.configure do |config|
|
232
224
|
config.env_name = 'production'
|
233
225
|
config.config_folder = 'spec/config'
|
234
|
-
config.report_method = proc do |*args|
|
235
|
-
klass = args.first
|
236
|
-
set_global(klass)
|
237
|
-
end
|
238
226
|
end
|
227
|
+
|
239
228
|
0.upto(9) do
|
240
229
|
RestfulClient.get('locally', '/non_existing') { 'default' }
|
241
230
|
end
|
@@ -262,6 +251,25 @@ describe :RestfulClient do
|
|
262
251
|
|
263
252
|
expect($some_global).to eq('ServiceJynx')
|
264
253
|
end
|
254
|
+
|
255
|
+
it 'should not call server after max errors with http_code => 500' do
|
256
|
+
RestfulClient.configure do |config|
|
257
|
+
config.env_name = 'production'
|
258
|
+
config.config_folder = 'spec/config'
|
259
|
+
config.report_method = proc do |*args|
|
260
|
+
klass = args.first
|
261
|
+
set_global(klass)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
0.upto(10) do
|
265
|
+
RestfulClient.get('locally', '/server_error') { 'default' }
|
266
|
+
end
|
267
|
+
|
268
|
+
RestfulClient.get('locally', '/server_error') { |msg| $some_global = msg }
|
269
|
+
|
270
|
+
expect($some_global).to include('set as down')
|
271
|
+
end
|
272
|
+
|
265
273
|
end
|
266
274
|
end
|
267
275
|
|
@@ -422,4 +430,16 @@ describe :RestfulClient do
|
|
422
430
|
expect(RestfulClient.srv_url('posts')).to eq('http://1.2.3.4:8383/api/v0/')
|
423
431
|
end
|
424
432
|
end
|
433
|
+
|
434
|
+
describe :NonJsonResponse do
|
435
|
+
it 'should fail to block when server side returns a plain string rather than json' do
|
436
|
+
RestfulClient.configure do |config|
|
437
|
+
config.env_name = 'production'
|
438
|
+
config.config_folder = 'spec/config'
|
439
|
+
end
|
440
|
+
|
441
|
+
RestfulClient.get('locally', '/non_json') { |msg| $some_global = msg }
|
442
|
+
expect($some_global).to include('unexpected token')
|
443
|
+
end
|
444
|
+
end
|
425
445
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/test_server.rb
CHANGED
@@ -15,6 +15,8 @@ module MyApp
|
|
15
15
|
[500, { 'Content-Type' => 'application/json' }, { counter: @@counter }.to_json]
|
16
16
|
elsif path == '/api/v0/bounce'
|
17
17
|
[200, { 'Content-Type' => 'text/plain' }, env['rack.input'].gets]
|
18
|
+
elsif path == '/api/v0/non_json'
|
19
|
+
[200, { 'Content-Type' => 'text/plain' }, 'moshe']
|
18
20
|
elsif path == '/api/v0/non_existing'
|
19
21
|
[404, { 'Content-Type' => 'text/plain' }, {}.to_json]
|
20
22
|
elsif path == '/api/v0/server_error'
|
metadata
CHANGED
@@ -1,55 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avner Cohen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: service_jynx
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: typhoeus
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '0'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
description: An HTTP framework for micro-services based environment, build on top
|
@@ -79,7 +65,7 @@ files:
|
|
79
65
|
- spec/restful_client_spec.rb
|
80
66
|
- spec/spec_helper.rb
|
81
67
|
- spec/support/test_server.rb
|
82
|
-
homepage: https://github.com/AvnerCohen/
|
68
|
+
homepage: https://github.com/AvnerCohen/restful-client
|
83
69
|
licenses:
|
84
70
|
- MIT
|
85
71
|
metadata: {}
|
@@ -99,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
85
|
version: '0'
|
100
86
|
requirements: []
|
101
87
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.4.
|
88
|
+
rubygems_version: 2.4.5.1
|
103
89
|
signing_key:
|
104
90
|
specification_version: 4
|
105
91
|
summary: An HTTP framework for micro-services based environment
|