restful_client 0.3.0 → 1.0.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: ffdd1539730f64064b5e045bf4afcad0374ec2dc
4
- data.tar.gz: 3110fcd87794defb963f4214b8164e706bf1cea5
3
+ metadata.gz: cf0ae7f87f8677979aa4e68a1722c8d9f5d027a2
4
+ data.tar.gz: d63577ee4253c7db5778cd350e42dd6eb14b053d
5
5
  SHA512:
6
- metadata.gz: 2b432086f2e3598fae207ca1a85e56a7c3a74f69194d00b10aa9ed495737c8072452e08d9f0e2c4ef97ff0b0899216400215e350832eb09461b4999013d4510e
7
- data.tar.gz: 6aebfaf5672c02e41a1b66d7c884bd0c7c3a404a4b9a678d014ef0f0fef9ae194a46868f69c5a9d4cec2bd078c9eeeab99710dde7d04e49d5f61df336a3000e6
6
+ metadata.gz: 9346c6b5595c4d02e5740c0309358c6bb07dfc96633ffc23235fe3d8f4ba1108dd9ec3234cb6723a922493b6a754f032717b1995aa8bc5e2df1a1f22a57fe1ae
7
+ data.tar.gz: 923fd5bce06ece481dce25caf498eae2a851e2b097ad7a1a83f8117c0179aa50eb9500e2a02f8091a8bffd660355b5a753983136f94947fc506b148fd958ece7
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ coverage
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -1 +1 @@
1
- ruby-2.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.6'
4
-
5
- gem 'pry-byebug', '~> 3.3.0', {}.merge(ENV['RM_INFO'] ? { require: false } : {})
6
- gem 'rspec', '~> 3.1'
7
- gem 'rspec-its', '~> 1.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
@@ -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
@@ -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.3.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/restful_client'
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.add_development_dependency 'bundler'
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://127.0.0.1:8383/api/v1/
7
+ url: http://localhost:8383/api/v1/
8
8
  pompa_service:
9
- url: http://127.0.0.1:8383/api/v1/
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://127.0.0.1:8383/api/v0/
22
+ url: http://localhost:8383/api/v0/
@@ -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
@@ -1,7 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require 'rspec'
4
+ require 'simplecov'
5
+ SimpleCov.start
5
6
 
6
7
  Dir['./spec/support/**/*.rb'].each { |f| load(f) }
7
8
  load("#{File.dirname(__FILE__)}/../lib/restful_client.rb")
@@ -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.3.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: 2015-12-30 00:00:00.000000000 Z
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/restful_client
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.8
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