nxt_http_client 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/lib/nxt_http_client/client.rb +20 -2
- data/lib/nxt_http_client/client_dsl.rb +1 -1
- data/lib/nxt_http_client/version.rb +1 -1
- data/nxt_http_client.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 487ffd02f8b43481b080e1d8d44904ea0d42b08bfdd8571f83c1d724f1dc3fdf
|
4
|
+
data.tar.gz: 601306df52b05252158373e563252fb6afb3d5686d6e1e91d232dec4c8187721
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03021c3307a49498cd261bfd68e0df1acf86c4ae9f3ad0825bffaa4a31873753a304295dc50fefb3937a4d7eea18f7799d624ccfa35ac3deecb0254bb59c3361
|
7
|
+
data.tar.gz: bb09bed1b60681e76f2a531d5a39e89ca7753e532d61fa5ed4d5a5f3c346721bf82dfefe0d769f5befd92fd91175bb51ebf74a79f6753324f7547c637bec2f5a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_http_client (0.1.
|
4
|
+
nxt_http_client (0.1.5)
|
5
5
|
activesupport (~> 5.2)
|
6
6
|
typhoeus
|
7
7
|
|
@@ -36,6 +36,7 @@ GEM
|
|
36
36
|
method_source (~> 0.9.0)
|
37
37
|
public_suffix (3.1.1)
|
38
38
|
rake (10.5.0)
|
39
|
+
redis (4.1.2)
|
39
40
|
rspec (3.8.0)
|
40
41
|
rspec-core (~> 3.8.0)
|
41
42
|
rspec-expectations (~> 3.8.0)
|
@@ -70,6 +71,7 @@ DEPENDENCIES
|
|
70
71
|
nxt_vcr_harness
|
71
72
|
pry
|
72
73
|
rake (~> 10.0)
|
74
|
+
redis
|
73
75
|
rspec (~> 3.0)
|
74
76
|
vcr
|
75
77
|
webmock
|
@@ -1,11 +1,29 @@
|
|
1
1
|
module NxtHttpClient
|
2
2
|
class Client
|
3
3
|
extend ClientDsl
|
4
|
+
CACHE_STRATEGIES = %w[global thread]
|
4
5
|
|
5
6
|
def build_request(url, **opts)
|
6
7
|
base_url = opts.delete(:base_url) || self.class.base_url
|
7
8
|
url = [base_url, url].reject(&:blank?).join('/').gsub(/([^https?:]\/\/)/, '/')
|
8
|
-
|
9
|
+
|
10
|
+
opts = self.class.default_request_options.with_indifferent_access.deep_merge(opts.with_indifferent_access)
|
11
|
+
opts[:headers] ||= {}
|
12
|
+
|
13
|
+
if opts[:cache] ||= false
|
14
|
+
strategy = opts.delete(:cache)
|
15
|
+
|
16
|
+
case strategy.to_s
|
17
|
+
when 'thread'
|
18
|
+
cache_key = Thread.current[:nxt_http_client_cache_key] ||= "#{SecureRandom.base58}::#{DateTime.current}"
|
19
|
+
opts[:headers].reverse_merge!(cache_key: cache_key)
|
20
|
+
when 'global'
|
21
|
+
opts[:headers].delete(:cache_key)
|
22
|
+
else
|
23
|
+
raise ArgumentError, "Cache strategy unknown: #{strategy}. Options are #{CACHE_STRATEGIES}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
9
27
|
|
10
28
|
Typhoeus::Request.new(url, opts)
|
11
29
|
end
|
@@ -51,7 +69,7 @@ module NxtHttpClient
|
|
51
69
|
result
|
52
70
|
end
|
53
71
|
|
54
|
-
%w[get post patch put].each do |method|
|
72
|
+
%w[get post patch put delete head].each do |method|
|
55
73
|
define_method method do |url = '', **opts, &block|
|
56
74
|
fire(url, opts.reverse_merge(method: method, &block))
|
57
75
|
end
|
@@ -31,7 +31,7 @@ module ClientDsl
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def default_request_options
|
34
|
-
@default_request_options ||= (defaults.request_options ||
|
34
|
+
@default_request_options ||= (defaults.request_options || ActiveSupport::HashWithIndifferentAccess.new)
|
35
35
|
end
|
36
36
|
|
37
37
|
def register_response_handler(handler = nil, &block)
|
data/nxt_http_client.gemspec
CHANGED
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.1.
|
4
|
+
version: 0.1.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-
|
14
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|
@@ -139,6 +139,20 @@ dependencies:
|
|
139
139
|
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: redis
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
type: :development
|
150
|
+
prerelease: false
|
151
|
+
version_requirements: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
142
156
|
description: NxtHttpClinet allows you to easily create and configure http clients.
|
143
157
|
email:
|
144
158
|
- a.robecke@getsafe.de
|