nxt_http_client 0.2.4 → 0.2.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
  SHA256:
3
- metadata.gz: e7ca4bb27e1b1bc88c3399927d0ff18b5abcc1e14fe8aee9b7f0168a0e0d451e
4
- data.tar.gz: 3950a97f0ba40a17a90504894cf8901320900d9c5692963b4565f8c8e404304e
3
+ metadata.gz: 2a9156afeb06fcba2f57308d7a0ef33582d4e14dd2f1673fdec05fd4173fdd73
4
+ data.tar.gz: f39565c9ab124f24ca55df92c5664037c7a116bf749f8d4acc0ccc502a0e9a54
5
5
  SHA512:
6
- metadata.gz: e96b9225a7514b7c1b22225f6209e99222f3e16698b134c41cde07c62fa1bfd6c83fea0c20cd4499f842ab607bf9985d3682e51618016ff90bc6c99e2c332ccc
7
- data.tar.gz: 9b266ecd968053cd6185e3215b749b11c640580d69b9bdaf91d1c7986b482fe3fe65725f75f9c3304d017174bb31600dcfd5005275c15e7fc3f212e271d5366f
6
+ metadata.gz: af06d4cbc5dfa2aa713e70f8e93bdff96f0e8669691b14d75e194306019d1e5f879f77f894d0d6afe673419a548d41faf4fbf34c5fb0ea704f6c6dc5b6408712
7
+ data.tar.gz: 73d399f7d6ceb3ed38312f7b98d0f825e697be53920a177dad2558fc2a4066146d5eb6413ec1b56957cee08b50b374d7cc8238f70827faaef823d52e4b81f355
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_http_client (0.2.4)
4
+ nxt_http_client (0.2.5)
5
5
  activesupport (~> 5.2)
6
6
  typhoeus
7
7
 
data/README.md CHANGED
@@ -149,6 +149,11 @@ You can also hook into the before_fire and after_fire callbacks to do something
149
149
  These callbacks are inherited down the class hierarchy but are not being chained. Meaning when you overwrite those in your subclass,
150
150
  the callbacks defined by your parent class will not be called anymore.
151
151
 
152
+ ### NxtHttpClient::Error
153
+
154
+ NxtHttpClient also provides an error base class that you might want to use as the base for your client errors.
155
+ It comes with a nice set of useful methods. You can ask the error for the request and response options since it
156
+ requires the response for initialization.
152
157
 
153
158
  ## Development
154
159
 
@@ -5,7 +5,12 @@ module NxtHttpClient
5
5
 
6
6
  def build_request(url, **opts)
7
7
  base_url = opts.delete(:base_url) || default_config.base_url
8
- url = [base_url, url].reject(&:blank?).join('/').gsub(/([^https?:]\/\/)/, '/')
8
+ url = [base_url, url].reject(&:blank?).join('/')
9
+
10
+ duplicated_slashes = url.match(/([^:]\/{2,})/)
11
+ duplicated_slashes && duplicated_slashes.captures.each do |capture|
12
+ url.gsub!(capture, "#{capture[0]}/")
13
+ end
9
14
 
10
15
  opts = default_config.request_options.with_indifferent_access.deep_merge(opts.with_indifferent_access)
11
16
  opts[:headers] ||= {}
@@ -6,6 +6,20 @@ module NxtHttpClient
6
6
 
7
7
  attr_reader :response
8
8
 
9
+ def to_s
10
+ "NxtHttpClient::Error::#{response_code}"
11
+ end
12
+
13
+ def to_h
14
+ {
15
+ url: url,
16
+ response_code: response_code,
17
+ request_options: request_options,
18
+ response_headers: response_headers,
19
+ body: body
20
+ }
21
+ end
22
+
9
23
  def body
10
24
  if response_content_type == 'application/json'
11
25
  JSON.parse(response.body)
@@ -16,11 +30,7 @@ module NxtHttpClient
16
30
  response.body
17
31
  end
18
32
 
19
- def to_s
20
- "NxtHttpClient::Error::#{status_code}"
21
- end
22
-
23
- def status_code
33
+ def response_code
24
34
  response.code || 0
25
35
  end
26
36
 
@@ -1,3 +1,3 @@
1
1
  module NxtHttpClient
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2019-08-04 00:00:00.000000000 Z
14
+ date: 2019-08-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus