http.rb 0.16.1 → 0.18.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.txt → CHANGELOG} +45 -0
- data/Gemfile +3 -5
- data/LICENSE +21 -0
- data/README.md +51 -39
- data/Rakefile +9 -0
- data/http.rb.gemspec +31 -14
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/{get.rb → request.rb} +5 -13
- data/lib/HTTP/verbs.rb +49 -0
- data/lib/Hash/x_www_form_urlencode.rb +1 -11
- data/lib/Net/HTTP/Report.rb +14 -0
- data/lib/Net/HTTP/set_options.rb +1 -4
- data/lib/Net/HTTPRequest/set_headers.rb +13 -0
- data/lib/Net/HTTPResponse/StatusPredicates.rb +3 -0
- data/lib/String/to_const.rb +7 -0
- data/lib/Thoran/Array/AllButFirst/all_but_first.rb +28 -0
- data/lib/Thoran/Array/FirstX/firstX.rb +32 -0
- data/lib/Thoran/String/ToConst/to_const.rb +47 -0
- data/lib/URI/Generic/use_sslQ.rb +1 -7
- data/lib/{HTTP.rb → http.rb} +1 -4
- data/spec/HTTP/delete_spec.rb +1 -1
- data/spec/HTTP/get_spec.rb +1 -1
- data/spec/HTTP/head_spec.rb +118 -0
- data/spec/HTTP/post_spec.rb +1 -1
- data/spec/HTTP/propfind_spec.rb +122 -0
- data/spec/HTTP/put_spec.rb +1 -1
- data/spec/Net/HTTP/Report_spec.rb +22 -0
- metadata +78 -16
- data/lib/HTTP/delete.rb +0 -55
- data/lib/HTTP/post.rb +0 -65
- data/lib/HTTP/put.rb +0 -65
- data/lib/Net/HTTP/Delete/set_headers.rb +0 -14
- data/lib/Net/HTTP/Get/set_headers.rb +0 -17
- data/lib/Net/HTTP/Post/set_headers.rb +0 -17
- data/lib/Net/HTTP/Put/set_headers.rb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8f29700e5af2badc9a6207ce6c3cf5ce189c6e282da3955535139b2014c1092
|
|
4
|
+
data.tar.gz: 121be70186382dab28df52b69f7a2e5c9501bb5891946865621250e63e85f952
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2a0ed184928d0f3656d8d9d28bcb37098759f94cf37f708c931b020c920d2d2c8f50a5a7856dcb1827759c3d8a917e5824b7266217861f21daca202533003c3
|
|
7
|
+
data.tar.gz: 22525a1fa099e471895bfe8cc660c728c3fcc52067b24849079b1f0c3c0e9ed50e64359c92d46de2aed7557b72d4855b39b93ab652a3fd2da122c9e5c3704df7
|
data/{CHANGELOG.txt → CHANGELOG}
RENAMED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
# 20260507
|
|
2
|
+
# 0.18.0: Add all missing HTTP verbs; use meta-programming to define verb methods.
|
|
3
|
+
1. + HTTP/verbs.rb; including:
|
|
4
|
+
+ HTTP::VERBS::WITHOUT_BODY: get, delete, head, options, trace
|
|
5
|
+
+ HTTP::VERBS::WITH_BODY: post, put, patch, propfind, proppatch, mkcol, copy, move, lock, unlock, report
|
|
6
|
+
2. + lib/Net/HTTP/Report.rb: Add Net::HTTP::Report, which is missing from Ruby's standard library. See RFC 3253.
|
|
7
|
+
3. - lib/HTTP/delete.rb
|
|
8
|
+
4. - lib/HTTP/get.rb
|
|
9
|
+
5. - lib/HTTP/post.rb
|
|
10
|
+
6. - lib/HTTP/put.rb
|
|
11
|
+
7. + String/to_const.rb
|
|
12
|
+
8. + Thoran/Array/AllButFirst/all_but_first.rb
|
|
13
|
+
9. + Thoran/Array/FirstX/firstX.rb
|
|
14
|
+
10. + Thoran/String/ToConst/to_const.rb
|
|
15
|
+
11. + LICENSE
|
|
16
|
+
12. + Rakefile
|
|
17
|
+
13. + spec/HTTP/head_spec.rb
|
|
18
|
+
14. + spec/HTTP/propfind_spec.rb
|
|
19
|
+
15. + spec/Net/HTTP/Report_spec.rb
|
|
20
|
+
16. ~ HTTP::VERSION: /0.17.0/0.18.0/
|
|
21
|
+
17. /CHANGELOG.txt/CHANGELOG/
|
|
22
|
+
18. /TODO.txt/TODO/
|
|
23
|
+
19. ~ CHANGELOG: + 0.18.0 entry
|
|
24
|
+
20. ~ http.rb.gemspec: /s/spec/; - date; + Rakefile; + development_dependencies
|
|
25
|
+
21. ~ Gemfile: /group :test/gemspec/
|
|
26
|
+
22. ~ .gitignore: Using a common one with lots of entries.
|
|
27
|
+
23. ~ README.md: /http.rb/http/; Trimmed the Description; Usage has more code blocks, making the comments Markdown sub-sections.
|
|
28
|
+
|
|
29
|
+
# 20260325
|
|
30
|
+
# 0.17.0: Extract HTTP.request method; consolidate set_headers.
|
|
31
|
+
1. + HTTP.request: Extract common plumbing (connection, SSL, auth, redirect, response) from verb methods.
|
|
32
|
+
2. ~ HTTP.get: Delegate to HTTP.request.
|
|
33
|
+
3. ~ HTTP.delete: Delegate to HTTP.request.
|
|
34
|
+
4. ~ HTTP.post: Delegate to HTTP.request.
|
|
35
|
+
5. ~ HTTP.put: Delegate to HTTP.request.
|
|
36
|
+
6. + Net::HTTPRequest#set_headers: Consolidate per-verb set_headers into single method on superclass.
|
|
37
|
+
7. - Net::HTTP::Get#set_headers
|
|
38
|
+
8. - Net::HTTP::Post#set_headers
|
|
39
|
+
9. - Net::HTTP::Put#set_headers
|
|
40
|
+
10. - Net::HTTP::Delete#set_headers
|
|
41
|
+
11. + TODO.txt
|
|
42
|
+
12. ~ HTTP::VERSION: /0.16.1/0.17.0/
|
|
43
|
+
13. ~ CHANGELOG.txt: + 0.17.0 entry
|
|
44
|
+
14. ~ http.rb.gemspec: Change date.
|
|
45
|
+
|
|
1
46
|
# 20250908
|
|
2
47
|
# 0.16.1: Allow any case for the content-type key.
|
|
3
48
|
1. ~ HTTP.post: Check for any case for content-type key.
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 thoran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,89 +1,94 @@
|
|
|
1
|
-
# http
|
|
1
|
+
# http
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
For many years this was a personal library, from around the middle of 2009 from what I can ascertain, though in various guises it may have been as early as late 2007.
|
|
6
6
|
|
|
7
|
-
Like many others before and after me with their respective libraries, I created it to simplify the heinous interface that is Net::HTTP.
|
|
7
|
+
Like many others before and after me with their respective libraries, I created it to simplify the heinous interface that is Net::HTTP. At the time of it's original creation I was doing a lot of a webscraping and didn't want a half-dozen line setup to make simple requests. It has stood the test of time, for me personally insofar as the interface remaining simpler than most other similar libraries, though it is also less full featured, but nevertheless for it's tiny size it packs in quite a bit.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Even so, through its various incarnations the goal has basically remained the same: to have a simple way of making HTTP requests in Ruby.
|
|
12
|
-
|
|
13
|
-
I'd never intended to publish this and had intended for it to remain a personal library, but decided to use it for a small project and so as it could be included with ease in a Gemfile it needed to be gemified and well here we are, rightly or wrongly.
|
|
14
|
-
|
|
15
|
-
Perhaps someone will appreciate its relative simplicity, since it is much smaller and the usage simpler than any of the other 'wrapper' libraries mentioned above at least, such that it can be read and comprehended in full in as little as a couple of minutes. It does just enough to do most simple HTTP GET and POST requests as simply as should be.
|
|
9
|
+
Perhaps some will appreciate its relative simplicity, since it is much smaller and the usage simpler than any of the other 'wrapper' libraries, such that it can be read and comprehended in full in as little as a couple of minutes. It does just enough to do most simple HTTP GET and POST requests as simply as should be.
|
|
16
10
|
|
|
17
11
|
|
|
18
12
|
## Installation
|
|
19
13
|
|
|
20
14
|
Add this line to your application's Gemfile:
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'http.rb'
|
|
18
|
+
```
|
|
24
19
|
|
|
25
20
|
And then execute:
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Or install it yourself as:
|
|
22
|
+
```shell
|
|
23
|
+
$ bundle
|
|
24
|
+
```
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
Or install it directly:
|
|
33
27
|
|
|
28
|
+
```shell
|
|
29
|
+
$ gem install http.rb
|
|
30
|
+
```
|
|
34
31
|
|
|
35
32
|
## Usage
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
# With just a URI
|
|
34
|
+
### With just a URI
|
|
39
35
|
|
|
36
|
+
```ruby
|
|
40
37
|
HTTP.get('http://example.com')
|
|
41
|
-
|
|
38
|
+
```
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
### With arguments only
|
|
44
41
|
|
|
42
|
+
```ruby
|
|
45
43
|
HTTP.get('http://example.com', {a: 1, b: 2})
|
|
46
44
|
HTTP.post('http://example.com', {a: 1, b: 2})
|
|
45
|
+
```
|
|
46
|
+
### With JSON data
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
```ruby
|
|
50
49
|
HTTP.post('http://example.com', {a: 1, b: 2}, {'Content-type' => 'application/json'})
|
|
50
|
+
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
### With custom headers only
|
|
53
53
|
|
|
54
|
+
```ruby
|
|
54
55
|
HTTP.get('http://example.com', {}, {'User-Agent'=>'Custom'})
|
|
55
56
|
HTTP.post('http://example.com', {}, {'User-Agent'=>'Custom'})
|
|
57
|
+
```
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
### With options only
|
|
58
60
|
|
|
61
|
+
```ruby
|
|
59
62
|
HTTP.get('http://example.com', {}, {}, {use_ssl: true})
|
|
60
63
|
HTTP.post('http://example.com', {}, {}, {use_ssl: true})
|
|
64
|
+
```
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
### With a block
|
|
63
67
|
|
|
68
|
+
```ruby
|
|
64
69
|
HTTP.get('http://example.com') do |response|
|
|
65
70
|
# Do stuff with a subclass of Net::HTTPResponse here...
|
|
66
71
|
end
|
|
67
|
-
|
|
68
|
-
# Do stuff with a subclass of Net::HTTPResponse here...
|
|
69
|
-
end
|
|
72
|
+
```
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
### With the lot
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
# Do stuff with a subclass of Net::HTTPResponse here...
|
|
75
|
-
end
|
|
76
|
+
```ruby
|
|
76
77
|
HTTP.post('http://example.com', {a: 1, b: 2}, {'User-Agent'=>'Custom'}, {use_ssl: true}) do |response|
|
|
77
78
|
# Do stuff with a subclass of Net::HTTPResponse here...
|
|
78
79
|
end
|
|
80
|
+
```
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
### Preventing redirections
|
|
81
83
|
|
|
84
|
+
```ruby
|
|
82
85
|
HTTP.get('http://example.com', {}, {}, {no_redirect: true})
|
|
83
86
|
# => #<Net::HTTPResponse @code=3xx>
|
|
87
|
+
```
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
### Response status predicate methods
|
|
86
90
|
|
|
91
|
+
```ruby
|
|
87
92
|
# 1xx
|
|
88
93
|
response = HTTP.get('http://example.com')
|
|
89
94
|
response.informational?
|
|
@@ -126,23 +131,26 @@ response.server_error?
|
|
|
126
131
|
# => true
|
|
127
132
|
response.error?
|
|
128
133
|
# => true
|
|
134
|
+
```
|
|
129
135
|
|
|
130
|
-
|
|
136
|
+
### Including it in a class
|
|
131
137
|
|
|
138
|
+
```ruby
|
|
132
139
|
class A
|
|
133
140
|
include HTTP
|
|
134
141
|
def a
|
|
135
142
|
get('http://example.com')
|
|
136
143
|
end
|
|
137
144
|
end
|
|
145
|
+
```
|
|
138
146
|
|
|
139
|
-
|
|
147
|
+
### Extending a class
|
|
140
148
|
|
|
149
|
+
```ruby
|
|
141
150
|
class A
|
|
142
151
|
extend HTTP
|
|
143
152
|
get('http://example.com')
|
|
144
153
|
end
|
|
145
|
-
|
|
146
154
|
```
|
|
147
155
|
|
|
148
156
|
## Allowed values for the options hash
|
|
@@ -239,8 +247,12 @@ verify_mode
|
|
|
239
247
|
|
|
240
248
|
## Contributing
|
|
241
249
|
|
|
242
|
-
1. Fork it ( https://github.com/thoran/
|
|
250
|
+
1. Fork it ( https://github.com/thoran/http/fork )
|
|
243
251
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
244
252
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
245
253
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
246
254
|
5. Create a new pull request
|
|
255
|
+
|
|
256
|
+
## Licence
|
|
257
|
+
|
|
258
|
+
MIT
|
data/Rakefile
ADDED
data/http.rb.gemspec
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
require_relative './lib/HTTP/VERSION'
|
|
2
2
|
|
|
3
|
-
Gem::Specification
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
class Gem::Specification
|
|
4
|
+
def development_dependencies=(gems)
|
|
5
|
+
gems.each{|gem| add_development_dependency(*gem)}
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Gem::Specification.new do |spec|
|
|
10
|
+
spec.name = 'http.rb'
|
|
11
|
+
spec.version = HTTP::VERSION
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
spec.summary = "HTTP made easy."
|
|
14
|
+
spec.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
|
|
10
15
|
some optional query arguments, some optional headers, and some \
|
|
11
16
|
Net::HTTP options, and that's it!"
|
|
12
|
-
s.author = 'thoran'
|
|
13
|
-
s.email = 'code@thoran.com'
|
|
14
|
-
s.homepage = "http://github.com/thoran/HTTP"
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
spec.author = 'thoran'
|
|
19
|
+
spec.email = 'code@thoran.com'
|
|
20
|
+
spec.homepage = "http://github.com/thoran/HTTP"
|
|
21
|
+
spec.license = 'MIT'
|
|
22
|
+
|
|
23
|
+
spec.required_ruby_version = '>= 2.7'
|
|
24
|
+
spec.require_paths = ['lib']
|
|
25
|
+
|
|
26
|
+
spec.files = [
|
|
27
|
+
'http.rb.gemspec',
|
|
28
|
+
'CHANGELOG',
|
|
18
29
|
'Gemfile',
|
|
30
|
+
'LICENSE',
|
|
31
|
+
'Rakefile',
|
|
19
32
|
'README.md',
|
|
20
|
-
'http.rb.gemspec',
|
|
21
33
|
Dir['lib/**/*.rb'],
|
|
22
|
-
Dir['spec/**/*.rb']
|
|
34
|
+
Dir['spec/**/*.rb'],
|
|
23
35
|
].flatten
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
spec.development_dependencies = %w{
|
|
38
|
+
pry
|
|
39
|
+
rake
|
|
40
|
+
rspec
|
|
41
|
+
webmock
|
|
42
|
+
}
|
|
26
43
|
end
|
data/lib/HTTP/VERSION.rb
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
# HTTP/
|
|
2
|
-
# HTTP.
|
|
1
|
+
# HTTP/request.rb
|
|
2
|
+
# HTTP.request
|
|
3
3
|
|
|
4
4
|
require 'net/http'
|
|
5
5
|
require 'openssl'
|
|
6
6
|
require 'uri'
|
|
7
7
|
|
|
8
|
-
require_relative '../Hash/x_www_form_urlencode'
|
|
9
8
|
require_relative '../Net/HTTP/set_options'
|
|
10
|
-
require_relative '../Net/
|
|
9
|
+
require_relative '../Net/HTTPRequest/set_headers'
|
|
11
10
|
require_relative '../Net/HTTPResponse/StatusPredicates'
|
|
12
11
|
require_relative '../URI/Generic/use_sslQ'
|
|
13
12
|
|
|
14
13
|
module HTTP
|
|
15
|
-
|
|
16
|
-
def get(uri, args = {}, headers = {}, options = {}, &block)
|
|
14
|
+
def request(uri, request_object, headers = {}, options = {}, &block)
|
|
17
15
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
18
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
19
17
|
no_redirect = options.delete(:no_redirect)
|
|
20
18
|
options[:use_ssl] ||= uri.use_ssl?
|
|
21
19
|
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
|
22
20
|
http.options = options
|
|
23
|
-
if args.empty?
|
|
24
|
-
request_object = Net::HTTP::Get.new(uri.request_uri)
|
|
25
|
-
else
|
|
26
|
-
request_object = Net::HTTP::Get.new(uri.request_uri + '?' + args.x_www_form_urlencode)
|
|
27
|
-
end
|
|
28
21
|
request_object.headers = headers
|
|
29
22
|
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
30
23
|
response = http.request(request_object)
|
|
@@ -49,6 +42,5 @@ module HTTP
|
|
|
49
42
|
end
|
|
50
43
|
end
|
|
51
44
|
|
|
52
|
-
module_function :
|
|
53
|
-
|
|
45
|
+
module_function :request
|
|
54
46
|
end
|
data/lib/HTTP/verbs.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# HTTP/verbs.rb
|
|
2
|
+
# HTTP.verb
|
|
3
|
+
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'net/http'
|
|
6
|
+
|
|
7
|
+
require_relative '../Hash/x_www_form_urlencode'
|
|
8
|
+
require_relative '../Net/HTTP/Report'
|
|
9
|
+
require_relative './request'
|
|
10
|
+
require_relative '../String/to_const'
|
|
11
|
+
|
|
12
|
+
module HTTP
|
|
13
|
+
module VERBS
|
|
14
|
+
WITHOUT_BODY = %i{get delete head options trace}
|
|
15
|
+
WITH_BODY = %i{post put patch propfind proppatch mkcol copy move lock unlock report}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
VERBS::WITHOUT_BODY.each do |verb|
|
|
19
|
+
define_method(verb) do |uri, args = {}, headers = {}, options = {}, &block|
|
|
20
|
+
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
21
|
+
request_uri = uri.request_uri
|
|
22
|
+
unless args.empty?
|
|
23
|
+
request_uri += '?' + args.x_www_form_urlencode
|
|
24
|
+
end
|
|
25
|
+
request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(request_uri)
|
|
26
|
+
request(uri, request_object, headers, options, &block)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module_function verb
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
VERBS::WITH_BODY.each do |verb|
|
|
33
|
+
define_method(verb) do |uri, data = {}, headers = {}, options = {}, &block|
|
|
34
|
+
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
35
|
+
request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(uri.request_uri)
|
|
36
|
+
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
|
37
|
+
if data.is_a?(String)
|
|
38
|
+
request_object.body = data
|
|
39
|
+
elsif content_type.start_with?('application/json')
|
|
40
|
+
request_object.body = JSON.dump(data)
|
|
41
|
+
else
|
|
42
|
+
request_object.form_data = data
|
|
43
|
+
end
|
|
44
|
+
request(uri, request_object, headers, options, &block)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module_function verb
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
# Hash/x_www_form_urlencode.rb
|
|
2
2
|
# Hash#x_www_form_urlencode
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes: Extracted from MtGox library.
|
|
8
|
-
|
|
9
|
-
# Todo:
|
|
10
|
-
# 1. I should separate out the functionality for adding '+' characters so as it can do both styles of encoding. That way I could reuse the existing Hash/to_parameter_string method as well...
|
|
11
|
-
|
|
12
|
-
require 'String/url_encode'
|
|
4
|
+
require_relative '../String/url_encode'
|
|
13
5
|
|
|
14
6
|
class Hash
|
|
15
|
-
|
|
16
7
|
def x_www_form_urlencode(joiner = '&')
|
|
17
8
|
inject([]){|a,e| a << "#{e.first.to_s.url_encode.gsub(/ /, '+')}=#{e.last.to_s.url_encode.gsub(/ /, '+')}" unless e.last.nil?; a}.join(joiner)
|
|
18
9
|
end
|
|
19
|
-
|
|
20
10
|
end
|
data/lib/Net/HTTP/set_options.rb
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
# Net/HTTP/set_options.rb
|
|
2
2
|
# Net::HTTP#set_options
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
4
|
+
require 'net/http'
|
|
6
5
|
|
|
7
6
|
module Net
|
|
8
7
|
class HTTP
|
|
9
|
-
|
|
10
8
|
def set_options(options = {})
|
|
11
9
|
options.each{|k,v| self.send("#{k}=", v)}
|
|
12
10
|
end
|
|
13
11
|
alias_method :options=, :set_options
|
|
14
|
-
|
|
15
12
|
end
|
|
16
13
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Thoran/Array/AllButFirst/all_but_first.rb
|
|
2
|
+
# Thoran::Array::AllButFirst#all_but_first
|
|
3
|
+
|
|
4
|
+
# 20141223
|
|
5
|
+
# 0.1.0
|
|
6
|
+
|
|
7
|
+
# Description: This returns a copy of the receiving array with the first element removed.
|
|
8
|
+
|
|
9
|
+
# Changes:
|
|
10
|
+
# 1. + Thoran namespace.
|
|
11
|
+
|
|
12
|
+
require 'Thoran/Array/FirstX/firstX'
|
|
13
|
+
|
|
14
|
+
module Thoran
|
|
15
|
+
module Array
|
|
16
|
+
module AllButFirst
|
|
17
|
+
|
|
18
|
+
def all_but_first
|
|
19
|
+
d = self.dup
|
|
20
|
+
d.first!
|
|
21
|
+
d
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Array.send(:include, Thoran::Array::AllButFirst)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Thoran/Array/FirstX/firstX.rb
|
|
2
|
+
# Thoran::Array::FirstX#first!
|
|
3
|
+
|
|
4
|
+
# 20180804
|
|
5
|
+
# 0.3.3
|
|
6
|
+
|
|
7
|
+
# Description: Sometimes it makes more sense to treat arrays this way.
|
|
8
|
+
|
|
9
|
+
# Changes since 0.2:
|
|
10
|
+
# 1. Added the original version 0.1.0 of the implementation to the later 0.1.0!
|
|
11
|
+
# 0/1
|
|
12
|
+
# 2. Switched the tests to spec-style.
|
|
13
|
+
# 1/2
|
|
14
|
+
# 3. Added a test for the state of the array afterward, since this is meant to be an in place change.
|
|
15
|
+
# 2/3
|
|
16
|
+
# 4. Added tests for the extended functionality introduced in the first version 0.1.0.
|
|
17
|
+
|
|
18
|
+
module Thoran
|
|
19
|
+
module Array
|
|
20
|
+
module FirstX
|
|
21
|
+
|
|
22
|
+
def first!(n = 1)
|
|
23
|
+
return_value = []
|
|
24
|
+
n.times{return_value << self.shift}
|
|
25
|
+
return_value.size == 1 ? return_value[0] : return_value
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Array.send(:include, Thoran::Array::FirstX)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Thoran/String/ToConst/to_const.rb
|
|
2
|
+
# Thoran::String::ToConst#to_const
|
|
3
|
+
|
|
4
|
+
# 20141223
|
|
5
|
+
# 0.2.0
|
|
6
|
+
|
|
7
|
+
# Description: This takes a string and returns a constant, with unlimited namespacing.
|
|
8
|
+
|
|
9
|
+
# History: Derived from Object#to_const 0.3.0, and superceding Object#to_const.
|
|
10
|
+
|
|
11
|
+
# Changes:
|
|
12
|
+
# 1. + Thoran namespace.
|
|
13
|
+
|
|
14
|
+
# Todo:
|
|
15
|
+
# 1. This only works for two levels of constants. Three and you're stuffed. So, this needs to be recursive...
|
|
16
|
+
# Done iteratively as of 0.1.0.
|
|
17
|
+
# 2. Make this work for symbols. However, this will only work if there's no namespacing. ie. :A is OK, but :A::B is not.
|
|
18
|
+
|
|
19
|
+
# Discussion:
|
|
20
|
+
# 1. Should this go separately into classes for which ::const_get will work and be removed from Object? Done as of 0.1.0.
|
|
21
|
+
|
|
22
|
+
require 'Thoran/Array/AllButFirst/all_but_first'
|
|
23
|
+
|
|
24
|
+
module Thoran
|
|
25
|
+
module String
|
|
26
|
+
module ToConst
|
|
27
|
+
|
|
28
|
+
def to_const
|
|
29
|
+
if self =~ /::/
|
|
30
|
+
constants = self.split('::')
|
|
31
|
+
constant = Object.const_get(constants.first)
|
|
32
|
+
constants = constants.all_but_first
|
|
33
|
+
until constants.empty? do
|
|
34
|
+
constant = constant.const_get(constants.shift)
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
constant = Object.const_get(self)
|
|
38
|
+
end
|
|
39
|
+
constant
|
|
40
|
+
end
|
|
41
|
+
alias_method :to_constant, :to_const
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
String.send(:include, Thoran::String::ToConst)
|
data/lib/URI/Generic/use_sslQ.rb
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
# URI/Generic/use_sslQ.rb
|
|
2
2
|
# URI::Generic#use_ssl?
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes:
|
|
8
|
-
# 1. Using the date from when first created in HTTP.get/post as the creation date.
|
|
4
|
+
require 'uri'
|
|
9
5
|
|
|
10
6
|
module URI
|
|
11
7
|
class Generic
|
|
12
|
-
|
|
13
8
|
def use_ssl?
|
|
14
9
|
scheme == 'https' ? true : false
|
|
15
10
|
end
|
|
16
|
-
|
|
17
11
|
end
|
|
18
12
|
end
|
data/lib/{HTTP.rb → http.rb}
RENAMED