nxt_http_client 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -0
- data/lib/nxt_http_client/client.rb +6 -1
- data/lib/nxt_http_client/error.rb +15 -5
- data/lib/nxt_http_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a9156afeb06fcba2f57308d7a0ef33582d4e14dd2f1673fdec05fd4173fdd73
|
4
|
+
data.tar.gz: f39565c9ab124f24ca55df92c5664037c7a116bf749f8d4acc0ccc502a0e9a54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af06d4cbc5dfa2aa713e70f8e93bdff96f0e8669691b14d75e194306019d1e5f879f77f894d0d6afe673419a548d41faf4fbf34c5fb0ea704f6c6dc5b6408712
|
7
|
+
data.tar.gz: 73d399f7d6ceb3ed38312f7b98d0f825e697be53920a177dad2558fc2a4066146d5eb6413ec1b56957cee08b50b374d7cc8238f70827faaef823d52e4b81f355
|
data/Gemfile.lock
CHANGED
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('/')
|
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
|
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
|
|
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
|
+
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-
|
14
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|