nxt_http_client 0.3.0 → 0.3.1

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: 22aa2f16ec7170133779ae75097fdd0c164a3a3a793a98f8d565d6ddfd2ca96c
4
- data.tar.gz: c21b929937fe483cd7d56754d50ba37ae9d83b10bb120e5b772b425f3a04e559
3
+ metadata.gz: 78ac5880ecaada2ab1423658c89c7e46a7edff5b3936c386255776d2a3a9fb93
4
+ data.tar.gz: 3bbd588bdaf3b12481685495fcbae33d497b8ced2a646e204bbc15d9739605d8
5
5
  SHA512:
6
- metadata.gz: be208ed0c5e3b617d48dcca068c8c588e9748ab34f23a538d9039f6b7ed1649dd96f54ec0dbb716de3c823b5f6ff452b06eadfd79a85514f97106d4fef0d7fd4
7
- data.tar.gz: 0743b9d3371ff51381c8a0f5b45547bc86302f0282e8064fe7a93f268e195361ca055ed7a085df38b82653909542488cd6de02a2d5b95abcf547068215097278
6
+ metadata.gz: 5fc826649a72b9b0f2e3076aab3e791045b01c021d1122344449f2b6865878270872e8cfd7a20edc58333608b0c4bbcce347efef4e7c4b4c126d6d173caa75ae
7
+ data.tar.gz: 0e06702933121d3cda176b386c1ed47df0a53fe276b00d4e2e2a2e7efc48ad7804bee9ee54593317f6b2c9eac1415a9351f227bc8625bfe224fbdb4e9f6e4cd5
@@ -5,4 +5,4 @@
5
5
  - [internal] Added CHANGELOG.MD
6
6
  - Refactored a bit
7
7
 
8
- [Compare v0.2.9...v0.2.10](https://github.com/nxt-insurance/nxt_http_client/compare/v0.2.9...v0.2.10)
8
+ [Compare v0.2.9...v0.3.0](https://github.com/nxt-insurance/nxt_http_client/compare/v0.2.9...v0.2.10)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_http_client (0.3.0)
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.6)
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.12.2)
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
@@ -11,5 +11,4 @@ require 'nxt_http_client/error'
11
11
 
12
12
  module NxtHttpClient
13
13
  class Error < StandardError; end
14
- # Your code goes here...
15
14
  end
@@ -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 to_s
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 == 'application/json'
31
+ if response_content_type&.starts_with?('application/json')
27
32
  JSON.parse(response.body)
28
33
  else
29
34
  response.body
@@ -1,3 +1,3 @@
1
1
  module NxtHttpClient
2
- VERSION = '0.3.0'
2
+ VERSION = "0.3.1"
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.3.0
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-07-30 00:00:00.000000000 Z
14
+ date: 2020-08-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus