http.rb 1.2.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 448e7dce1f8dc9a0b23a659b351d10e241ccf1e3cf853663046ec4d7e6e0c8fe
4
- data.tar.gz: 75123ecd90c4f5333b8c9a6d62435ab20b46623a5871eb8464a224a92c900ed1
3
+ metadata.gz: 8e8141a5ebd470216fbd373f5a21fa5b96981be7dc2d6ddb7d8131b220b91ef7
4
+ data.tar.gz: 20a7507d9c92457c23f38970f9d04877c527115d298a07a5c3fe0015c88ff627
5
5
  SHA512:
6
- metadata.gz: 7fadfa5b0e33af922edc397877c6fecdff9fd0e5fdb2c8bbb17b9aaeb33f7cddc61553129e1ae6dafc7ee7367a4e1e0a71fa380119020dafbb50e66873f2333c
7
- data.tar.gz: d5b35c43b60b13b3e34b1b56a5d02189266401ccb3a9d63b9d87ead07330f96efb80e2577391eea8ed0ec2a734050d7b22aa0fb21e50cfe334b53ca700ede7a6
6
+ metadata.gz: 97514595af94da5845f2189b81751838c1c753ee69afaf31cd43d08ab80cfbd623b7da8214e61375a011210ef9dbe330f318e3981b0b5c350f63b12f4526c2a7
7
+ data.tar.gz: a8828932d5d72ab5348f44b2f0bff95f14a13653682161963fdb3d518f3734805798abf518bd7fe849f70e838225a9229b989147c94a3808e533e1f5d50836cd
data/CHANGELOG CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## 20260609
4
4
 
5
+ 1.2.1: Split the request builders into their own files.
6
+
7
+ request_with_body and request_without_body, added in 1.2.0, each move into their own file, matching the one-method-per-file layout used throughout lib/. Purely internal reorganisation — the methods, their signatures, and their behaviour are unchanged — so it is a patch, not a minor.
8
+
9
+ 1. + lib/HTTP/request_without_body.rb: HTTP.request_without_body, extracted from verbs.rb; requires net/http and the Hash#x_www_form_urlencode extension.
10
+ 2. + lib/HTTP/request_with_body.rb: HTTP.request_with_body, extracted from verbs.rb; requires net/http and json.
11
+ 3. ~ HTTP/verbs.rb: the request builders are extracted; the file now requires the two new files and keeps the VERBS constant and the named-method generation.
12
+ 4. ~ HTTP::VERSION: /1.2.0/1.2.1/
13
+ 5. ~ CHANGELOG: + 1.2.1 entry
14
+
15
+ ## 20260609
16
+
5
17
  1.2.0: Extract request_without_body and request_with_body.
6
18
 
7
19
  The logic for building request objects — constructing the Net::HTTP request class, encoding bodies, and assembling query strings — lived inside the define_method loops and was unreachable except through the eight named methods. Downstream gems needing a method without a named helper (notably webdav's PROPFIND) had to build raw Net::HTTP request objects and bypass that logic entirely. Those two loop bodies are now module functions, callable directly as HTTP.request_without_body(method, ...) and HTTP.request_with_body(method, ...); the named methods delegate to them and behave identically.
data/lib/HTTP/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '1.2.0'
5
+ VERSION = '1.2.1'
6
6
  end
@@ -0,0 +1,25 @@
1
+ # HTTP/request_with_body.rb
2
+ # HTTP.request_with_body
3
+
4
+ require 'json'
5
+ require 'net/http'
6
+
7
+ require_relative './request'
8
+
9
+ module HTTP
10
+ def request_with_body(method, uri, data = {}, headers = {}, options = {}, &block)
11
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
+ request_object = Net::HTTP.const_get(method.to_s.capitalize).new(uri.request_uri)
13
+ content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
14
+ if data.is_a?(String)
15
+ request_object.body = data
16
+ elsif content_type.start_with?('application/json')
17
+ request_object.body = JSON.dump(data)
18
+ else
19
+ request_object.form_data = data
20
+ end
21
+ request(uri, request_object, headers, options, &block)
22
+ end
23
+
24
+ module_function :request_with_body
25
+ end
@@ -0,0 +1,21 @@
1
+ # HTTP/request_without_body.rb
2
+ # HTTP.request_without_body
3
+
4
+ require 'net/http'
5
+
6
+ require_relative '../Hash/x_www_form_urlencode'
7
+ require_relative './request'
8
+
9
+ module HTTP
10
+ def request_without_body(method, uri, args = {}, headers = {}, options = {}, &block)
11
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
+ request_uri = uri.request_uri
13
+ unless args.empty?
14
+ request_uri += '?' + args.x_www_form_urlencode
15
+ end
16
+ request_object = Net::HTTP.const_get(method.to_s.capitalize).new(request_uri)
17
+ request(uri, request_object, headers, options, &block)
18
+ end
19
+
20
+ module_function :request_without_body
21
+ end
data/lib/HTTP/verbs.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  # HTTP/verbs.rb
2
2
  # HTTP.verb
3
3
 
4
- require 'json'
5
- require 'net/http'
6
-
7
- require_relative '../Hash/x_www_form_urlencode'
8
- require_relative './request'
4
+ require_relative './request_without_body'
5
+ require_relative './request_with_body'
9
6
 
10
7
  module HTTP
11
8
  module VERBS
@@ -13,32 +10,6 @@ module HTTP
13
10
  WITH_BODY = %i{post put patch}
14
11
  end
15
12
 
16
- def request_without_body(method, uri, args = {}, headers = {}, options = {}, &block)
17
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
18
- request_uri = uri.request_uri
19
- unless args.empty?
20
- request_uri += '?' + args.x_www_form_urlencode
21
- end
22
- request_object = Net::HTTP.const_get(method.to_s.capitalize).new(request_uri)
23
- request(uri, request_object, headers, options, &block)
24
- end
25
- module_function :request_without_body
26
-
27
- def request_with_body(method, uri, data = {}, headers = {}, options = {}, &block)
28
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
29
- request_object = Net::HTTP.const_get(method.to_s.capitalize).new(uri.request_uri)
30
- content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
31
- if data.is_a?(String)
32
- request_object.body = data
33
- elsif content_type.start_with?('application/json')
34
- request_object.body = JSON.dump(data)
35
- else
36
- request_object.form_data = data
37
- end
38
- request(uri, request_object, headers, options, &block)
39
- end
40
- module_function :request_with_body
41
-
42
13
  VERBS::WITHOUT_BODY.each do |verb|
43
14
  define_method(verb) do |uri, args = {}, headers = {}, options = {}, &block|
44
15
  request_without_body(verb, uri, args, headers, options, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -97,6 +97,8 @@ files:
97
97
  - lib/HTTP/RETRY.rb
98
98
  - lib/HTTP/VERSION.rb
99
99
  - lib/HTTP/request.rb
100
+ - lib/HTTP/request_with_body.rb
101
+ - lib/HTTP/request_without_body.rb
100
102
  - lib/HTTP/verbs.rb
101
103
  - lib/Hash/x_www_form_urlencode.rb
102
104
  - lib/Net/HTTP/set_options.rb