nap 1.1.1 → 1.2.0.pre
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/README.md +10 -2
- data/lib/rest/error.rb +13 -15
- data/lib/rest/request.rb +78 -63
- data/lib/rest/response.rb +10 -8
- data/lib/rest.rb +23 -21
- metadata +8 -39
- data/support/cacert.pem +0 -3016
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3918e6029d9b1f27388ead24c3595866663e0e1605c5fb7995827e972e21255a
|
|
4
|
+
data.tar.gz: 6e52a5e30bf63142ac74a5d1dc655ed472f1fc9e2ff6ddc14c9e11e8fe51c278
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a08b2f7f550793facf60b7efcacdc7aa33d410b98bf56d0046fe2548572d2a50a2a32b673ed6ab38e08dff4d736a236faa6bdef5025fab1642b17749785b3cc3
|
|
7
|
+
data.tar.gz: c8986312fe7aa65741315b2913aa20dd47cbe4fdb53925b59a2fd0056a90f0ed3698b541b185da9cf380c05241380f353edb51f904d9c650a2ed665ffbbe0766
|
data/README.md
CHANGED
|
@@ -10,7 +10,9 @@ gem 'nap'
|
|
|
10
10
|
require 'rest'
|
|
11
11
|
require 'json'
|
|
12
12
|
|
|
13
|
-
response = REST.get(
|
|
13
|
+
response = REST.get(
|
|
14
|
+
'https://example.com/timelines/friends.json',
|
|
15
|
+
{},
|
|
14
16
|
{:username => '_evan', :password => 'buttonscat'}
|
|
15
17
|
)
|
|
16
18
|
if response.ok?
|
|
@@ -71,7 +73,13 @@ Nap couldn't be the shining beacon in the eternal darkness without help from:
|
|
|
71
73
|
|
|
72
74
|
For all other great human beings, please visit the GitHub contributors page.
|
|
73
75
|
|
|
74
|
-
## Changes from 1.
|
|
76
|
+
## Changes from 1.1.1 to 1.2.0
|
|
77
|
+
|
|
78
|
+
* We no longer bundle cacert.pem because it's dangerous when it's not updated frequently enough, that's a job for the Ruby distribution or the operating system.
|
|
79
|
+
* Changes the default for the `tls_verify:` and `verify_ssl:` options to `true` instead of `false` to make it harder to accidentally make a connection where TLS certs are not verified.
|
|
80
|
+
* Modernizes the code a bit to we're sure it runs on Ruby 3.3 and 4.0.
|
|
81
|
+
|
|
82
|
+
## Changes from 1.1.0 to 1.1.1
|
|
75
83
|
|
|
76
84
|
* Updated cacert.pem.
|
|
77
85
|
|
data/lib/rest/error.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'net/http'
|
|
2
4
|
|
|
3
5
|
module REST
|
|
@@ -23,19 +25,19 @@ module REST
|
|
|
23
25
|
# This constant can be used to rescue only the known `Timeout` error classes.
|
|
24
26
|
module Timeout
|
|
25
27
|
def self.class_names
|
|
26
|
-
%w
|
|
28
|
+
%w[
|
|
27
29
|
Errno::ETIMEDOUT
|
|
28
30
|
Timeout::Error
|
|
29
31
|
Net::OpenTimeout
|
|
30
32
|
Net::ReadTimeout
|
|
31
|
-
|
|
33
|
+
]
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
# This constant can be used to rescue only the known `Connection` error classes.
|
|
36
38
|
module Connection
|
|
37
39
|
def self.class_names
|
|
38
|
-
%w
|
|
40
|
+
%w[
|
|
39
41
|
EOFError
|
|
40
42
|
Errno::ECONNABORTED
|
|
41
43
|
Errno::ECONNREFUSED
|
|
@@ -46,38 +48,34 @@ module REST
|
|
|
46
48
|
Errno::ENETUNREACH
|
|
47
49
|
SocketError
|
|
48
50
|
OpenSSL::SSL::SSLError
|
|
49
|
-
|
|
51
|
+
]
|
|
50
52
|
end
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
# This constant can be used to rescue only the known `Protocol` error classes.
|
|
54
56
|
module Protocol
|
|
55
57
|
def self.class_names
|
|
56
|
-
%w
|
|
58
|
+
%w[
|
|
57
59
|
Net::HTTPBadResponse
|
|
58
60
|
Net::HTTPHeaderSyntaxError
|
|
59
61
|
Net::ProtocolError
|
|
60
62
|
Zlib::GzipFile::Error
|
|
61
|
-
|
|
63
|
+
]
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
private
|
|
66
|
-
|
|
67
67
|
[Timeout, Connection, Protocol].each do |mod|
|
|
68
68
|
mod.send(:include, Error)
|
|
69
69
|
|
|
70
70
|
# Collect all the error classes that exist at runtime.
|
|
71
71
|
def mod.classes
|
|
72
72
|
class_names.map do |name|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
current.const_get(const)
|
|
77
|
-
end
|
|
78
|
-
rescue NameError
|
|
79
|
-
nil
|
|
73
|
+
# MRI < 2 does not support full constant paths for `Object.const_get`.
|
|
74
|
+
name.split('::').inject(Object) do |current, const|
|
|
75
|
+
current.const_get(const)
|
|
80
76
|
end
|
|
77
|
+
rescue NameError
|
|
78
|
+
nil
|
|
81
79
|
end.compact
|
|
82
80
|
end
|
|
83
81
|
|
data/lib/rest/request.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'uri'
|
|
2
4
|
require 'net/http'
|
|
5
|
+
require 'net/https'
|
|
3
6
|
|
|
4
7
|
module REST
|
|
5
8
|
# Request holds a HTTP request
|
|
6
9
|
class Request
|
|
7
10
|
attr_accessor :verb, :url, :body, :headers, :options, :request
|
|
8
|
-
|
|
11
|
+
|
|
9
12
|
# * <tt>verb</tt>: The verb to use in the request, either :get, :head, :patch, :put, or :post
|
|
10
13
|
# * <tt>url</tt>: The URL to send the request to, must be a URI instance
|
|
11
14
|
# * <tt>body</tt>: The body to use in the request
|
|
@@ -13,9 +16,9 @@ module REST
|
|
|
13
16
|
# * <tt>options</tt>: A hash of additional options
|
|
14
17
|
# * <tt>username</tt>: Username to use for basic authentication
|
|
15
18
|
# * <tt>password</tt>: Password to use for basic authentication
|
|
16
|
-
# * <tt>tls_verify/verify_ssl</tt>:
|
|
17
|
-
# * <tt>tls_ca_file</tt>: Use a specific file for CA certificates instead of the
|
|
18
|
-
#
|
|
19
|
+
# * <tt>tls_verify/verify_ssl</tt>: Disable CA verification when you really don't want it
|
|
20
|
+
# * <tt>tls_ca_file</tt>: Use a specific file for CA certificates instead of the system
|
|
21
|
+
# provided bundle, for example when using your own internal CA chain.
|
|
19
22
|
# * <tt>tls_key_and_certificate_file</tt>: The client key and certificate file to use for this
|
|
20
23
|
# request
|
|
21
24
|
# * <tt>tls_certificate</tt>: The client certficate to use for this request
|
|
@@ -31,12 +34,14 @@ module REST
|
|
|
31
34
|
#
|
|
32
35
|
# request = REST::Request.new(:post,
|
|
33
36
|
# URI.parse('http://example.com/pigeons'),
|
|
34
|
-
# {'name' => '
|
|
37
|
+
# {'name' => 'Homer'}.to_json,
|
|
35
38
|
# {'Accept' => 'application/json, */*', 'Content-Type' => 'application/json; charset=utf-8'}
|
|
36
39
|
# )
|
|
37
40
|
#
|
|
38
41
|
# # Pass a block to configure the underlying +Net::HTTP+ request.
|
|
39
|
-
# request = REST::Request.new(
|
|
42
|
+
# request = REST::Request.new(
|
|
43
|
+
# :get, URI.parse('http://example.com/pigeons/largest')
|
|
44
|
+
# ) do |http_request|
|
|
40
45
|
# http_request.open_timeout = 15 # seconds
|
|
41
46
|
# end
|
|
42
47
|
#
|
|
@@ -45,30 +50,32 @@ module REST
|
|
|
45
50
|
# request = REST::Request.new(:put,
|
|
46
51
|
# URI.parse('http://example.com/pigeons/1'),
|
|
47
52
|
# {'name' => 'Homer'}.to_json,
|
|
48
|
-
# {
|
|
49
|
-
#
|
|
53
|
+
# {
|
|
54
|
+
# 'Accept' => 'application/json, */*',
|
|
55
|
+
# 'Content-Type' => 'application/json; charset=utf-8'
|
|
56
|
+
# },
|
|
57
|
+
# { username: 'Admin', password: 'secret'}
|
|
50
58
|
# )
|
|
51
59
|
#
|
|
52
60
|
# == TLS / SSL examples
|
|
53
61
|
#
|
|
54
62
|
# # Use a client key and certificate
|
|
55
63
|
# request = REST::Request.new(:get, URI.parse('https://example.com/pigeons/1'), nil, {}, {
|
|
56
|
-
# :
|
|
64
|
+
# tls_key_and_certificate_file: '/home/alice/keys/example.pem'
|
|
57
65
|
# })
|
|
58
66
|
#
|
|
59
67
|
# # Use a client certificate and key from a specific location
|
|
60
68
|
# key_and_certificate = File.read('/home/alice/keys/example.pem')
|
|
61
69
|
# request = REST::Request.new(:get, URI.parse('https://example.com/pigeons/1'), nil, {}, {
|
|
62
|
-
# :
|
|
63
|
-
# :
|
|
70
|
+
# tls_key: OpenSSL::PKey::RSA.new(key_and_certificate),
|
|
71
|
+
# tls_certificate: OpenSSL::X509::Certificate.new(key_and_certificate)
|
|
64
72
|
# })
|
|
65
73
|
#
|
|
66
74
|
# # Verify the server certificate against a specific certificate
|
|
67
75
|
# request = REST::Request.new(:get, URI.parse('https://example.com/pigeons/1'), nil, {}, {
|
|
68
|
-
# :
|
|
69
|
-
# :tls_ca_file => '/home/alice/keys/example.pem'
|
|
76
|
+
# tls_ca_file: '/home/alice/keys/example.pem'
|
|
70
77
|
# })
|
|
71
|
-
def initialize(verb, url, body=nil, headers={}, options={}, &configure_block)
|
|
78
|
+
def initialize(verb, url, body = nil, headers = {}, options = {}, &configure_block)
|
|
72
79
|
@verb = verb
|
|
73
80
|
@url = url
|
|
74
81
|
@body = body
|
|
@@ -76,77 +83,68 @@ module REST
|
|
|
76
83
|
@options = options
|
|
77
84
|
@configure_block = configure_block
|
|
78
85
|
end
|
|
79
|
-
|
|
86
|
+
|
|
80
87
|
# Returns the path (including the query) for the request
|
|
81
88
|
def path
|
|
82
89
|
[url.path.empty? ? '/' : url.path, url.query].compact.join('?')
|
|
83
90
|
end
|
|
84
|
-
|
|
91
|
+
|
|
85
92
|
def proxy_env
|
|
86
93
|
{
|
|
87
|
-
'http'
|
|
88
|
-
'https' => ENV['HTTPS_PROXY'] || ENV
|
|
94
|
+
'http' => ENV['HTTP_PROXY'] || ENV.fetch('http_proxy', nil),
|
|
95
|
+
'https' => ENV['HTTPS_PROXY'] || ENV.fetch('https_proxy', nil)
|
|
89
96
|
}
|
|
90
97
|
end
|
|
91
|
-
|
|
98
|
+
|
|
92
99
|
def proxy_settings
|
|
93
100
|
proxy_env[url.scheme] ? URI.parse(proxy_env[url.scheme]) : nil
|
|
94
101
|
end
|
|
95
|
-
|
|
102
|
+
|
|
96
103
|
def http_proxy
|
|
97
|
-
if settings = proxy_settings
|
|
104
|
+
if (settings = proxy_settings)
|
|
98
105
|
Net::HTTP.Proxy(settings.host, settings.port, settings.user, settings.password)
|
|
99
106
|
end
|
|
100
107
|
end
|
|
101
|
-
|
|
108
|
+
|
|
102
109
|
# Configures and returns a new <tt>Net::HTTP</tt> request object
|
|
103
110
|
def http_request
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
http_request =
|
|
112
|
+
if http_proxy
|
|
113
|
+
http_proxy.new(url.host, url.port)
|
|
114
|
+
else
|
|
115
|
+
Net::HTTP.new(url.host, url.port)
|
|
116
|
+
end
|
|
117
|
+
|
|
110
118
|
# enable SSL/TLS
|
|
111
119
|
if url.scheme == 'https'
|
|
112
|
-
require 'net/https'
|
|
113
|
-
require 'openssl'
|
|
114
120
|
Error::Connection.extend_classes!
|
|
115
|
-
|
|
121
|
+
|
|
116
122
|
http_request.use_ssl = true
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
http_request.enable_post_connection_check = true
|
|
121
|
-
end
|
|
122
|
-
# from http://curl.haxx.se/ca/cacert.pem
|
|
123
|
-
http_request.ca_file = options[:tls_ca_file] || File.expand_path('../../../support/cacert.pem', __FILE__)
|
|
124
|
-
http_request.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
125
|
-
else
|
|
126
|
-
http_request.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
127
|
-
end
|
|
128
|
-
|
|
123
|
+
http_request.ca_file = options[:tls_ca_file]
|
|
124
|
+
http_request.verify_mode = verify_mode
|
|
125
|
+
|
|
129
126
|
if options[:tls_key_and_certificate_file]
|
|
130
127
|
key_and_certificate = File.read(options[:tls_key_and_certificate_file])
|
|
131
128
|
options[:tls_key] = OpenSSL::PKey::RSA.new(key_and_certificate)
|
|
132
129
|
options[:tls_certificate] = OpenSSL::X509::Certificate.new(key_and_certificate)
|
|
133
130
|
end
|
|
134
|
-
|
|
135
|
-
if options[:tls_key]
|
|
131
|
+
|
|
132
|
+
if options[:tls_key] && options[:tls_certificate]
|
|
136
133
|
http_request.key = options[:tls_key]
|
|
137
134
|
http_request.cert = options[:tls_certificate]
|
|
138
135
|
elsif options[:tls_key] || options[:tls_certificate]
|
|
139
|
-
raise
|
|
136
|
+
raise(
|
|
137
|
+
ArgumentError,
|
|
138
|
+
'Please specify both the certificate and private key (:tls_key and :tls_certificate)'
|
|
139
|
+
)
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
end
|
|
146
|
-
|
|
142
|
+
|
|
143
|
+
@configure_block&.call(http_request)
|
|
144
|
+
|
|
147
145
|
http_request
|
|
148
146
|
end
|
|
149
|
-
|
|
147
|
+
|
|
150
148
|
def request_for_verb
|
|
151
149
|
case verb
|
|
152
150
|
when :get
|
|
@@ -156,11 +154,12 @@ module REST
|
|
|
156
154
|
when :delete
|
|
157
155
|
Net::HTTP::Delete.new(path, headers)
|
|
158
156
|
when :patch
|
|
159
|
-
|
|
160
|
-
Net::HTTP::Patch.new(path, headers)
|
|
161
|
-
else
|
|
157
|
+
unless defined?(Net::HTTP::Patch)
|
|
162
158
|
raise ArgumentError, "This version of the Ruby standard library doesn't support PATCH"
|
|
163
159
|
end
|
|
160
|
+
|
|
161
|
+
Net::HTTP::Patch.new(path, headers)
|
|
162
|
+
|
|
164
163
|
when :put
|
|
165
164
|
Net::HTTP::Put.new(path, headers)
|
|
166
165
|
when :post
|
|
@@ -169,28 +168,44 @@ module REST
|
|
|
169
168
|
raise ArgumentError, "Unknown HTTP verb `#{verb}'"
|
|
170
169
|
end
|
|
171
170
|
end
|
|
172
|
-
|
|
171
|
+
|
|
173
172
|
# Performs the actual request and returns a REST::Response object with the response
|
|
174
173
|
def perform
|
|
175
174
|
self.request = request_for_verb
|
|
176
175
|
request.body = body
|
|
177
|
-
|
|
178
|
-
if options[:username]
|
|
176
|
+
|
|
177
|
+
if options[:username] && options[:password]
|
|
179
178
|
request.basic_auth(options[:username], options[:password])
|
|
180
179
|
end
|
|
181
|
-
|
|
180
|
+
|
|
182
181
|
http_request = http_request()
|
|
183
182
|
response = http_request.start { |http| http.request(request) }
|
|
184
183
|
REST::Response.new(response.code, response.instance_variable_get('@header'), response.body)
|
|
185
184
|
end
|
|
186
|
-
|
|
185
|
+
|
|
187
186
|
# Shortcut for REST::Request.new(*args).perform.
|
|
188
187
|
#
|
|
189
188
|
# See new for options.
|
|
190
|
-
def self.perform(
|
|
191
|
-
request = new(
|
|
189
|
+
def self.perform(*, &)
|
|
190
|
+
request = new(*, &)
|
|
192
191
|
request.perform
|
|
193
192
|
end
|
|
193
|
+
|
|
194
|
+
private
|
|
195
|
+
|
|
196
|
+
def verify_mode
|
|
197
|
+
if verify_tls?
|
|
198
|
+
OpenSSL::SSL::VERIFY_PEER
|
|
199
|
+
else
|
|
200
|
+
OpenSSL::SSL::VERIFY_NONE
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def verify_tls?
|
|
205
|
+
return false if options[:tls_verify] == false
|
|
206
|
+
return false if options[:verify_ssl] == false
|
|
207
|
+
|
|
208
|
+
true
|
|
209
|
+
end
|
|
194
210
|
end
|
|
195
211
|
end
|
|
196
|
-
|
data/lib/rest/response.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module REST
|
|
2
4
|
# Response holds a HTTP response
|
|
3
5
|
class Response
|
|
@@ -19,28 +21,28 @@ module REST
|
|
|
19
21
|
[422, :unprocessable_entity],
|
|
20
22
|
[404, :not_found],
|
|
21
23
|
[500, :internal_server_error]
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
+
].freeze
|
|
25
|
+
|
|
24
26
|
attr_accessor :body, :headers, :status_code
|
|
25
|
-
|
|
27
|
+
|
|
26
28
|
# * <tt>status_code</tt>: The status code of the response (ie. 200 or '404')
|
|
27
29
|
# * <tt>headers</tt>: The headers of the response
|
|
28
30
|
# * <tt>body</tt>: The body of the response
|
|
29
|
-
def initialize(status_code, headers={}, body='')
|
|
31
|
+
def initialize(status_code, headers = {}, body = '')
|
|
30
32
|
@status_code = status_code.to_i
|
|
31
33
|
@headers = headers
|
|
32
34
|
@body = body
|
|
33
35
|
end
|
|
34
|
-
|
|
36
|
+
|
|
35
37
|
CODES.each do |code, name|
|
|
36
38
|
define_method "#{name}?" do
|
|
37
39
|
status_code == code
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
|
-
|
|
42
|
+
|
|
41
43
|
# Returns _true_ when the status code is in the 2XX range. Returns false otherwise.
|
|
42
44
|
def success?
|
|
43
|
-
|
|
45
|
+
status_code.to_s =~ /2../ ? true : false
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
|
-
end
|
|
48
|
+
end
|
data/lib/rest.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'uri'
|
|
2
4
|
|
|
3
5
|
# REST is basically a convenience wrapper around Net::HTTP. It defines a simple and consistant API
|
|
@@ -7,8 +9,8 @@ require 'uri'
|
|
|
7
9
|
# requests. See REST::Error for a complete discussion of options.
|
|
8
10
|
module REST
|
|
9
11
|
# Library version
|
|
10
|
-
VERSION = '1.
|
|
11
|
-
|
|
12
|
+
VERSION = '1.2.0.pre'
|
|
13
|
+
|
|
12
14
|
# Performs a GET on a resource. See REST::Request.new for a complete discussion of options.
|
|
13
15
|
#
|
|
14
16
|
# response = REST.get('http://example.com/pigeons/12',
|
|
@@ -20,10 +22,10 @@ module REST
|
|
|
20
22
|
# else
|
|
21
23
|
# puts "Couldn't fetch your pigeon (#{response.status_code})"
|
|
22
24
|
# end
|
|
23
|
-
def self.get(uri, headers={}, options={}, &
|
|
24
|
-
REST::Request.perform(:get, URI.parse(uri), nil, headers, options, &
|
|
25
|
+
def self.get(uri, headers = {}, options = {}, &)
|
|
26
|
+
REST::Request.perform(:get, URI.parse(uri), nil, headers, options, &)
|
|
25
27
|
end
|
|
26
|
-
|
|
28
|
+
|
|
27
29
|
# Performs a HEAD on a resource. See REST::Request.new for a complete discussion of options.
|
|
28
30
|
#
|
|
29
31
|
# response = REST.head('http://example.com/pigeons/12')
|
|
@@ -34,8 +36,8 @@ module REST
|
|
|
34
36
|
# else
|
|
35
37
|
# puts "Couldn't fetch your pigeon (#{response.status_code})"
|
|
36
38
|
# end
|
|
37
|
-
def self.head(uri, headers={}, options={}, &
|
|
38
|
-
REST::Request.perform(:head, URI.parse(uri), nil, headers, options, &
|
|
39
|
+
def self.head(uri, headers = {}, options = {}, &)
|
|
40
|
+
REST::Request.perform(:head, URI.parse(uri), nil, headers, options, &)
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
# Performs a DELETE on a resource. See REST::Request.new for a complete discussion of options.
|
|
@@ -48,10 +50,10 @@ module REST
|
|
|
48
50
|
# else
|
|
49
51
|
# puts "Couldn't delete your pigeon (#{response.status_code})"
|
|
50
52
|
# end
|
|
51
|
-
def self.delete(uri, headers={}, options={}, &
|
|
52
|
-
REST::Request.perform(:delete, URI.parse(uri), nil, headers, options, &
|
|
53
|
+
def self.delete(uri, headers = {}, options = {}, &)
|
|
54
|
+
REST::Request.perform(:delete, URI.parse(uri), nil, headers, options, &)
|
|
53
55
|
end
|
|
54
|
-
|
|
56
|
+
|
|
55
57
|
# Performs a PATCH on a resource. See REST::Request.new for a complete discussion of options.
|
|
56
58
|
#
|
|
57
59
|
# response = REST.patch('http://example.com/pigeons/12',
|
|
@@ -64,10 +66,10 @@ module REST
|
|
|
64
66
|
# puts "Couldn't rename your pigeon (#{response.status_code})"
|
|
65
67
|
# puts XML.parse(response.body).reason
|
|
66
68
|
# end
|
|
67
|
-
def self.patch(uri, body, headers={}, options={}, &
|
|
68
|
-
REST::Request.perform(:patch, URI.parse(uri), body, headers, options, &
|
|
69
|
+
def self.patch(uri, body, headers = {}, options = {}, &)
|
|
70
|
+
REST::Request.perform(:patch, URI.parse(uri), body, headers, options, &)
|
|
69
71
|
end
|
|
70
|
-
|
|
72
|
+
|
|
71
73
|
# Performs a PUT on a resource. See REST::Request.new for a complete discussion of options.
|
|
72
74
|
#
|
|
73
75
|
# response = REST.put('http://example.com/pigeons/12',
|
|
@@ -80,10 +82,10 @@ module REST
|
|
|
80
82
|
# puts "Couldn't replace your pigeon (#{response.status_code})"
|
|
81
83
|
# puts XML.parse(response.body).reason
|
|
82
84
|
# end
|
|
83
|
-
def self.put(uri, body, headers={}, options={}, &
|
|
84
|
-
REST::Request.perform(:put, URI.parse(uri), body, headers, options, &
|
|
85
|
+
def self.put(uri, body, headers = {}, options = {}, &)
|
|
86
|
+
REST::Request.perform(:put, URI.parse(uri), body, headers, options, &)
|
|
85
87
|
end
|
|
86
|
-
|
|
88
|
+
|
|
87
89
|
# Performs a POST on a resource. See REST::Request.new for a complete discussion of options.
|
|
88
90
|
#
|
|
89
91
|
# response = REST.post('http://example.com/pigeons',
|
|
@@ -96,11 +98,11 @@ module REST
|
|
|
96
98
|
# puts "Couldn't create your pigeon (#{response.status_code})"
|
|
97
99
|
# puts XML.parse(response.body).reason
|
|
98
100
|
# end
|
|
99
|
-
def self.post(uri, body, headers={}, options={}, &
|
|
100
|
-
REST::Request.perform(:post, URI.parse(uri), body, headers, options, &
|
|
101
|
+
def self.post(uri, body, headers = {}, options = {}, &)
|
|
102
|
+
REST::Request.perform(:post, URI.parse(uri), body, headers, options, &)
|
|
101
103
|
end
|
|
102
104
|
end
|
|
103
105
|
|
|
104
|
-
require File.expand_path('
|
|
105
|
-
require File.expand_path('
|
|
106
|
-
require File.expand_path('
|
|
106
|
+
require File.expand_path('rest/error', __dir__)
|
|
107
|
+
require File.expand_path('rest/request', __dir__)
|
|
108
|
+
require File.expand_path('rest/response', __dir__)
|
metadata
CHANGED
|
@@ -1,43 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nap
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0.pre
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Manfred Stienstra
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: rake
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '12'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '12'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: peck
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.5'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.5'
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
41
12
|
description: |2
|
|
42
13
|
Nap is a really simple REST library. It allows you to perform HTTP requests
|
|
43
14
|
with minimal amounts of code.
|
|
@@ -45,8 +16,8 @@ email: manfred@fngtps.com
|
|
|
45
16
|
executables: []
|
|
46
17
|
extensions: []
|
|
47
18
|
extra_rdoc_files:
|
|
48
|
-
- README.md
|
|
49
19
|
- LICENSE
|
|
20
|
+
- README.md
|
|
50
21
|
files:
|
|
51
22
|
- LICENSE
|
|
52
23
|
- README.md
|
|
@@ -54,12 +25,11 @@ files:
|
|
|
54
25
|
- lib/rest/error.rb
|
|
55
26
|
- lib/rest/request.rb
|
|
56
27
|
- lib/rest/response.rb
|
|
57
|
-
- support/cacert.pem
|
|
58
28
|
homepage: https://github.com/Fingertips/nap
|
|
59
29
|
licenses:
|
|
60
30
|
- MIT
|
|
61
|
-
metadata:
|
|
62
|
-
|
|
31
|
+
metadata:
|
|
32
|
+
rubygems_mfa_required: 'true'
|
|
63
33
|
rdoc_options:
|
|
64
34
|
- "--charset=utf-8"
|
|
65
35
|
require_paths:
|
|
@@ -68,15 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
68
38
|
requirements:
|
|
69
39
|
- - ">="
|
|
70
40
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: '
|
|
41
|
+
version: '3.3'
|
|
72
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
43
|
requirements:
|
|
74
44
|
- - ">="
|
|
75
45
|
- !ruby/object:Gem::Version
|
|
76
46
|
version: '0'
|
|
77
47
|
requirements: []
|
|
78
|
-
rubygems_version:
|
|
79
|
-
signing_key:
|
|
48
|
+
rubygems_version: 4.0.10
|
|
80
49
|
specification_version: 4
|
|
81
50
|
summary: Nap is a really simple REST library.
|
|
82
51
|
test_files: []
|