eezee 1.0.11 → 1.0.16

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
  SHA256:
3
- metadata.gz: 8ec8c0319024f4bba7f5954a4c550b6a9979693675c372471cf11b2f46151921
4
- data.tar.gz: 0ee3cda9cdf0a4a9c7c603106bede81fb67e3102db7fb4d955e5b1d7a3755a02
3
+ metadata.gz: dff31d95a272e5be3b3ae2bc7c50bb922fe036ac2eed5fb9eff9e783a593cd2e
4
+ data.tar.gz: f54e4d23d284a390e3e9b3caa06a0534d04a1891c0c0161799ad1d6ca6d69a5a
5
5
  SHA512:
6
- metadata.gz: 51b80692f4d37107bd6087095e8066fc7c1bc361563d31fe2a41ba4f3fd5edafad3937d268cca6910326550aca915e13c90186d0cd42a7e2ea0982dbe5f347f9
7
- data.tar.gz: 9e39db90a62825eae3cdca9736fd9020b0d21c4355b5e5126aee2d9a6ecb67ce620fd1afe44a8edf61bd4c2484d4becfea07f44e660d918c7a9905eb8dd19e74
6
+ metadata.gz: 53adc04cf023c5a674eaf2969ae82d469e165fd194ee1b6b3fa006d8cfb3f8ad56cc52f6818959911c1c1309e6a9ceaed64bee3b0e69e21e1b17fc5a51cf0022
7
+ data.tar.gz: 47780012f741482b8afde6b55cf8043662aa597403cb70ea181a65ae274c487456231f9ee80adfd2f6e53a60b4a76a1d1f2d0a5e2520f67673da520836af8c56
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 1.0.16
2
+ * Add option to discard request validations using env EEZEE_DISCARD_REQUEST_VALIDATIONS
3
+
4
+ ### 1.0.15
5
+
6
+ * Append uri in error log and message
7
+
8
+ ### 1.0.14
9
+
10
+ * Add ddtrace support
11
+ * Add changelog
data/README.md CHANGED
@@ -179,7 +179,8 @@ Here are the list of available options and about them:
179
179
  | `raise_error` | No | `false` | If you want that Eezee raises an error if the request has wasn't successful. See more in [Errors](#errors) | `true` |
180
180
  | `logger` | No | `false` | If you want to log the request, response, and error | `true` |
181
181
  | `url_encoded` | No | `false` | If you want to send request body as form_url_encoded | `true` |
182
-
182
+ | `preserve_url_params` | No | `false` | The query params will be preserved if the url or path has a nested param like `:character_id` this value will be not replaced | `true` |
183
+ | `ddtrace` | No | `nil` | Support for [DataDog apm](http://gems.datadoghq.com/trace/docs/#Faraday) | `{}` |
183
184
 
184
185
  ### Services
185
186
 
@@ -28,7 +28,7 @@ module Eezee
28
28
  .tap { |response| request.after!(request, response, nil) }
29
29
  rescue Faraday::Error => e
30
30
  response = Eezee::Response.new(e)
31
- error = Eezee::RequestErrorFactory.build(response)
31
+ error = Eezee::RequestErrorFactory.build(request, response)
32
32
  error.log if request.logger
33
33
  return response if rescue_faraday_error?(request, response, error)
34
34
 
@@ -72,14 +72,19 @@ module Eezee
72
72
 
73
73
  def build_faraday_client(request)
74
74
  Faraday.new(request.uri) do |config|
75
- config.request :url_encoded if request.url_encoded
76
- config.use(Faraday::Response::RaiseError) if request.raise_error
77
- config.headers = request.headers if request.headers
78
- config.options[:open_timeout] = request.open_timeout if request.open_timeout
79
- config.options[:timeout] = request.timeout if request.timeout
80
- config.adapter(Faraday.default_adapter)
75
+ faraday_client_options!(config, request)
81
76
  end
82
77
  end
78
+
79
+ def faraday_client_options!(config, request)
80
+ config.request :url_encoded if request.url_encoded
81
+ config.use(Faraday::Response::RaiseError) if request.raise_error
82
+ config.headers = request.headers if request.headers
83
+ config.options[:open_timeout] = request.open_timeout if request.open_timeout
84
+ config.options[:timeout] = request.timeout if request.timeout
85
+ config.adapter(Faraday.default_adapter)
86
+ config.use(:ddtrace, request.ddtrace) if request.ddtrace.any?
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Eezee
4
4
  class RequestError < Error
5
- attr_reader :response
5
+ attr_reader :response, :request
6
6
 
7
- def initialize(response)
7
+ def initialize(request = nil, response = nil)
8
+ @request = request
8
9
  @response = response
9
10
  super(build_message)
10
11
  end
@@ -16,7 +17,7 @@ module Eezee
16
17
  private
17
18
 
18
19
  def build_message
19
- "CODE: #{@response.code} - BODY: #{@response.body.to_json}"
20
+ "CODE: #{@response&.code} - URI: #{@request&.uri} - BODY: #{@response&.body&.to_json}"
20
21
  end
21
22
  end
22
23
 
data/lib/eezee/request.rb CHANGED
@@ -16,6 +16,8 @@ module Eezee
16
16
  timeout
17
17
  url
18
18
  url_encoded
19
+ preserve_url_params
20
+ ddtrace
19
21
  ].freeze
20
22
 
21
23
  DEFAULT = {
@@ -24,7 +26,9 @@ module Eezee
24
26
  params: {},
25
27
  payload: {},
26
28
  raise_error: false,
27
- url_encoded: false
29
+ url_encoded: false,
30
+ preserve_url_params: false,
31
+ ddtrace: {}
28
32
  }.freeze
29
33
 
30
34
  attr_accessor(*(ACCESSORS | %i[uri method]))
@@ -56,7 +60,7 @@ module Eezee
56
60
  validate!
57
61
  build_urn!
58
62
  handle_query_params!
59
- handle_urn_params!
63
+ handle_urn_params! unless @preserve_url_params
60
64
  end
61
65
 
62
66
  def hook!(hook, params)
@@ -66,6 +70,8 @@ module Eezee
66
70
  end
67
71
 
68
72
  def validate!
73
+ return if ENV['EEZEE_DISCARD_REQUEST_VALIDATIONS']
74
+
69
75
  raise Eezee::RequiredFieldError.new(self.class, :url) unless @url
70
76
  end
71
77
 
@@ -3,10 +3,10 @@
3
3
  module Eezee
4
4
  class RequestErrorFactory
5
5
  class << self
6
- def build(response)
6
+ def build(request, response)
7
7
  return TimeoutError.new(response) if response.timeout?
8
8
 
9
- find_by_code(response.code).new(response)
9
+ find_by_code(response.code).new(request, response)
10
10
  end
11
11
 
12
12
  private
data/lib/eezee/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eezee
4
- VERSION = '1.0.11'
4
+ VERSION = '1.0.16'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eezee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - linqueta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-26 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.17.0
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '0.17'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.17.0
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '0.17'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -239,6 +233,7 @@ executables: []
239
233
  extensions: []
240
234
  extra_rdoc_files: []
241
235
  files:
236
+ - CHANGELOG.md
242
237
  - MIT-LICENSE
243
238
  - README.md
244
239
  - lib/eezee.rb
@@ -261,7 +256,7 @@ homepage: https://github.com/linqueta/eezee
261
256
  licenses:
262
257
  - MIT
263
258
  metadata: {}
264
- post_install_message:
259
+ post_install_message:
265
260
  rdoc_options: []
266
261
  require_paths:
267
262
  - lib
@@ -277,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
272
  version: '0'
278
273
  requirements: []
279
274
  rubygems_version: 3.0.3
280
- signing_key:
275
+ signing_key:
281
276
  specification_version: 4
282
277
  summary: The easiest HTTP client for Ruby
283
278
  test_files: []