activeresource 6.0.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/active_resource/base.rb +10 -11
- data/lib/active_resource/connection.rb +5 -6
- data/lib/active_resource/custom_methods.rb +1 -1
- data/lib/active_resource/http_mock.rb +26 -11
- data/lib/active_resource/inheriting_hash.rb +19 -0
- data/lib/active_resource/validations.rb +1 -1
- data/lib/active_resource/version.rb +2 -2
- data/lib/active_resource.rb +4 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95f17d4e9c32ac07705fd268b64bc8d2dbdff491b948c87339ab8b7bd054163e
|
4
|
+
data.tar.gz: 9b7ec268d567d641a25608f31d29e8a5675c8436b89448eaecd7a1e179dff587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 789a6c7d3dd6044c806e8496ebcdf422f0c8c21e64dc42d6e0352781b96070b8f190b0a42ce8171f920bd9d1057969f4599ef150c7be334da59e89c2d4ac10fb
|
7
|
+
data.tar.gz: 29df5673ea2374cfa8a282b47bce5ca4d800744add388ddd8baaab0d3fd157a835361049213b4640aeac5697a86b94247c407c1b19dcedd552c4d77bb15fa6bc
|
data/README.md
CHANGED
@@ -112,7 +112,7 @@ end
|
|
112
112
|
Active Resource is built on a standard JSON or XML format for requesting and submitting resources
|
113
113
|
over HTTP. It mirrors the RESTful routing built into Action Controller but will also work with any
|
114
114
|
other REST service that properly implements the protocol. REST uses HTTP, but unlike "typical" web
|
115
|
-
applications, it makes use of all the
|
115
|
+
applications, it makes use of all the verbs available in the HTTP specification:
|
116
116
|
|
117
117
|
* GET requests are used for finding and retrieving resources.
|
118
118
|
* POST requests are used to create new resources.
|
data/lib/active_resource/base.rb
CHANGED
@@ -11,7 +11,6 @@ require "active_support/core_ext/object/blank"
|
|
11
11
|
require "active_support/core_ext/object/to_query"
|
12
12
|
require "active_support/core_ext/object/duplicable"
|
13
13
|
require "set"
|
14
|
-
require "uri"
|
15
14
|
|
16
15
|
require "active_resource/connection"
|
17
16
|
require "active_resource/formats"
|
@@ -490,8 +489,8 @@ module ActiveResource
|
|
490
489
|
self._site = nil
|
491
490
|
else
|
492
491
|
self._site = create_site_uri_from(site)
|
493
|
-
self._user =
|
494
|
-
self._password =
|
492
|
+
self._user = URI_PARSER.unescape(_site.user) if _site.user
|
493
|
+
self._password = URI_PARSER.unescape(_site.password) if _site.password
|
495
494
|
end
|
496
495
|
end
|
497
496
|
|
@@ -750,7 +749,7 @@ module ActiveResource
|
|
750
749
|
# Default value is <tt>site.path</tt>.
|
751
750
|
def prefix=(value = "/")
|
752
751
|
# Replace :placeholders with '#{embedded options[:lookups]}'
|
753
|
-
prefix_call = value.gsub(/:\w+/) { |key| "\#{
|
752
|
+
prefix_call = value.gsub(/:\w+/) { |key| "\#{URI_PARSER.escape options[#{key}].to_s}" }
|
754
753
|
|
755
754
|
# Clear prefix parameters in case they have been cached
|
756
755
|
@prefix_parameters = nil
|
@@ -1072,13 +1071,13 @@ module ActiveResource
|
|
1072
1071
|
#
|
1073
1072
|
# Note.exists(1349) # => false
|
1074
1073
|
def exists?(id, options = {})
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1074
|
+
return false unless id
|
1075
|
+
|
1076
|
+
prefix_options, query_options = split_options(options[:params])
|
1077
|
+
path = element_path(id, prefix_options, query_options)
|
1078
|
+
response = connection.head(path, headers)
|
1079
|
+
|
1080
|
+
(200..206).include?(response.code.to_i)
|
1082
1081
|
rescue ActiveResource::ResourceNotFound, ActiveResource::ResourceGone
|
1083
1082
|
false
|
1084
1083
|
end
|
@@ -5,7 +5,6 @@ require "active_support/core_ext/object/inclusion"
|
|
5
5
|
require "net/https"
|
6
6
|
require "date"
|
7
7
|
require "time"
|
8
|
-
require "uri"
|
9
8
|
|
10
9
|
module ActiveResource
|
11
10
|
# Class to handle connections to remote web services.
|
@@ -43,8 +42,8 @@ module ActiveResource
|
|
43
42
|
def site=(site)
|
44
43
|
@site = site.is_a?(URI) ? site : URI.parse(site)
|
45
44
|
@ssl_options ||= {} if @site.is_a?(URI::HTTPS)
|
46
|
-
@user =
|
47
|
-
@password =
|
45
|
+
@user = URI_PARSER.unescape(@site.user) if @site.user
|
46
|
+
@password = URI_PARSER.unescape(@site.password) if @site.password
|
48
47
|
end
|
49
48
|
|
50
49
|
# Set the proxy for remote service.
|
@@ -173,8 +172,8 @@ module ActiveResource
|
|
173
172
|
|
174
173
|
def new_http
|
175
174
|
if @proxy
|
176
|
-
user =
|
177
|
-
password =
|
175
|
+
user = URI_PARSER.unescape(@proxy.user) if @proxy.user
|
176
|
+
password = URI_PARSER.unescape(@proxy.password) if @proxy.password
|
178
177
|
Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, user, password)
|
179
178
|
else
|
180
179
|
Net::HTTP.new(@site.host, @site.port)
|
@@ -211,7 +210,7 @@ module ActiveResource
|
|
211
210
|
|
212
211
|
# Builds headers for request to remote service.
|
213
212
|
def build_request_headers(headers, http_method, uri)
|
214
|
-
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers)
|
213
|
+
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers.to_hash)
|
215
214
|
end
|
216
215
|
|
217
216
|
def response_auth_header
|
@@ -119,7 +119,7 @@ module ActiveResource
|
|
119
119
|
|
120
120
|
private
|
121
121
|
def custom_method_element_url(method_name, options = {})
|
122
|
-
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
|
122
|
+
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{URI.encode_www_form_component(id.to_s)}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
|
123
123
|
end
|
124
124
|
|
125
125
|
def custom_method_new_element_url(method_name, options = {})
|
@@ -58,12 +58,12 @@ module ActiveResource
|
|
58
58
|
end
|
59
59
|
|
60
60
|
[ :post, :patch, :put, :get, :delete, :head ].each do |method|
|
61
|
-
# def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
62
|
-
# @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
|
61
|
+
# def post(path, request_headers = {}, body = nil, status = 200, response_headers = {}, options: {})
|
62
|
+
# @responses[Request.new(:post, path, nil, request_headers, options)] = Response.new(body || "", status, response_headers)
|
63
63
|
# end
|
64
64
|
module_eval <<-EOE, __FILE__, __LINE__ + 1
|
65
|
-
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
66
|
-
request = Request.new(:#{method}, path, nil, request_headers)
|
65
|
+
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {}, options = {})
|
66
|
+
request = Request.new(:#{method}, path, nil, request_headers, options)
|
67
67
|
response = Response.new(body || "", status, response_headers)
|
68
68
|
|
69
69
|
delete_duplicate_responses(request)
|
@@ -244,8 +244,8 @@ module ActiveResource
|
|
244
244
|
{ true => %w(post patch put),
|
245
245
|
false => %w(get delete head) }.each do |has_body, methods|
|
246
246
|
methods.each do |method|
|
247
|
-
# def post(path, body, headers)
|
248
|
-
# request = ActiveResource::Request.new(:post, path, body, headers)
|
247
|
+
# def post(path, body, headers, options = {})
|
248
|
+
# request = ActiveResource::Request.new(:post, path, body, headers, options)
|
249
249
|
# self.class.requests << request
|
250
250
|
# if response = self.class.responses.assoc(request)
|
251
251
|
# response[1]
|
@@ -254,8 +254,8 @@ module ActiveResource
|
|
254
254
|
# end
|
255
255
|
# end
|
256
256
|
module_eval <<-EOE, __FILE__, __LINE__ + 1
|
257
|
-
def #{method}(path, #{'body, ' if has_body}headers)
|
258
|
-
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers)
|
257
|
+
def #{method}(path, #{'body, ' if has_body}headers, options = {})
|
258
|
+
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers, options)
|
259
259
|
self.class.requests << request
|
260
260
|
if response = self.class.responses.assoc(request)
|
261
261
|
response[1]
|
@@ -279,19 +279,34 @@ module ActiveResource
|
|
279
279
|
class Request
|
280
280
|
attr_accessor :path, :method, :body, :headers
|
281
281
|
|
282
|
-
def initialize(method, path, body = nil, headers = {})
|
283
|
-
@method, @path, @body, @headers = method, path, body, headers
|
282
|
+
def initialize(method, path, body = nil, headers = {}, options = {})
|
283
|
+
@method, @path, @body, @headers, @options = method, path, body, headers, options
|
284
284
|
end
|
285
285
|
|
286
286
|
def ==(req)
|
287
|
-
|
287
|
+
same_path?(req) && method == req.method && headers_match?(req)
|
288
288
|
end
|
289
289
|
|
290
290
|
def to_s
|
291
291
|
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
|
292
292
|
end
|
293
293
|
|
294
|
+
# Removes query parameters from the path.
|
295
|
+
#
|
296
|
+
# @return [String] the path without query parameters
|
297
|
+
def remove_query_params_from_path
|
298
|
+
path.split("?").first
|
299
|
+
end
|
300
|
+
|
294
301
|
private
|
302
|
+
def same_path?(req)
|
303
|
+
if @options && @options[:omit_query_in_path]
|
304
|
+
remove_query_params_from_path == req.remove_query_params_from_path
|
305
|
+
else
|
306
|
+
path == req.path
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
295
310
|
def headers_match?(req)
|
296
311
|
# Ignore format header on equality if it's not defined
|
297
312
|
format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]
|
@@ -11,5 +11,24 @@ module ActiveResource
|
|
11
11
|
def [](key)
|
12
12
|
super || @parent_hash[key]
|
13
13
|
end
|
14
|
+
|
15
|
+
# Merges the flattened parent hash (if it's an InheritingHash)
|
16
|
+
# with ourself
|
17
|
+
def to_hash
|
18
|
+
@parent_hash.to_hash.merge(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# So we can see the merged object in IRB or the Rails console
|
22
|
+
def pretty_print(pp)
|
23
|
+
pp.pp_hash to_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
to_hash.inspect
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
inspect
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
@@ -160,7 +160,7 @@ module ActiveResource
|
|
160
160
|
# my_person.valid?
|
161
161
|
# # => false
|
162
162
|
#
|
163
|
-
def valid?
|
163
|
+
def valid?(context = nil)
|
164
164
|
run_callbacks :validate do
|
165
165
|
super
|
166
166
|
load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?
|
data/lib/active_resource.rb
CHANGED
@@ -23,6 +23,8 @@
|
|
23
23
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
24
|
#++
|
25
25
|
|
26
|
+
require "uri"
|
27
|
+
|
26
28
|
require "active_support"
|
27
29
|
require "active_model"
|
28
30
|
require "active_resource/exceptions"
|
@@ -31,6 +33,8 @@ require "active_resource/version"
|
|
31
33
|
module ActiveResource
|
32
34
|
extend ActiveSupport::Autoload
|
33
35
|
|
36
|
+
URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new
|
37
|
+
|
34
38
|
autoload :Base
|
35
39
|
autoload :Callbacks
|
36
40
|
autoload :Connection
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -135,11 +135,11 @@ licenses:
|
|
135
135
|
- MIT
|
136
136
|
metadata:
|
137
137
|
bug_tracker_uri: https://github.com/rails/activeresource/issues
|
138
|
-
changelog_uri: https://github.com/rails/activeresource/releases/tag/v6.
|
138
|
+
changelog_uri: https://github.com/rails/activeresource/releases/tag/v6.1.1
|
139
139
|
documentation_uri: http://rubydoc.info/gems/activeresource
|
140
|
-
source_code_uri: https://github.com/rails/activeresource/tree/v6.
|
140
|
+
source_code_uri: https://github.com/rails/activeresource/tree/v6.1.1
|
141
141
|
rubygems_mfa_required: 'true'
|
142
|
-
post_install_message:
|
142
|
+
post_install_message:
|
143
143
|
rdoc_options: []
|
144
144
|
require_paths:
|
145
145
|
- lib
|
@@ -154,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
158
|
-
signing_key:
|
157
|
+
rubygems_version: 3.5.11
|
158
|
+
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: REST modeling framework (part of Rails).
|
161
161
|
test_files: []
|