nxt_http_client 0.3.0 → 0.3.1
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/CHANGELOG.md +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +36 -0
- data/lib/nxt_http_client.rb +0 -1
- data/lib/nxt_http_client/error.rb +9 -4
- 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: 78ac5880ecaada2ab1423658c89c7e46a7edff5b3936c386255776d2a3a9fb93
|
4
|
+
data.tar.gz: 3bbd588bdaf3b12481685495fcbae33d497b8ced2a646e204bbc15d9739605d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fc826649a72b9b0f2e3076aab3e791045b01c021d1122344449f2b6865878270872e8cfd7a20edc58333608b0c4bbcce347efef4e7c4b4c126d6d173caa75ae
|
7
|
+
data.tar.gz: 0e06702933121d3cda176b386c1ed47df0a53fe276b00d4e2e2a2e7efc48ad7804bee9ee54593317f6b2c9eac1415a9351f227bc8625bfe224fbdb4e9f6e4cd5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_http_client (0.3.
|
4
|
+
nxt_http_client (0.3.1)
|
5
5
|
activesupport (~> 6.0.0)
|
6
6
|
nxt_registry
|
7
7
|
typhoeus
|
@@ -18,13 +18,13 @@ GEM
|
|
18
18
|
addressable (2.7.0)
|
19
19
|
public_suffix (>= 2.0.2, < 5.0)
|
20
20
|
coderay (1.1.2)
|
21
|
-
concurrent-ruby (1.1.
|
21
|
+
concurrent-ruby (1.1.7)
|
22
22
|
crack (0.4.3)
|
23
23
|
safe_yaml (~> 1.0.0)
|
24
24
|
diff-lcs (1.3)
|
25
25
|
ethon (0.12.0)
|
26
26
|
ffi (>= 1.3.0)
|
27
|
-
ffi (1.
|
27
|
+
ffi (1.13.1)
|
28
28
|
hashdiff (1.0.1)
|
29
29
|
i18n (1.8.5)
|
30
30
|
concurrent-ruby (~> 1.0)
|
data/README.md
CHANGED
@@ -94,6 +94,42 @@ class MyClient < NxtHttpClient
|
|
94
94
|
end
|
95
95
|
```
|
96
96
|
|
97
|
+
### HTTP Methods
|
98
|
+
|
99
|
+
Instead of fire you can simply use the http verbs as methods
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
class MyClient < NxtHttpClient
|
103
|
+
|
104
|
+
def initialize(url)
|
105
|
+
@url = url
|
106
|
+
end
|
107
|
+
|
108
|
+
attr_reader :url
|
109
|
+
|
110
|
+
def fetch
|
111
|
+
get(url) do
|
112
|
+
handler.on(:success) { |response| response.body }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def create(params)
|
117
|
+
post(url, params: params) do
|
118
|
+
handler.on(:success) { |response| response.body }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def update(params)
|
123
|
+
put(url, params: params) do
|
124
|
+
handler.on(:success) { |response| response.body }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# ... there are others as you know ...
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
132
|
+
|
97
133
|
### configure
|
98
134
|
|
99
135
|
Register default request options on the class level. Available options are `request_options` that are passed directly to
|
data/lib/nxt_http_client.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
module NxtHttpClient
|
2
2
|
class Error < StandardError
|
3
|
-
def initialize(response)
|
3
|
+
def initialize(response, message = nil)
|
4
4
|
@response = response.blank? ? Typhoeus::Response.new : response
|
5
5
|
@id = SecureRandom.uuid
|
6
|
+
@message = message || default_message
|
7
|
+
|
8
|
+
super(@message)
|
6
9
|
end
|
7
10
|
|
8
|
-
attr_reader :response, :id
|
11
|
+
attr_reader :response, :id, :message
|
12
|
+
|
13
|
+
alias_method :to_s, :message
|
9
14
|
|
10
|
-
def
|
15
|
+
def default_message
|
11
16
|
"NxtHttpClient::Error::#{response_code}"
|
12
17
|
end
|
13
18
|
|
@@ -23,7 +28,7 @@ module NxtHttpClient
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def body
|
26
|
-
if response_content_type
|
31
|
+
if response_content_type&.starts_with?('application/json')
|
27
32
|
JSON.parse(response.body)
|
28
33
|
else
|
29
34
|
response.body
|
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.3.
|
4
|
+
version: 0.3.1
|
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: 2020-
|
14
|
+
date: 2020-08-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|