http_store 0.3.26 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +83 -67
- data/db/migrate/3_add_retry_times_field_to_http_log.rb +5 -0
- data/lib/http_store.rb +1 -1
- data/lib/http_store/client.rb +15 -7
- data/lib/http_store/configuration.rb +5 -1
- data/lib/http_store/helpers/responseable.rb +4 -0
- data/lib/http_store/helpers/storable.rb +7 -5
- data/lib/http_store/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '095768d03abf8ec3126756076df29cf53ebeb58747c9c5be1f69f9e5e4b92f6a'
|
4
|
+
data.tar.gz: 3601807df78cfb7d04e62b79dc56dd80206836663a7fb22d2f34c83c488671d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce691e99ee9e448ee72e3a21748266605c9da44289e0e0750c1d235c51a7222348ae2549914d2ed9979464b1defd57171efeca53d8b908de8c40028f67fb061c
|
7
|
+
data.tar.gz: 6e514460d70567b4c37dd24bdf7ccbb4a004b7ee06cbdb278d6783e98284b0af0346ec2ddfc89c0f65cb14ed82b8a58f5af4ec85c9e0b1aaf1d5201cf50abc15
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
http_store (0.3
|
4
|
+
http_store (0.5.3)
|
5
5
|
activerecord (>= 5.0, < 6.1)
|
6
6
|
hashie (~> 3.0)
|
7
7
|
rails (>= 5, < 7)
|
@@ -10,110 +10,125 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (
|
14
|
-
actionpack (=
|
13
|
+
actioncable (6.0.3.3)
|
14
|
+
actionpack (= 6.0.3.3)
|
15
15
|
nio4r (~> 2.0)
|
16
16
|
websocket-driver (>= 0.6.1)
|
17
|
-
|
18
|
-
actionpack (=
|
19
|
-
|
20
|
-
|
17
|
+
actionmailbox (6.0.3.3)
|
18
|
+
actionpack (= 6.0.3.3)
|
19
|
+
activejob (= 6.0.3.3)
|
20
|
+
activerecord (= 6.0.3.3)
|
21
|
+
activestorage (= 6.0.3.3)
|
22
|
+
activesupport (= 6.0.3.3)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.0.3.3)
|
25
|
+
actionpack (= 6.0.3.3)
|
26
|
+
actionview (= 6.0.3.3)
|
27
|
+
activejob (= 6.0.3.3)
|
21
28
|
mail (~> 2.5, >= 2.5.4)
|
22
29
|
rails-dom-testing (~> 2.0)
|
23
|
-
actionpack (
|
24
|
-
actionview (=
|
25
|
-
activesupport (=
|
26
|
-
rack (~> 2.0)
|
30
|
+
actionpack (6.0.3.3)
|
31
|
+
actionview (= 6.0.3.3)
|
32
|
+
activesupport (= 6.0.3.3)
|
33
|
+
rack (~> 2.0, >= 2.0.8)
|
27
34
|
rack-test (>= 0.6.3)
|
28
35
|
rails-dom-testing (~> 2.0)
|
29
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
30
|
-
|
31
|
-
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
+
actiontext (6.0.3.3)
|
38
|
+
actionpack (= 6.0.3.3)
|
39
|
+
activerecord (= 6.0.3.3)
|
40
|
+
activestorage (= 6.0.3.3)
|
41
|
+
activesupport (= 6.0.3.3)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (6.0.3.3)
|
44
|
+
activesupport (= 6.0.3.3)
|
32
45
|
builder (~> 3.1)
|
33
46
|
erubi (~> 1.4)
|
34
47
|
rails-dom-testing (~> 2.0)
|
35
|
-
rails-html-sanitizer (~> 1.
|
36
|
-
activejob (
|
37
|
-
activesupport (=
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (6.0.3.3)
|
50
|
+
activesupport (= 6.0.3.3)
|
38
51
|
globalid (>= 0.3.6)
|
39
|
-
activemodel (
|
40
|
-
activesupport (=
|
41
|
-
activerecord (
|
42
|
-
activemodel (=
|
43
|
-
activesupport (=
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
activerecord (=
|
52
|
+
activemodel (6.0.3.3)
|
53
|
+
activesupport (= 6.0.3.3)
|
54
|
+
activerecord (6.0.3.3)
|
55
|
+
activemodel (= 6.0.3.3)
|
56
|
+
activesupport (= 6.0.3.3)
|
57
|
+
activestorage (6.0.3.3)
|
58
|
+
actionpack (= 6.0.3.3)
|
59
|
+
activejob (= 6.0.3.3)
|
60
|
+
activerecord (= 6.0.3.3)
|
48
61
|
marcel (~> 0.3.1)
|
49
|
-
activesupport (
|
62
|
+
activesupport (6.0.3.3)
|
50
63
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
51
64
|
i18n (>= 0.7, < 2)
|
52
65
|
minitest (~> 5.1)
|
53
66
|
tzinfo (~> 1.1)
|
54
|
-
|
55
|
-
builder (3.2.
|
67
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
68
|
+
builder (3.2.4)
|
56
69
|
byebug (11.0.1)
|
57
|
-
concurrent-ruby (1.1.
|
58
|
-
crass (1.0.
|
70
|
+
concurrent-ruby (1.1.7)
|
71
|
+
crass (1.0.6)
|
59
72
|
diff-lcs (1.3)
|
60
73
|
domain_name (0.5.20190701)
|
61
74
|
unf (>= 0.0.5, < 1.0.0)
|
62
|
-
erubi (1.
|
75
|
+
erubi (1.9.0)
|
63
76
|
globalid (0.4.2)
|
64
77
|
activesupport (>= 4.2.0)
|
65
78
|
hashie (3.6.0)
|
66
79
|
http-accept (1.7.0)
|
67
80
|
http-cookie (1.0.3)
|
68
81
|
domain_name (~> 0.5)
|
69
|
-
i18n (1.
|
82
|
+
i18n (1.8.5)
|
70
83
|
concurrent-ruby (~> 1.0)
|
71
|
-
loofah (2.
|
84
|
+
loofah (2.7.0)
|
72
85
|
crass (~> 1.0.2)
|
73
86
|
nokogiri (>= 1.5.9)
|
74
87
|
mail (2.7.1)
|
75
88
|
mini_mime (>= 0.1.1)
|
76
89
|
marcel (0.3.3)
|
77
90
|
mimemagic (~> 0.3.2)
|
78
|
-
method_source (0.
|
79
|
-
mime-types (3.3)
|
91
|
+
method_source (1.0.0)
|
92
|
+
mime-types (3.3.1)
|
80
93
|
mime-types-data (~> 3.2015)
|
81
|
-
mime-types-data (3.
|
82
|
-
mimemagic (0.3.
|
94
|
+
mime-types-data (3.2020.0512)
|
95
|
+
mimemagic (0.3.5)
|
83
96
|
mini_mime (1.0.2)
|
84
97
|
mini_portile2 (2.4.0)
|
85
|
-
minitest (5.
|
98
|
+
minitest (5.14.2)
|
86
99
|
netrc (0.11.0)
|
87
|
-
nio4r (2.5.
|
88
|
-
nokogiri (1.10.
|
100
|
+
nio4r (2.5.4)
|
101
|
+
nokogiri (1.10.10)
|
89
102
|
mini_portile2 (~> 2.4.0)
|
90
|
-
rack (2.
|
103
|
+
rack (2.2.3)
|
91
104
|
rack-test (1.1.0)
|
92
105
|
rack (>= 1.0, < 3)
|
93
|
-
rails (
|
94
|
-
actioncable (=
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
106
|
+
rails (6.0.3.3)
|
107
|
+
actioncable (= 6.0.3.3)
|
108
|
+
actionmailbox (= 6.0.3.3)
|
109
|
+
actionmailer (= 6.0.3.3)
|
110
|
+
actionpack (= 6.0.3.3)
|
111
|
+
actiontext (= 6.0.3.3)
|
112
|
+
actionview (= 6.0.3.3)
|
113
|
+
activejob (= 6.0.3.3)
|
114
|
+
activemodel (= 6.0.3.3)
|
115
|
+
activerecord (= 6.0.3.3)
|
116
|
+
activestorage (= 6.0.3.3)
|
117
|
+
activesupport (= 6.0.3.3)
|
103
118
|
bundler (>= 1.3.0)
|
104
|
-
railties (=
|
119
|
+
railties (= 6.0.3.3)
|
105
120
|
sprockets-rails (>= 2.0.0)
|
106
121
|
rails-dom-testing (2.0.3)
|
107
122
|
activesupport (>= 4.2.0)
|
108
123
|
nokogiri (>= 1.6)
|
109
|
-
rails-html-sanitizer (1.
|
110
|
-
loofah (~> 2.
|
111
|
-
railties (
|
112
|
-
actionpack (=
|
113
|
-
activesupport (=
|
124
|
+
rails-html-sanitizer (1.3.0)
|
125
|
+
loofah (~> 2.3)
|
126
|
+
railties (6.0.3.3)
|
127
|
+
actionpack (= 6.0.3.3)
|
128
|
+
activesupport (= 6.0.3.3)
|
114
129
|
method_source
|
115
130
|
rake (>= 0.8.7)
|
116
|
-
thor (>= 0.
|
131
|
+
thor (>= 0.20.3, < 2.0)
|
117
132
|
rake (10.5.0)
|
118
133
|
rest-client (2.1.0)
|
119
134
|
http-accept (>= 1.7.0, < 2.0)
|
@@ -133,23 +148,24 @@ GEM
|
|
133
148
|
diff-lcs (>= 1.2.0, < 2.0)
|
134
149
|
rspec-support (~> 3.8.0)
|
135
150
|
rspec-support (3.8.2)
|
136
|
-
sprockets (
|
151
|
+
sprockets (4.0.2)
|
137
152
|
concurrent-ruby (~> 1.0)
|
138
153
|
rack (> 1, < 3)
|
139
|
-
sprockets-rails (3.2.
|
154
|
+
sprockets-rails (3.2.2)
|
140
155
|
actionpack (>= 4.0)
|
141
156
|
activesupport (>= 4.0)
|
142
157
|
sprockets (>= 3.0.0)
|
143
|
-
thor (0.
|
158
|
+
thor (1.0.1)
|
144
159
|
thread_safe (0.3.6)
|
145
|
-
tzinfo (1.2.
|
160
|
+
tzinfo (1.2.7)
|
146
161
|
thread_safe (~> 0.1)
|
147
162
|
unf (0.1.4)
|
148
163
|
unf_ext
|
149
|
-
unf_ext (0.0.7.
|
150
|
-
websocket-driver (0.7.
|
164
|
+
unf_ext (0.0.7.7)
|
165
|
+
websocket-driver (0.7.3)
|
151
166
|
websocket-extensions (>= 0.1.0)
|
152
|
-
websocket-extensions (0.1.
|
167
|
+
websocket-extensions (0.1.5)
|
168
|
+
zeitwerk (2.4.0)
|
153
169
|
|
154
170
|
PLATFORMS
|
155
171
|
ruby
|
@@ -162,4 +178,4 @@ DEPENDENCIES
|
|
162
178
|
rspec (~> 3.0)
|
163
179
|
|
164
180
|
BUNDLED WITH
|
165
|
-
2.
|
181
|
+
2.1.4
|
data/lib/http_store.rb
CHANGED
@@ -8,7 +8,7 @@ require 'http_store/engine'
|
|
8
8
|
module HttpStore
|
9
9
|
extend ActiveSupport::Autoload
|
10
10
|
|
11
|
-
REQUEST_KEYS = %w[http_method url data_type headers query_params data other_params force request_valid]
|
11
|
+
REQUEST_KEYS = %w[http_method url data_type headers query_params data other_params force request_valid retry_times]
|
12
12
|
RESPONSE_KEYS = %w[status_code response response_headers response_data response_valid response_code cache_response]
|
13
13
|
META_KEYS = %w[request_digest client_type parent_id requestable_id requestable_type]
|
14
14
|
TMP_KEYS = %w[requestable response_obj]
|
data/lib/http_store/client.rb
CHANGED
@@ -15,17 +15,19 @@ module HttpStore
|
|
15
15
|
build_request
|
16
16
|
|
17
17
|
return unless request_valid?
|
18
|
-
|
19
|
-
# exist request or not force, return
|
20
18
|
load_storeable_record and return if use_cache?
|
21
19
|
|
22
20
|
execute # send request
|
23
|
-
|
21
|
+
retry! while need_retry? && retry_times.to_i > 0
|
24
22
|
|
25
|
-
build_response
|
26
23
|
after_response
|
27
|
-
|
28
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def retry!
|
27
|
+
@meta.retry_times = retry_times.to_i - 1
|
28
|
+
@meta.force = true
|
29
|
+
|
30
|
+
execute
|
29
31
|
end
|
30
32
|
|
31
33
|
HttpStore::ALL_KEYS.each do |meta_key|
|
@@ -47,6 +49,11 @@ module HttpStore
|
|
47
49
|
|
48
50
|
def execute
|
49
51
|
@meta.response_obj = get? ? http_get_execute : http_post_execute
|
52
|
+
raise HttpStore::RequestError, 'response_obj is nil' if response_obj.nil?
|
53
|
+
|
54
|
+
build_response
|
55
|
+
ensure
|
56
|
+
store_request
|
50
57
|
end
|
51
58
|
|
52
59
|
def http_get_execute
|
@@ -59,7 +66,8 @@ module HttpStore
|
|
59
66
|
|
60
67
|
def http_post_execute
|
61
68
|
real_data = json_request? ? data.to_json : data.to_hash
|
62
|
-
RestClient.post(uri, real_data, headers.symbolize_keys)
|
69
|
+
# RestClient.post(uri, real_data, headers.symbolize_keys)
|
70
|
+
RestClient::Request.execute(method: :post, url: url, payload: real_data, headers: headers.symbolize_keys, verify_ssl: false)
|
63
71
|
rescue RestClient::ExceptionWithResponse => e
|
64
72
|
# :nocov:
|
65
73
|
e.response
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module HttpStore
|
2
2
|
class Configuration
|
3
|
-
attr_writer :store_enable, :store_class
|
3
|
+
attr_writer :store_enable, :store_class, :store_time
|
4
4
|
|
5
5
|
def store_enable
|
6
6
|
@store_enable || true
|
@@ -9,5 +9,9 @@ module HttpStore
|
|
9
9
|
def store_class
|
10
10
|
@store_class || HttpStore::HttpLog
|
11
11
|
end
|
12
|
+
|
13
|
+
def store_time
|
14
|
+
@store_time || 31_536_000
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module HttpStore
|
2
2
|
module Helpers
|
3
3
|
module Storable
|
4
|
-
STRING_LIMIT_SIZE =
|
4
|
+
STRING_LIMIT_SIZE = 1000
|
5
|
+
TEXT_LIMIT_SIZE = 10000
|
5
6
|
|
6
7
|
def storeable_record
|
7
8
|
return unless HttpStore.config.store_enable
|
8
9
|
|
9
|
-
|
10
|
+
expired_time = Time.current - HttpStore.config.store_time
|
11
|
+
@storeable_record ||= HttpStore.config.store_class.where('created_at > ?', expired_time).where(request_digest: @meta.request_digest, cache_response: true).order(id: :desc).first
|
10
12
|
end
|
11
13
|
|
12
14
|
def load_storeable_record
|
@@ -39,11 +41,11 @@ module HttpStore
|
|
39
41
|
storable_v = storable(v)
|
40
42
|
|
41
43
|
begin
|
42
|
-
storable_v = storable_v.to_json[0..
|
44
|
+
storable_v = storable_v.to_json[0..TEXT_LIMIT_SIZE] if v.is_a?(Hash) || v.is_a?(Array)
|
43
45
|
|
44
46
|
[k, storable_v]
|
45
47
|
rescue JSON::GeneratorError
|
46
|
-
[k, storable_v.to_s[0..
|
48
|
+
[k, storable_v.to_s[0..TEXT_LIMIT_SIZE]]
|
47
49
|
end
|
48
50
|
end.to_h
|
49
51
|
end
|
@@ -69,7 +71,7 @@ module HttpStore
|
|
69
71
|
raise EncodingError unless str.encoding.name == 'UTF-8'
|
70
72
|
raise EncodingError unless str.valid_encoding?
|
71
73
|
|
72
|
-
str.length > STRING_LIMIT_SIZE ? { digest: Digest::SHA1.hexdigest(str), origin: str[0..
|
74
|
+
str.length > STRING_LIMIT_SIZE ? { digest: Digest::SHA1.hexdigest(str), origin: str[0..STRING_LIMIT_SIZE] } : str
|
73
75
|
rescue EncodingError
|
74
76
|
{ digest: Digest::SHA1.hexdigest(str) }
|
75
77
|
end
|
data/lib/http_store/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- black
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- bin/setup
|
154
154
|
- db/migrate/1_create_http_logs.rb
|
155
155
|
- db/migrate/2_add_cache_response_field_to_http_log.rb
|
156
|
+
- db/migrate/3_add_retry_times_field_to_http_log.rb
|
156
157
|
- http_store.gemspec
|
157
158
|
- lib/generators/http_store/initializer_generator.rb
|
158
159
|
- lib/http_store.rb
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
- !ruby/object:Gem::Version
|
187
188
|
version: '0'
|
188
189
|
requirements: []
|
189
|
-
rubygems_version: 3.0.
|
190
|
+
rubygems_version: 3.0.8
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
193
|
summary: store the http request, it based on rest-client
|