scorn 0.4.1 → 0.5.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/CHANGELOG.md +7 -0
- data/README.md +20 -0
- data/lib/scorn.rb +50 -4
- data/scorn.gemspec +0 -1
- metadata +1 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bb1a6d83e869832d0a50be04f08b25c4ce7022ad94fe07e34fd4cdba5844eec
|
|
4
|
+
data.tar.gz: 9439039ffee263c9f3e235e80463f6e270451968e07bb6b16fac783addcf17c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3389ec427a18e89472bbd822fa2b89f5b279fd11cc929c4e35d5f88eb90ca9dea7f4372d6701a258da67cacfd9a91b739156adcf3322bc256304846dfe51de10
|
|
7
|
+
data.tar.gz: b19d98b315a0790c192bff0f44af6ed5431badfccdf9cc61312d557ddcde7ce54d2a65d35c736845d96110f366dcda85a0d5f181240c6ba1921d48e01a650d8c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -9,6 +9,7 @@ A stupid HTTP client library.
|
|
|
9
9
|
```ruby
|
|
10
10
|
r = Scorn.get('https://example.com/data.json')
|
|
11
11
|
|
|
12
|
+
p r # => { "data" => [ "foo", "bar" ] }
|
|
12
13
|
p r._response._c # => 200
|
|
13
14
|
```
|
|
14
15
|
|
|
@@ -37,6 +38,25 @@ p r['form'] # => { 'n' => '-1', 'source' => 'src', 'target' => 'tgt' }
|
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
|
|
41
|
+
### Options:
|
|
42
|
+
|
|
43
|
+
* `accept:` for the `Accept` header
|
|
44
|
+
* `uauthorization:` or `auth:` for the `Authorization` header
|
|
45
|
+
* `content_type:` for the `Content-Type` header
|
|
46
|
+
* `etag:` or `if_none_match:` for the `If-None-Match` header
|
|
47
|
+
* `user_agent:` for the `Agent` header
|
|
48
|
+
* `ssl_verify: false`, `ssl_verify: :none`, `verify: false`, as expected
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
r = Scorn.get(
|
|
52
|
+
'https://httpbin.org/get',
|
|
53
|
+
auth: 'Bearer toto-nada-xplus',
|
|
54
|
+
json: true)
|
|
55
|
+
|
|
56
|
+
p r['headers']['Authorization'] # => 'Bearer toto-nada-xplus'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
40
60
|
## LICENSE
|
|
41
61
|
|
|
42
62
|
MIT, see [LICENSE.txt](LICENSE.txt)
|
data/lib/scorn.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
|
|
2
|
+
# scorn.rb
|
|
3
|
+
|
|
2
4
|
require 'json'
|
|
3
5
|
require 'time'
|
|
4
6
|
require 'base64'
|
|
5
|
-
require 'webrick' # for the http code to message mapping
|
|
6
7
|
require 'ostruct'
|
|
7
8
|
require 'openssl'
|
|
8
9
|
require 'net/http'
|
|
@@ -10,7 +11,7 @@ require 'net/http'
|
|
|
10
11
|
|
|
11
12
|
module Scorn
|
|
12
13
|
|
|
13
|
-
VERSION = '0.
|
|
14
|
+
VERSION = '0.5.0'.freeze
|
|
14
15
|
|
|
15
16
|
class << self
|
|
16
17
|
|
|
@@ -118,8 +119,13 @@ module Scorn
|
|
|
118
119
|
opts[:content_type] || 'application/x-www-form-urlencoded' \
|
|
119
120
|
if verb == :post
|
|
120
121
|
|
|
122
|
+
h['If-None-Match'] =
|
|
123
|
+
opts[:etag] || opts[:if_none_match] \
|
|
124
|
+
if verb == :get || verb == :head
|
|
125
|
+
|
|
121
126
|
opts.each do |k, v|
|
|
122
|
-
|
|
127
|
+
k = k.to_s.gsub('_', '-')
|
|
128
|
+
h[k] = v if k.start_with?(/x-/i)
|
|
123
129
|
end
|
|
124
130
|
|
|
125
131
|
h.compact!
|
|
@@ -142,6 +148,10 @@ module Scorn
|
|
|
142
148
|
|
|
143
149
|
headers.each { |k, v| req[k] = v }
|
|
144
150
|
|
|
151
|
+
class << req
|
|
152
|
+
def _headers; each_header.inject({}) { |h, (k, v)| h[k] = v; h }; end
|
|
153
|
+
end
|
|
154
|
+
|
|
145
155
|
req
|
|
146
156
|
end
|
|
147
157
|
|
|
@@ -163,7 +173,7 @@ module Scorn
|
|
|
163
173
|
res._uri = uri
|
|
164
174
|
res._request = req
|
|
165
175
|
res._c = res.code.to_i
|
|
166
|
-
res._sta =
|
|
176
|
+
res._sta = STATUS_CODES[res._c] || ''
|
|
167
177
|
res._elapsed = monow - t0
|
|
168
178
|
#res._proxy = detail_proxy(http)
|
|
169
179
|
|
|
@@ -208,6 +218,42 @@ module Scorn
|
|
|
208
218
|
|
|
209
219
|
r
|
|
210
220
|
end
|
|
221
|
+
|
|
222
|
+
# https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv
|
|
223
|
+
#
|
|
224
|
+
STATUS_CODES = {
|
|
225
|
+
|
|
226
|
+
100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing',
|
|
227
|
+
|
|
228
|
+
200 => 'OK', 201 => 'Created', 202 => 'Accepted',
|
|
229
|
+
203 => 'Non-Authoritative Information',
|
|
230
|
+
204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
|
|
231
|
+
207 => 'Multi-Status', 208 => 'Already Reported', 226 => 'IM Used',
|
|
232
|
+
|
|
233
|
+
300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found',
|
|
234
|
+
303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy',
|
|
235
|
+
307 => 'Temporary Redirect', 308 => 'Permanent Redirect',
|
|
236
|
+
|
|
237
|
+
400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required',
|
|
238
|
+
403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed',
|
|
239
|
+
406 => 'Not Acceptable', 407 => 'Proxy Authentication Required',
|
|
240
|
+
408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone',
|
|
241
|
+
411 => 'Length Required', 412 => 'Precondition Failed',
|
|
242
|
+
413 => 'Payload Too Large', 414 => 'URI Too Long',
|
|
243
|
+
415 => 'Unsupported Media Type', 416 => 'Range Not Satisfiable',
|
|
244
|
+
417 => 'Expectation Failed', 422 => 'Unprocessable Entity',
|
|
245
|
+
423 => 'Locked', 424 => 'Failed Dependency', 426 => 'Upgrade Required',
|
|
246
|
+
428 => 'Precondition Required', 429 => 'Too Many Requests',
|
|
247
|
+
431 => 'Request Header Fields Too Large',
|
|
248
|
+
|
|
249
|
+
500 => 'Internal Server Error', 501 => 'Not Implemented',
|
|
250
|
+
502 => 'Bad Gateway', 503 => 'Service Unavailable',
|
|
251
|
+
504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported',
|
|
252
|
+
506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage',
|
|
253
|
+
508 => 'Loop Detected', 510 => 'Not Extended',
|
|
254
|
+
511 => 'Network Authentication Required'
|
|
255
|
+
|
|
256
|
+
}.freeze
|
|
211
257
|
end
|
|
212
258
|
end
|
|
213
259
|
|
data/scorn.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: scorn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Mettraux
|
|
@@ -23,20 +23,6 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: webrick
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
26
|
- !ruby/object:Gem::Dependency
|
|
41
27
|
name: ostruct
|
|
42
28
|
requirement: !ruby/object:Gem::Requirement
|