http.rb 0.15.0 → 0.15.1
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.txt +11 -0
- data/http.rb.gemspec +1 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/delete.rb +1 -0
- data/lib/HTTP/put.rb +7 -5
- data/lib/HTTP.rb +2 -0
- data/spec/HTTP/post_spec.rb +4 -4
- data/spec/HTTP/put_spec.rb +52 -20
- 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: 7eeee894fa63eb3d4e2ffe9fb35f9521111adc63b05261b56dd691e0f74f2613
|
4
|
+
data.tar.gz: ef36a1ad9059459da8f1941f6c7e2ca9c5150466d7944a1fd8278bf403311008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c02f7c9af8804c92de600e42bcbb161236826503b1be6e184704aa12e214b2665c195aa827610772780dfc9a3a7cf45b8f4bf13500959b4c34a88a241334a81c
|
7
|
+
data.tar.gz: abbd416370db5c0b118b259e284a2d5ba1ca1ae6bda9dde3f9b20826f37fbff4a57dacfa7e90b4bf52b49c0ee8116d53f83a1dfcf5c2eed3e5d2364fc3825b13
|
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 20250721
|
2
|
+
# 0.15.1: Fix PUT; require delete and put in the load file.
|
3
|
+
1. + require 'HTTP/post'
|
4
|
+
2. + require 'HTTP/put'
|
5
|
+
3. ~ HTTP/put.rb: Params in the body!
|
6
|
+
3. ~ spec/HTTP/put_spec.rb: Remove copy-pasta rubbish.
|
7
|
+
4. ~ spec/HTTP/post_spec.rb: Mostly formatting.
|
8
|
+
4. ~ HTTP::VERSION: /0.15.0/0.15.1/
|
9
|
+
5. ~ CHANGELOG.txt
|
10
|
+
6. ~ http.rb.gemspec: Change date.
|
11
|
+
|
1
12
|
# 20250716
|
2
13
|
# 0.15.0: + PUT
|
3
14
|
1. + HTTP.put
|
data/http.rb.gemspec
CHANGED
@@ -3,7 +3,7 @@ require_relative './lib/HTTP/VERSION'
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'http.rb'
|
5
5
|
s.version = HTTP::VERSION
|
6
|
-
s.date = '2025-07-
|
6
|
+
s.date = '2025-07-21'
|
7
7
|
|
8
8
|
s.summary = "HTTP made easy."
|
9
9
|
s.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/delete.rb
CHANGED
@@ -6,6 +6,7 @@ require 'openssl'
|
|
6
6
|
require 'uri'
|
7
7
|
|
8
8
|
require_relative '../Hash/x_www_form_urlencode'
|
9
|
+
require_relative '../HTTP/get'
|
9
10
|
require_relative '../Net/HTTP/set_options'
|
10
11
|
require_relative '../Net/HTTP/Delete/set_headers'
|
11
12
|
require_relative '../Net/HTTPResponse/StatusPredicates'
|
data/lib/HTTP/put.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# HTTP/put.rb
|
2
2
|
# HTTP.put
|
3
3
|
|
4
|
+
require 'json'
|
4
5
|
require 'net/http'
|
5
6
|
require 'openssl'
|
6
7
|
require 'uri'
|
7
8
|
|
8
|
-
require_relative '../
|
9
|
+
require_relative '../HTTP/get'
|
9
10
|
require_relative '../Net/HTTP/set_options'
|
10
11
|
require_relative '../Net/HTTP/Put/set_headers'
|
11
12
|
require_relative '../Net/HTTPResponse/StatusPredicates'
|
@@ -13,17 +14,18 @@ require_relative '../URI/Generic/use_sslQ'
|
|
13
14
|
|
14
15
|
module HTTP
|
15
16
|
|
16
|
-
def put(uri,
|
17
|
+
def put(uri, data = {}, headers = {}, options = {}, &block)
|
17
18
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
18
19
|
http = Net::HTTP.new(uri.host, uri.port)
|
19
20
|
no_redirect = options.delete(:no_redirect)
|
20
21
|
options[:use_ssl] ||= uri.use_ssl?
|
21
22
|
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
22
23
|
http.options = options
|
23
|
-
|
24
|
-
|
24
|
+
request_object = Net::HTTP::Put.new(uri.request_uri)
|
25
|
+
if headers['Content-Type'] == 'application/json'
|
26
|
+
request_object.body = JSON.dump(data)
|
25
27
|
else
|
26
|
-
request_object =
|
28
|
+
request_object.form_data = data
|
27
29
|
end
|
28
30
|
request_object.headers = headers
|
29
31
|
request_object.basic_auth(uri.user, uri.password) if uri.user
|
data/lib/HTTP.rb
CHANGED
data/spec/HTTP/post_spec.rb
CHANGED
@@ -194,8 +194,8 @@ describe ".post" do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it "does a redirect" do
|
197
|
-
expect(HTTP).to receive(:post).with(request_uri).and_call_original
|
198
|
-
expect(HTTP).to receive(:get).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
197
|
+
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
198
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
199
199
|
response = HTTP.post(request_uri)
|
200
200
|
expect(response.success?).to eq(true)
|
201
201
|
end
|
@@ -221,8 +221,8 @@ describe ".post" do
|
|
221
221
|
end
|
222
222
|
|
223
223
|
it "does a redirect" do
|
224
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
225
224
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
225
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
226
226
|
response = HTTP.post(request_uri)
|
227
227
|
expect(response.success?).to eq(true)
|
228
228
|
end
|
@@ -236,8 +236,8 @@ describe ".post" do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
it "does a redirect" do
|
239
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
240
239
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
240
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
241
241
|
response = HTTP.post(request_uri)
|
242
242
|
expect(response.success?).to eq(true)
|
243
243
|
end
|
data/spec/HTTP/put_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe ".put" do
|
|
7
7
|
context "with uri-only supplied" do
|
8
8
|
before do
|
9
9
|
stub_request(:put, 'http://example.com/path').
|
10
|
-
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
10
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
11
11
|
to_return(status: 200, body: '', headers: {})
|
12
12
|
end
|
13
13
|
|
@@ -36,7 +36,8 @@ describe ".put" do
|
|
36
36
|
|
37
37
|
it "returns an instance of URI" do
|
38
38
|
expect(uri).to eq(uri)
|
39
|
-
HTTP.put(uri)
|
39
|
+
response = HTTP.put(uri)
|
40
|
+
expect(response.success?).to eq(true)
|
40
41
|
end
|
41
42
|
|
42
43
|
it "creates a new Net::HTTP object" do
|
@@ -47,29 +48,60 @@ describe ".put" do
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
context "with
|
51
|
+
context "with form data supplied" do
|
51
52
|
let(:uri){'http://example.com/path'}
|
52
53
|
let(:parsed_uri){URI.parse(uri)}
|
53
54
|
let(:args) do; {a: 1, b: 2}; end
|
54
|
-
let(:
|
55
|
-
let(:
|
56
|
-
let(:
|
55
|
+
let(:headers) do; {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}; end
|
56
|
+
let(:encoded_form_data){args.x_www_form_urlencode}
|
57
|
+
let(:request_uri){parsed_uri.request_uri}
|
58
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
57
59
|
|
58
60
|
before do
|
59
|
-
stub_request(:put,
|
60
|
-
with(
|
61
|
+
stub_request(:put, "http://example.com/path").
|
62
|
+
with(body: encoded_form_data, headers: headers).
|
61
63
|
to_return(status: 200, body: '', headers: {})
|
62
64
|
end
|
63
65
|
|
64
|
-
it "
|
65
|
-
|
66
|
-
response = HTTP.put(uri, args)
|
66
|
+
it "sets the form data" do
|
67
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
68
|
+
response = HTTP.put(uri, args, headers)
|
69
|
+
expect(request_object.body).to eq(encoded_form_data)
|
67
70
|
expect(response.success?).to eq(true)
|
68
71
|
end
|
69
72
|
|
70
|
-
it "creates a new Net::HTTP::
|
71
|
-
expect(Net::HTTP::Put).to receive(:new).with(
|
72
|
-
response = HTTP.put(uri, args)
|
73
|
+
it "creates a new Net::HTTP::Post object" do
|
74
|
+
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
75
|
+
response = HTTP.put(uri, args, headers)
|
76
|
+
expect(response.success?).to eq(true)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with JSON data supplied" do
|
81
|
+
let(:uri){'http://example.com/path'}
|
82
|
+
let(:parsed_uri){URI.parse(uri)}
|
83
|
+
let(:args) do; {a: 1, b: 2}; end
|
84
|
+
let(:headers) do; {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}; end
|
85
|
+
let(:json_data){JSON.dump(args)}
|
86
|
+
let(:request_uri){parsed_uri.request_uri}
|
87
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
88
|
+
|
89
|
+
before do
|
90
|
+
stub_request(:put, "http://example.com/path").
|
91
|
+
with(body: json_data, headers: headers).
|
92
|
+
to_return(status: 200, body: '', headers: {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets the body" do
|
96
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
97
|
+
response = HTTP.put(uri, args, headers)
|
98
|
+
expect(request_object.body).to eq(json_data)
|
99
|
+
expect(response.success?).to eq(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates a new Net::HTTP::Post object" do
|
103
|
+
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
104
|
+
response = HTTP.put(uri, args, headers)
|
73
105
|
expect(response.success?).to eq(true)
|
74
106
|
end
|
75
107
|
end
|
@@ -78,17 +110,17 @@ describe ".put" do
|
|
78
110
|
let(:uri){'http://example.com/path'}
|
79
111
|
let(:parsed_uri){URI.parse(uri)}
|
80
112
|
let(:headers) do; {'User-Agent' => 'Rspec'}; end
|
81
|
-
let(:
|
82
|
-
let(:request_object){Net::HTTP::Put.new(
|
113
|
+
let(:request_uri){parsed_uri.request_uri}
|
114
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
83
115
|
|
84
116
|
before do
|
85
117
|
stub_request(:put, 'http://example.com/path').
|
86
|
-
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Rspec'}).
|
118
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Rspec'}).
|
87
119
|
to_return(status: 200, body: '', headers: {})
|
88
120
|
end
|
89
121
|
|
90
122
|
it "sets the headers on the request object" do
|
91
|
-
allow(Net::HTTP::Put).to receive(:new).with(
|
123
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
92
124
|
response = HTTP.put(uri, {}, headers)
|
93
125
|
expect(request_object['User-Agent']).to eq('Rspec')
|
94
126
|
expect(response.success?).to eq(true)
|
@@ -103,7 +135,7 @@ describe ".put" do
|
|
103
135
|
|
104
136
|
before do
|
105
137
|
stub_request(:put, 'https://example.com:80/path').
|
106
|
-
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
138
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
107
139
|
to_return(status: 200, body: '', headers: {})
|
108
140
|
end
|
109
141
|
|
@@ -120,7 +152,7 @@ describe ".put" do
|
|
120
152
|
|
121
153
|
before do
|
122
154
|
stub_request(:put, 'http://example.com/path').
|
123
|
-
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
155
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
124
156
|
to_return(status: 200, body: '', headers: {})
|
125
157
|
end
|
126
158
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoran
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-21 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, some
|
13
13
|
optional query arguments, some optional headers, and some Net::HTTP options,
|