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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30beca79e944d3f7f1d9a042d502593a24cd28dc
4
- data.tar.gz: 43176302a9f186c38ee982e962085812c324e749
3
+ metadata.gz: 4c30beae6ba69e4282f6aeb92bcb3db1b67e7cda
4
+ data.tar.gz: b826bdcd9e33e89f4397ba62080c1fbebb26dc68
5
5
  SHA512:
6
- metadata.gz: 1e92a959db3b863d6d196551a6f3497fe0db2903c643354b059009d6cbb25a7996a2531f7af2b4c2fd502286b5546f64883b29ad63b2d2f4ae659e0018cc565f
7
- data.tar.gz: 0c6d55ca68c2c5cfe8a577c2d730ab0b414776930908df0b9a7982d816f6020a88c9178fcf3c84da4b011dc4cfcfa600e7e6a9d25cd2576f2ce3ef3cfb7da80a
6
+ metadata.gz: a912d6b5dd5e72d3f14233c64bb452839e600eb3e23c84627d7d00cf4307a3080e2eae327359b5004e4d8e621fb262d8308edcdc4e902db5d34732221f2dc5c1
7
+ data.tar.gz: 87e4d7ce29b3988e6db193e148e24e08b11e7ad6a77df17952318d4eea46cdeb37c921c81038915f6126d22abbd330a76dfec1a3b6796d57378b39bda9e0c5e0
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.0
5
4
  - 2.2.4
6
5
  - 2.3.1
7
6
  - 2.4.0
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.8)
15
- simplecov (<= 0.13)
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.13.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.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
-
@@ -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(:code => response.code, :body => body)
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 code = response.code
96
+ case response
95
97
  when Net::HTTPSuccess
96
98
  true
97
99
  else
98
- @logger.error "example endpoint responded with a non-success #{code} code."
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
- retry unless (tries_count -= 1).zero?
111
+ @logger.warn(error.message)
112
+ (tries_count -= 1).zero? ? raise : retry
111
113
  else
112
114
  response
113
115
  end
@@ -1,3 +1,3 @@
1
1
  module NetworkClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -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", '~> 0'
32
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
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.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: '0'
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: '0'
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: