twingly-http 0.3.2 → 0.4.0
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/lib/twingly/http.rb +58 -8
- data/lib/twingly/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: 573e3beb22fd03c1961fe5b6264b3a2b1ef9f0a5a89b95e0094e1693e76dff7f
|
4
|
+
data.tar.gz: 30a0dda321f1a3804492fd91e49907456cd3e45494f79ff571c054b648f7725c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d209c54bbd796f27d38796d6a5449cf961e7de9a351700098ba92f022502a34950dc7652c4c9d16f80d9ae7474fe65bd6d3a60976cf43db65f767d5fb97277e
|
7
|
+
data.tar.gz: 6e4db092c8893e0539b17af90233d9ac86f2bbb2f51a2ab3b29fbd7c671211861168e30b434b4abdbf209c332861292a71bee37cb47fe4a91f3623b14f67a21f
|
data/lib/twingly/http.rb
CHANGED
@@ -61,6 +61,18 @@ module Twingly
|
|
61
61
|
http_response_for(:post, url: url, body: body, headers: headers)
|
62
62
|
end
|
63
63
|
|
64
|
+
def put(url, body:, headers: {})
|
65
|
+
http_response_for(:put, url: url, body: body, headers: headers)
|
66
|
+
end
|
67
|
+
|
68
|
+
def patch(url, body:, headers: {})
|
69
|
+
http_response_for(:patch, url: url, body: body, headers: headers)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete(url, params: {}, headers: {})
|
73
|
+
http_response_for(:delete, url: url, params: params, headers: headers)
|
74
|
+
end
|
75
|
+
|
64
76
|
private
|
65
77
|
|
66
78
|
def default_logger
|
@@ -80,14 +92,8 @@ module Twingly
|
|
80
92
|
@max_url_size_bytes = DEFAULT_MAX_URL_SIZE_BYTES
|
81
93
|
end
|
82
94
|
|
83
|
-
# rubocop:disable Metrics/MethodLength
|
84
95
|
def http_response_for(method, **args)
|
85
|
-
response =
|
86
|
-
when :get
|
87
|
-
http_get_response(**args)
|
88
|
-
when :post
|
89
|
-
http_post_response(**args)
|
90
|
-
end
|
96
|
+
response = send("http_#{method}_response", **args)
|
91
97
|
|
92
98
|
Response.new(headers: response.headers.to_h,
|
93
99
|
status: response.status,
|
@@ -99,7 +105,6 @@ module Twingly
|
|
99
105
|
rescue FaradayMiddleware::RedirectLimitReached => error
|
100
106
|
raise RedirectLimitReachedError, error.message
|
101
107
|
end
|
102
|
-
# rubocop:enable all
|
103
108
|
|
104
109
|
def http_get_response(url:, params:, headers:)
|
105
110
|
binary_url = url.dup.force_encoding(Encoding::BINARY)
|
@@ -131,6 +136,51 @@ module Twingly
|
|
131
136
|
end
|
132
137
|
end
|
133
138
|
|
139
|
+
def http_put_response(url:, body:, headers:)
|
140
|
+
binary_url = url.dup.force_encoding(Encoding::BINARY)
|
141
|
+
http_client = create_http_client
|
142
|
+
|
143
|
+
headers = default_headers.merge(headers)
|
144
|
+
|
145
|
+
http_client.put do |request|
|
146
|
+
request.url(binary_url)
|
147
|
+
request.headers.merge!(headers)
|
148
|
+
request.body = body
|
149
|
+
request.options.timeout = @http_timeout
|
150
|
+
request.options.open_timeout = @http_open_timeout
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def http_patch_response(url:, body:, headers:)
|
155
|
+
binary_url = url.dup.force_encoding(Encoding::BINARY)
|
156
|
+
http_client = create_http_client
|
157
|
+
|
158
|
+
headers = default_headers.merge(headers)
|
159
|
+
|
160
|
+
http_client.patch do |request|
|
161
|
+
request.url(binary_url)
|
162
|
+
request.headers.merge!(headers)
|
163
|
+
request.body = body
|
164
|
+
request.options.timeout = @http_timeout
|
165
|
+
request.options.open_timeout = @http_open_timeout
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def http_delete_response(url:, params:, headers:)
|
170
|
+
binary_url = url.dup.force_encoding(Encoding::BINARY)
|
171
|
+
http_client = create_http_client
|
172
|
+
|
173
|
+
headers = default_headers.merge(headers)
|
174
|
+
|
175
|
+
http_client.delete do |request|
|
176
|
+
request.url(binary_url)
|
177
|
+
request.params.merge!(params)
|
178
|
+
request.headers.merge!(headers)
|
179
|
+
request.options.timeout = @http_timeout
|
180
|
+
request.options.open_timeout = @http_open_timeout
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
134
184
|
def create_http_client # rubocop:disable Metrics/MethodLength
|
135
185
|
Faraday.new do |faraday|
|
136
186
|
faraday.request :url_size_limit,
|
data/lib/twingly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|