network-client 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Gemfile.lock +5 -5
- data/README.md +4 -2
- data/lib/network-client/core.rb +21 -19
- data/lib/network-client/version.rb +1 -1
- data/network-client.gemspec +2 -2
- metadata +3 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c30beae6ba69e4282f6aeb92bcb3db1b67e7cda
|
4
|
+
data.tar.gz: b826bdcd9e33e89f4397ba62080c1fbebb26dc68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a912d6b5dd5e72d3f14233c64bb452839e600eb3e23c84627d7d00cf4307a3080e2eae327359b5004e4d8e621fb262d8308edcdc4e902db5d34732221f2dc5c1
|
7
|
+
data.tar.gz: 87e4d7ce29b3988e6db193e148e24e08b11e7ad6a77df17952318d4eea46cdeb37c921c81038915f6126d22abbd330a76dfec1a3b6796d57378b39bda9e0c5e0
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,8 +11,8 @@ GEM
|
|
11
11
|
i18n (~> 0.7)
|
12
12
|
minitest (~> 5.1)
|
13
13
|
tzinfo (~> 1.1)
|
14
|
-
codeclimate-test-reporter (1.0.
|
15
|
-
simplecov
|
14
|
+
codeclimate-test-reporter (1.0.7)
|
15
|
+
simplecov
|
16
16
|
concurrent-ruby (1.0.5)
|
17
17
|
diff-lcs (1.3)
|
18
18
|
docile (1.1.5)
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
36
|
rspec-support (~> 3.6.0)
|
37
37
|
rspec-support (3.6.0)
|
38
|
-
simplecov (0.
|
38
|
+
simplecov (0.14.1)
|
39
39
|
docile (~> 1.1.0)
|
40
40
|
json (>= 1.8, < 3)
|
41
41
|
simplecov-html (~> 0.10.0)
|
@@ -49,12 +49,12 @@ PLATFORMS
|
|
49
49
|
|
50
50
|
DEPENDENCIES
|
51
51
|
bundler (~> 1.14)
|
52
|
-
codeclimate-test-reporter (~> 1.0
|
52
|
+
codeclimate-test-reporter (~> 1.0)
|
53
53
|
factory_girl (~> 4.5)
|
54
54
|
network-client!
|
55
55
|
rake (~> 10.0)
|
56
56
|
rspec (~> 3.6)
|
57
|
-
simplecov
|
57
|
+
simplecov (~> 0.14.1)
|
58
58
|
|
59
59
|
BUNDLED WITH
|
60
60
|
1.14.6
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Network Client
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/network-client.svg)](https://rubygems.org/gems/network-client)
|
3
3
|
[![Build Status](https://travis-ci.org/abarrak/network-client.svg?branch=master)](https://travis-ci.org/abarrak/network-client)
|
4
|
-
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/abarrak/network-client.svg)](https://gemnasium.com/github.com/abarrak/network-client)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/abarrak/network-client/badges/coverage.svg)](https://codeclimate.com/github/abarrak/network-client/coverage)
|
6
|
+
[![Code Climate](https://lima.codeclimate.com/github/abarrak/network-client/badges/gpa.svg)](https://lima.codeclimate.com/github/abarrak/network-client)
|
7
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
5
8
|
|
6
9
|
## Installation
|
7
10
|
|
@@ -34,4 +37,3 @@ Bug reports and pull requests are very much appreciated at [Github](https://gith
|
|
34
37
|
|
35
38
|
## License
|
36
39
|
[MIT](http://opensource.org/licenses/MIT).
|
37
|
-
|
data/lib/network-client/core.rb
CHANGED
@@ -24,6 +24,7 @@ module NetworkClient
|
|
24
24
|
def initialize(endpoint:, tries: 1)
|
25
25
|
@uri = URI.parse(endpoint)
|
26
26
|
@tries = tries
|
27
|
+
|
27
28
|
set_http_client
|
28
29
|
set_logger
|
29
30
|
set_response_struct
|
@@ -45,6 +46,18 @@ module NetworkClient
|
|
45
46
|
request_json :delete, path, params
|
46
47
|
end
|
47
48
|
|
49
|
+
def set_logger
|
50
|
+
@logger = if defined?(Rails)
|
51
|
+
Rails.logger
|
52
|
+
elsif block_given?
|
53
|
+
yield
|
54
|
+
else
|
55
|
+
logger = Logger.new(STDOUT)
|
56
|
+
logger.level = Logger::DEBUG
|
57
|
+
logger
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
48
61
|
private
|
49
62
|
|
50
63
|
def set_http_client
|
@@ -53,18 +66,6 @@ module NetworkClient
|
|
53
66
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
54
67
|
end
|
55
68
|
|
56
|
-
def set_logger
|
57
|
-
@logger ||= begin
|
58
|
-
if block_given?
|
59
|
-
yield
|
60
|
-
else
|
61
|
-
logger = Logger.new(STDOUT)
|
62
|
-
logger.level = Logger::DEBUG
|
63
|
-
logger
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
69
|
def set_response_struct
|
69
70
|
@response_struct = Struct.new(:code, :body)
|
70
71
|
end
|
@@ -73,7 +74,7 @@ module NetworkClient
|
|
73
74
|
response = request(http_method, path, params)
|
74
75
|
body = JSON.parse(response.body)
|
75
76
|
|
76
|
-
@response_struct.new(
|
77
|
+
@response_struct.new(response.code, body)
|
77
78
|
|
78
79
|
rescue JSON::ParserError => error
|
79
80
|
@logger.error "parsing response body as json failed.\n Details: \n #{error.message}"
|
@@ -81,21 +82,22 @@ module NetworkClient
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def request(http_method, path, params = {})
|
85
|
+
headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' }
|
84
86
|
case http_method
|
85
87
|
when :get
|
86
88
|
full_path = encode_path_params(path, params)
|
87
|
-
request = HTTP_VERBS[http_method].new(full_path)
|
89
|
+
request = HTTP_VERBS[http_method].new(full_path, headers)
|
88
90
|
else
|
89
|
-
request = HTTP_VERBS[http_method].new(path)
|
91
|
+
request = HTTP_VERBS[http_method].new(path, headers)
|
90
92
|
request.set_form_data(params)
|
91
93
|
end
|
92
94
|
|
93
95
|
response = http_request(request)
|
94
|
-
case
|
96
|
+
case response
|
95
97
|
when Net::HTTPSuccess
|
96
98
|
true
|
97
99
|
else
|
98
|
-
@logger.error "
|
100
|
+
@logger.error "endpoint responded with a non-success #{code} code."
|
99
101
|
end
|
100
102
|
|
101
103
|
response
|
@@ -106,8 +108,8 @@ module NetworkClient
|
|
106
108
|
tries_count ||= @tries
|
107
109
|
response = @http.request(request)
|
108
110
|
rescue Errno::ECONNREFUSED, Net::ReadTimeout, Net::OpenTimeout => error
|
109
|
-
@logger.warn(error)
|
110
|
-
|
111
|
+
@logger.warn(error.message)
|
112
|
+
(tries_count -= 1).zero? ? raise : retry
|
111
113
|
else
|
112
114
|
response
|
113
115
|
end
|
data/network-client.gemspec
CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.6"
|
30
30
|
spec.add_development_dependency "factory_girl", "~> 4.5"
|
31
|
-
spec.add_development_dependency "simplecov",
|
32
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency "simplecov", "~> 0.14.1"
|
32
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: network-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdullah Barrak (abarrak)
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.14.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.14.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: codeclimate-test-reporter
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,9 +87,6 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '1.0'
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.0.0
|
93
90
|
type: :development
|
94
91
|
prerelease: false
|
95
92
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -97,9 +94,6 @@ dependencies:
|
|
97
94
|
- - "~>"
|
98
95
|
- !ruby/object:Gem::Version
|
99
96
|
version: '1.0'
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 1.0.0
|
103
97
|
description: network-client gem is almost a drop-in thin layer around Net::HTTP classes with
|
104
98
|
simple error handling and retry functionality implemented.
|
105
99
|
email:
|