scorn 0.4.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bedbc6554c2cd5389e7d02371797bf45ab92660e5e25e4baa3bacd9a32035ca
4
- data.tar.gz: b24b770e64ae7365585cd99df1a56834f9d4d7755d66bc1ade51b38b076ed56f
3
+ metadata.gz: 7bb1a6d83e869832d0a50be04f08b25c4ce7022ad94fe07e34fd4cdba5844eec
4
+ data.tar.gz: 9439039ffee263c9f3e235e80463f6e270451968e07bb6b16fac783addcf17c8
5
5
  SHA512:
6
- metadata.gz: 4fd97916ebb14977ade4e8c692aa3e4a9037a67a29d263ac40339a6196baeef1a9b311fe51aea4af56ce4c0c1e675b6e2c5e855a3887e19c51981a8a0733c920
7
- data.tar.gz: fcf050769e5b0f5ee946fbc3dff12ac6180ec7293969cd435159140a3359592c0d1faeb5e57e8efb4729311ae5be3577346fa4824b18ef3452176a93eb107f98
6
+ metadata.gz: 3389ec427a18e89472bbd822fa2b89f5b279fd11cc929c4e35d5f88eb90ca9dea7f4372d6701a258da67cacfd9a91b739156adcf3322bc256304846dfe51de10
7
+ data.tar.gz: b19d98b315a0790c192bff0f44af6ed5431badfccdf9cc61312d557ddcde7ce54d2a65d35c736845d96110f366dcda85a0d5f181240c6ba1921d48e01a650d8c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## scorn 0.5.0 released 2026-10-10
6
+
7
+ * Accept `x_foobar_header: 'hello'`
8
+ * `r._response._request._headers`
9
+ * Implement :etag/:if_none_match opt
10
+
11
+
12
+ ## scorn 0.4.1 released 2026-09-02
13
+
14
+ * Tidy dependencies
15
+
16
+
5
17
  ## scorn 0.4.0 released 2025-08-01
6
18
 
7
19
  * Parse "[]" JSON arrays too
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2021-2025, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2021-2026, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # scorn
3
3
 
4
- [![tests](https://github.com/jmettraux/scorn/workflows/test/badge.svg)](https://github.com/jmettraux/scorn/actions)
4
+ <!--[![tests](https://github.com/jmettraux/scorn/workflows/test/badge.svg)](https://github.com/jmettraux/scorn/actions)-->
5
5
  [![gem version](https://badge.fury.io/rb/scorn.svg)](http://badge.fury.io/rb/scorn)
6
6
 
7
7
  A stupid HTTP client library.
@@ -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.4.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
- h[k] = v if k.start_with?(/X-/)
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 = WEBrick::HTTPStatus.reason_phrase(res.code) rescue ''
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
@@ -22,24 +22,25 @@ A stupid HTTP client library. Consider with scorn.
22
22
  'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
23
23
  'documentation_uri' => s.homepage,
24
24
  'bug_tracker_uri' => s.homepage + '/issues',
25
- #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
26
25
  'homepage_uri' => s.homepage,
27
26
  'source_code_uri' => s.homepage,
27
+ #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
28
28
  #'wiki_uri' => s.homepage + '/wiki',
29
+ 'rubygems_mfa_required' => 'true',
29
30
  }
30
31
 
31
32
  #s.files = `git ls-files`.split("\n")
32
33
  s.files = Dir[
33
- 'README.{md,txt}',
34
- 'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
35
- 'Makefile',
34
+ '{README,CHANGELOG,CREDITS,LICENSE}.{md,txt}',
35
+ #'Makefile',
36
36
  'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
37
37
  "#{s.name}.gemspec",
38
38
  ]
39
39
 
40
- #s.add_runtime_dependency 'raabro', '~> 1.4'
40
+ s.add_runtime_dependency 'base64'
41
+ s.add_runtime_dependency 'ostruct'
41
42
 
42
- s.add_development_dependency 'rspec', '~> 3.8'
43
+ s.add_development_dependency 'probatio', '~> 1.6'
43
44
 
44
45
  s.require_path = 'lib'
45
46
  end
metadata CHANGED
@@ -1,28 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: rspec
13
+ name: base64
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ostruct
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
+ - !ruby/object:Gem::Dependency
41
+ name: probatio
14
42
  requirement: !ruby/object:Gem::Requirement
15
43
  requirements:
16
44
  - - "~>"
17
45
  - !ruby/object:Gem::Version
18
- version: '3.8'
46
+ version: '1.6'
19
47
  type: :development
20
48
  prerelease: false
21
49
  version_requirements: !ruby/object:Gem::Requirement
22
50
  requirements:
23
51
  - - "~>"
24
52
  - !ruby/object:Gem::Version
25
- version: '3.8'
53
+ version: '1.6'
26
54
  description: A stupid HTTP client library. Consider with scorn.
27
55
  email:
28
56
  - jmettraux@gmail.com
@@ -33,7 +61,6 @@ files:
33
61
  - CHANGELOG.md
34
62
  - CREDITS.md
35
63
  - LICENSE.txt
36
- - Makefile
37
64
  - README.md
38
65
  - lib/scorn.rb
39
66
  - scorn.gemspec
@@ -46,6 +73,7 @@ metadata:
46
73
  bug_tracker_uri: https://github.com/jmettraux/scorn/issues
47
74
  homepage_uri: https://github.com/jmettraux/scorn
48
75
  source_code_uri: https://github.com/jmettraux/scorn
76
+ rubygems_mfa_required: 'true'
49
77
  rdoc_options: []
50
78
  require_paths:
51
79
  - lib
@@ -60,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
90
  requirements: []
63
- rubygems_version: 3.6.2
91
+ rubygems_version: 3.6.9
64
92
  specification_version: 4
65
93
  summary: stupid HTTP client
66
94
  test_files: []
data/Makefile DELETED
@@ -1,45 +0,0 @@
1
-
2
- ## gem tasks ##
3
-
4
- NAME != \
5
- ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name"
6
- VERSION != \
7
- ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version"
8
-
9
- count_lines:
10
- find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
11
- find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
12
- cl: count_lines
13
-
14
- scan:
15
- scan lib/**/*.rb
16
-
17
- gemspec_validate:
18
- @echo "---"
19
- ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
20
- @echo "---"
21
-
22
- name: gemspec_validate
23
- @echo "$(NAME) $(VERSION)"
24
-
25
- cw:
26
- find lib -name "*.rb" -exec ruby -cw {} \;
27
-
28
- build: gemspec_validate
29
- gem build $(NAME).gemspec
30
- mkdir -p pkg
31
- mv $(NAME)-$(VERSION).gem pkg/
32
-
33
- push: build
34
- gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
35
-
36
- spec:
37
- bundle exec rspec
38
- test: spec
39
-
40
-
41
- ## specific to project ##
42
-
43
-
44
- .PHONY: count_lines scan gemspec_validate name cw build push spec
45
-