scorn 0.3.1 → 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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE.txt +1 -1
  4. data/Makefile +4 -4
  5. data/lib/scorn.rb +60 -27
  6. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cebb2eff53282bd30d083de64a8ed4ed2beba5fe05b6b61d2faf2c32dea4ed91
4
- data.tar.gz: bfd2381a856f11c5ebe4f278a25d207b76ef1ab5415ac2c448e68f5766c259ec
3
+ metadata.gz: 0bedbc6554c2cd5389e7d02371797bf45ab92660e5e25e4baa3bacd9a32035ca
4
+ data.tar.gz: b24b770e64ae7365585cd99df1a56834f9d4d7755d66bc1ade51b38b076ed56f
5
5
  SHA512:
6
- metadata.gz: 45151e4ce0f25e4213d6fdd645bf09ce93df55f1a5bbe9036927884cbe555fc45189a3fa0b0724efc8520eded294944e38d76395cf05bcc07ff52276c33049a5
7
- data.tar.gz: 1523769e1a4bf6efa6132d0e3c9bedb81cb7580c28d48918f226cdc5ca73c128937440df6fbafb7ce468fd10b3127cdbdaadf2080442e3b23bdd25128c30cdbd
6
+ metadata.gz: 4fd97916ebb14977ade4e8c692aa3e4a9037a67a29d263ac40339a6196baeef1a9b311fe51aea4af56ce4c0c1e675b6e2c5e855a3887e19c51981a8a0733c920
7
+ data.tar.gz: fcf050769e5b0f5ee946fbc3dff12ac6180ec7293969cd435159140a3359592c0d1faeb5e57e8efb4729311ae5be3577346fa4824b18ef3452176a93eb107f98
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## scorn 0.4.0 released 2025-08-01
6
+
7
+ * Parse "[]" JSON arrays too
8
+ * Accept :auth or :authentication
9
+ * Fix :verify or :ssl_verify client option
10
+ * Add HEAD requests
11
+
12
+
5
13
  ## scorn 0.3.1 released 2021-01-12
6
14
 
7
15
  * Fix duplicate Content-Type headers when POSTing
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2021-2021, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2021-2025, 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/Makefile CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
2
  ## gem tasks ##
3
3
 
4
- NAME = \
5
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
6
- VERSION = \
7
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
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
8
 
9
9
  count_lines:
10
10
  find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
data/lib/scorn.rb CHANGED
@@ -10,10 +10,15 @@ require 'net/http'
10
10
 
11
11
  module Scorn
12
12
 
13
- VERSION = '0.3.1'
13
+ VERSION = '0.4.0'
14
14
 
15
15
  class << self
16
16
 
17
+ def head(uri, opts={})
18
+
19
+ Scorn::Client.new(opts).head(uri, opts)
20
+ end
21
+
17
22
  def get(uri, opts={})
18
23
 
19
24
  Scorn::Client.new(opts).get(uri, opts)
@@ -39,11 +44,23 @@ module Scorn
39
44
  [ 'Ruby', RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM ].join(' ')
40
45
 
41
46
  @ssl_verify_mode =
42
- (opts[:ssl_verify_none] == :none || opts[:verify_none] == :none) ?
47
+ (
48
+ opts[:ssl_verify] == :none || opts[:verify] == :none ||
49
+ opts[:ssl_verify] == false || opts[:verify] == false
50
+ ) ?
43
51
  OpenSSL::SSL::VERIFY_NONE : # :-(
44
52
  OpenSSL::SSL::VERIFY_PEER
45
53
  end
46
54
 
55
+ def head(uri, opts={})
56
+
57
+ u = uri.is_a?(String) ? URI(uri) : uri
58
+
59
+ res = request(u, make_head_req(u, opts))
60
+
61
+ opts[:res] ? res : read_response(res)
62
+ end
63
+
47
64
  def get(uri, opts={})
48
65
 
49
66
  u = uri.is_a?(String) ? URI(uri) : uri
@@ -64,25 +81,19 @@ module Scorn
64
81
 
65
82
  protected
66
83
 
67
- def make_get_req(uri, opts)
84
+ def make_head_req(uri, opts)
68
85
 
69
- accept =
70
- opts[:accept] ||
71
- (opts[:json] && 'application/json') ||
72
- '*/*'
86
+ make_req(:head, uri, gather_headers(:head, opts))
87
+ end
73
88
 
74
- make_req(
75
- :get, uri,
76
- agent: opts[:user_agent] || user_agent,
77
- accept: accept)
89
+ def make_get_req(uri, opts)
90
+
91
+ make_req(:get, uri, gather_headers(:get, opts))
78
92
  end
79
93
 
80
94
  def make_post_req(uri, opts)
81
95
 
82
- req = make_req(
83
- :post, uri,
84
- agent: opts[:user_agent] || user_agent,
85
- type: opts[:content_type] || 'application/x-www-form-urlencoded')
96
+ req = make_req(:post, uri, gather_headers(:post, opts))
86
97
 
87
98
  data = opts[:data]
88
99
  req.set_form_data(data) if data
@@ -90,6 +101,32 @@ module Scorn
90
101
  req
91
102
  end
92
103
 
104
+ def gather_headers(verb, opts)
105
+
106
+ h = {}
107
+
108
+ h['Accept'] =
109
+ opts[:accept] ||
110
+ (opts[:json] && 'application/json') ||
111
+ '*/*'
112
+ h['Agent'] =
113
+ opts[:user_agent] || user_agent
114
+ h['Authorization'] =
115
+ opts[:authorization] || opts[:auth]
116
+
117
+ h['Content-Type'] =
118
+ opts[:content_type] || 'application/x-www-form-urlencoded' \
119
+ if verb == :post
120
+
121
+ opts.each do |k, v|
122
+ h[k] = v if k.start_with?(/X-/)
123
+ end
124
+
125
+ h.compact!
126
+
127
+ h
128
+ end
129
+
93
130
  def make_req(type, uri, headers)
94
131
 
95
132
  u = [ uri.path, uri.query ].compact.join('?')
@@ -97,21 +134,13 @@ module Scorn
97
134
 
98
135
  req =
99
136
  case type
137
+ when :head then Net::HTTP::Head.new(u)
100
138
  when :get then Net::HTTP::Get.new(u)
101
139
  when :post then Net::HTTP::Post.new(u)
102
140
  else fail ArgumentError.new("HTTP #{type} not implemented")
103
141
  end
104
142
 
105
- headers.each do |k, v|
106
- hk =
107
- case k
108
- when :accept then 'Accept'
109
- when :agent then 'User-Agent'
110
- when :type then 'Content-Type'
111
- else k.to_s
112
- end
113
- req[hk] = v
114
- end
143
+ headers.each { |k, v| req[k] = v }
115
144
 
116
145
  req
117
146
  end
@@ -162,11 +191,15 @@ module Scorn
162
191
  def read_response(res)
163
192
 
164
193
  s = res.body
165
- st = s.strip
194
+ st = s ? s.strip : ''
195
+
196
+ a_z = "#{st[0, 1]}#{st[-1, 1]}"
166
197
 
167
198
  r =
168
- if st[0, 1] == '{' && st[-1, 1] == '}'
199
+ if a_z == '{}' || a_z == '[]'
169
200
  JSON.parse(st) rescue s
201
+ elsif s == nil
202
+ ''
170
203
  else
171
204
  s
172
205
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
10
+ date: 2025-08-01 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rspec
@@ -47,7 +46,6 @@ metadata:
47
46
  bug_tracker_uri: https://github.com/jmettraux/scorn/issues
48
47
  homepage_uri: https://github.com/jmettraux/scorn
49
48
  source_code_uri: https://github.com/jmettraux/scorn
50
- post_install_message:
51
49
  rdoc_options: []
52
50
  require_paths:
53
51
  - lib
@@ -62,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
60
  - !ruby/object:Gem::Version
63
61
  version: '0'
64
62
  requirements: []
65
- rubygems_version: 3.0.3
66
- signing_key:
63
+ rubygems_version: 3.6.2
67
64
  specification_version: 4
68
65
  summary: stupid HTTP client
69
66
  test_files: []