From 03b96306176bfc328929cb422ae61d37ee071310 Mon Sep 17 00:00:00 2001 From: Marc G Gauthier Date: Fri, 19 Aug 2011 11:11:17 +0200 Subject: Do not try to use as a parameter elements that are not acceptable --- activeresource/lib/active_resource/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 693bd0592e..f88772a7ff 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -955,7 +955,7 @@ module ActiveResource prefix_options, query_options = {}, {} (options || {}).each do |key, value| - next if key.blank? + next if key.blank? || [Fixnum, Date, Time, Float].include?(key.class) (prefix_parameters.include?(key.to_sym) ? prefix_options : query_options)[key.to_sym] = value end -- cgit v1.2.3 From 28d605ff7fe1de0ae9b3bcdb48ac6209859c7ecf Mon Sep 17 00:00:00 2001 From: Marc G Gauthier Date: Thu, 1 Sep 2011 18:26:29 +0200 Subject: Do not use objects that don't respond to to_sym (integers, floats, dates...) as parameters --- activeresource/lib/active_resource/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index f88772a7ff..990d9a38dd 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -955,7 +955,7 @@ module ActiveResource prefix_options, query_options = {}, {} (options || {}).each do |key, value| - next if key.blank? || [Fixnum, Date, Time, Float].include?(key.class) + next if key.blank? || !key.respond_to?(:to_sym) (prefix_parameters.include?(key.to_sym) ? prefix_options : query_options)[key.to_sym] = value end -- cgit v1.2.3 From a06d17480ff533fbc375df219a4e70886fb4899b Mon Sep 17 00:00:00 2001 From: John Mileham Date: Tue, 23 Aug 2011 19:04:35 -0400 Subject: ActiveResource shouldn't rely on the presence of Content-Length --- activeresource/lib/active_resource/base.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 693bd0592e..236dc565f3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1357,7 +1357,9 @@ module ActiveResource end def load_attributes_from_response(response) - if !response['Content-Length'].blank? && response['Content-Length'] != "0" && !response.body.nil? && response.body.strip.size > 0 + if (response_code_allows_body?(response.code) && + (response['Content-Length'].nil? || response['Content-Length'] != "0") && + !response.body.nil? && response.body.strip.size > 0) load(self.class.format.decode(response.body), true) @persisted = true end @@ -1381,6 +1383,12 @@ module ActiveResource end private + + # Determine whether the response is allowed to have a body per HTTP 1.1 spec section 4.4.1 + def response_code_allows_body?(c) + !((100..199).include?(c) || [204,304].include?(c)) + end + # Tries to find a resource for a given collection name; if it fails, then the resource is created def find_or_create_resource_for_collection(name) find_or_create_resource_for(ActiveSupport::Inflector.singularize(name.to_s)) -- cgit v1.2.3 From 41365a8275dcb6d2e2fbe21ae2b2dfc52db19c1f Mon Sep 17 00:00:00 2001 From: Colin Shield & Ian Lesperance Date: Wed, 28 Sep 2011 15:23:47 -0700 Subject: Fixed digest authentication for requests with a query string [#3158] --- activeresource/lib/active_resource/connection.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index d923204dde..592fca96a4 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -238,8 +238,11 @@ module ActiveResource def digest_auth_header(http_method, uri) params = extract_params_from_response + request_uri = uri.path + request_uri << "?#{uri.query}" if uri.query + ha1 = Digest::MD5.hexdigest("#{@user}:#{params['realm']}:#{@password}") - ha2 = Digest::MD5.hexdigest("#{http_method.to_s.upcase}:#{uri.path}") + ha2 = Digest::MD5.hexdigest("#{http_method.to_s.upcase}:#{request_uri}") params.merge!('cnonce' => client_nonce) request_digest = Digest::MD5.hexdigest([ha1, params['nonce'], "0", params['cnonce'], params['qop'], ha2].join(":")) -- cgit v1.2.3 From d4457dc32b4d5dc9fde6c852f55a0d43ee021282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Sep 2011 14:20:41 +0200 Subject: Provide read_attribute_for_serialization as the API to serialize attributes. --- activeresource/lib/active_resource/base.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 1ffd83b91d..03c4cc5b9e 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1384,6 +1384,10 @@ module ActiveResource private + def read_attribute_for_serialization(n) + attributes[n] + end + # Determine whether the response is allowed to have a body per HTTP 1.1 spec section 4.4.1 def response_code_allows_body?(c) !((100..199).include?(c) || [204,304].include?(c)) -- cgit v1.2.3 From a78a75d67a8072bc7613edbed548d4b865daadf8 Mon Sep 17 00:00:00 2001 From: Jim Herzberg Date: Tue, 11 Oct 2011 17:46:24 -0700 Subject: activeresource should treat HTTP status 307 as redirection, same as 301 and 302; added missing test cases for statii 301 and 302. --- activeresource/lib/active_resource/base.rb | 4 ++-- activeresource/lib/active_resource/connection.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 03c4cc5b9e..3fb8ce7790 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -170,8 +170,8 @@ module ActiveResource # 404 is just one of the HTTP error response codes that Active Resource will handle with its own exception. The # following HTTP response codes will also result in these exceptions: # - # * 200..399 - Valid response, no exception (other than 301, 302) - # * 301, 302 - ActiveResource::Redirection + # * 200..399 - Valid response, no exception (other than 301, 302 and 307) + # * 301, 302, 307 - ActiveResource::Redirection # * 400 - ActiveResource::BadRequest # * 401 - ActiveResource::UnauthorizedAccess # * 403 - ActiveResource::ForbiddenAccess diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 592fca96a4..73410c2d82 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -122,7 +122,7 @@ module ActiveResource # Handles response and error codes from the remote service. def handle_response(response) case response.code.to_i - when 301,302 + when 301,302,307 raise(Redirection.new(response)) when 200...400 response -- cgit v1.2.3 From b8bb5f44c8ba02786ed42d04f66641f236ef42c3 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 11 Oct 2011 21:01:11 -0700 Subject: Treat 303 See Other as a redirect response, too --- activeresource/lib/active_resource/base.rb | 4 ++-- activeresource/lib/active_resource/connection.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 3fb8ce7790..7b8afdca3c 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -170,8 +170,8 @@ module ActiveResource # 404 is just one of the HTTP error response codes that Active Resource will handle with its own exception. The # following HTTP response codes will also result in these exceptions: # - # * 200..399 - Valid response, no exception (other than 301, 302 and 307) - # * 301, 302, 307 - ActiveResource::Redirection + # * 200..399 - Valid response. No exceptions, other than these redirects: + # * 301, 302, 303, 307 - ActiveResource::Redirection # * 400 - ActiveResource::BadRequest # * 401 - ActiveResource::UnauthorizedAccess # * 403 - ActiveResource::ForbiddenAccess diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 73410c2d82..94839c8c25 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -122,7 +122,7 @@ module ActiveResource # Handles response and error codes from the remote service. def handle_response(response) case response.code.to_i - when 301,302,307 + when 301, 302, 303, 307 raise(Redirection.new(response)) when 200...400 response -- cgit v1.2.3 From b7cccae71e4c42415f8c0dab7b083ed7db54c0c1 Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Thu, 13 Oct 2011 16:27:10 -0300 Subject: improved ActiveResource's .element_path and .new_element_path methods documentation by specifing how .site should be declared in order to use prefix_options --- activeresource/lib/active_resource/base.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 03c4cc5b9e..fa5c4470eb 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -637,6 +637,10 @@ module ActiveResource # Post.element_path(1) # # => /posts/1.json # + # class Comment < ActiveResource::Base + # self.site = "http://37s.sunrise.i/posts/:post_id/" + # end + # # Comment.element_path(1, :post_id => 5) # # => /posts/5/comments/1.json # @@ -663,6 +667,10 @@ module ActiveResource # Post.new_element_path # # => /posts/new.json # + # class Comment < ActiveResource::Base + # self.site = "http://37s.sunrise.i/posts/:post_id/" + # end + # # Comment.collection_path(:post_id => 5) # # => /posts/5/comments/new.json def new_element_path(prefix_options = {}) -- cgit v1.2.3 From 9dc9db1c99bce6b4c478f0a587abcb7744f2ad5e Mon Sep 17 00:00:00 2001 From: Robert Ross Date: Mon, 21 Nov 2011 17:06:00 -0800 Subject: Fix missing single quote that was messing up syntax highlighting. --- activeresource/lib/active_resource/custom_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index c1931b2758..f7cb381711 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -23,7 +23,7 @@ module ActiveResource # self.site = "http://37s.sunrise.i:3000" # end # - # Person.new(:name => 'Ryan).post(:register) # POST /people/new/register.json + # Person.new(:name => 'Ryan').post(:register) # POST /people/new/register.json # # => { :id => 1, :name => 'Ryan' } # # Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.json -- cgit v1.2.3 From 93387e2e7c66fb34bde5442ad314c9c63729b75b Mon Sep 17 00:00:00 2001 From: lest Date: Wed, 30 Nov 2011 18:44:37 +0300 Subject: fix deprecation warnings in activeresource --- activeresource/lib/active_resource/base.rb | 4 +- .../lib/active_resource/custom_methods.rb | 48 +++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 10cc727bd9..93991ab6b3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1477,7 +1477,7 @@ module ActiveResource extend ActiveModel::Naming include CustomMethods, Observing, Validations include ActiveModel::Conversion - include ActiveModel::Serializers::JSON - include ActiveModel::Serializers::Xml + include ActiveModel::Serializable::JSON + include ActiveModel::Serializable::XML end end diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index f7cb381711..2a651dd48e 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -85,37 +85,35 @@ module ActiveResource end end - module InstanceMethods - def get(method_name, options = {}) - self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body) - end + def get(method_name, options = {}) + self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body) + end - def post(method_name, options = {}, body = nil) - request_body = body.blank? ? encode : body - if new? - connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers) - else - connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers) - end + def post(method_name, options = {}, body = nil) + request_body = body.blank? ? encode : body + if new? + connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers) + else + connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers) end + end - def put(method_name, options = {}, body = '') - connection.put(custom_method_element_url(method_name, options), body, self.class.headers) - end + def put(method_name, options = {}, body = '') + connection.put(custom_method_element_url(method_name, options), body, self.class.headers) + end - def delete(method_name, options = {}) - connection.delete(custom_method_element_url(method_name, options), self.class.headers) - end + def delete(method_name, options = {}) + connection.delete(custom_method_element_url(method_name, options), self.class.headers) + end - private - def custom_method_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}" - end + private + def custom_method_element_url(method_name, options = {}) + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}" + end - def custom_method_new_element_url(method_name, options = {}) - "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}" - end - end + def custom_method_new_element_url(method_name, options = {}) + "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.__send__(:query_string, options)}" + end end end -- cgit v1.2.3 From 5b2eb64ceb08cd005dc06b721935de5853971473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Nov 2011 18:38:28 +0100 Subject: Revert "Implement ArraySerializer and move old serialization API to a new namespace." This reverts commit 8896b4fdc8a543157cdf4dfc378607ebf6c10ab0. Conflicts: activemodel/lib/active_model.rb activemodel/lib/active_model/serializable.rb activemodel/lib/active_model/serializer.rb activemodel/test/cases/serializer_test.rb --- activeresource/lib/active_resource/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 93991ab6b3..10cc727bd9 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1477,7 +1477,7 @@ module ActiveResource extend ActiveModel::Naming include CustomMethods, Observing, Validations include ActiveModel::Conversion - include ActiveModel::Serializable::JSON - include ActiveModel::Serializable::XML + include ActiveModel::Serializers::JSON + include ActiveModel::Serializers::Xml end end -- cgit v1.2.3 From 9811c3624a3f5881069093ee55d53be2457d4c03 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 1 Dec 2011 00:32:37 +0530 Subject: fix bad nodocs --- activeresource/lib/active_resource/exceptions.rb | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'activeresource/lib/active_resource') diff --git a/activeresource/lib/active_resource/exceptions.rb b/activeresource/lib/active_resource/exceptions.rb index 6b953b28ad..51bede3bd0 100644 --- a/activeresource/lib/active_resource/exceptions.rb +++ b/activeresource/lib/active_resource/exceptions.rb @@ -33,35 +33,45 @@ module ActiveResource # 3xx Redirection class Redirection < ConnectionError # :nodoc: - def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end + def to_s + response['Location'] ? "#{super} => #{response['Location']}" : super + end end - # Raised when ... - class MissingPrefixParam < ArgumentError; end # :nodoc: + class MissingPrefixParam < ArgumentError # :nodoc: + end # 4xx Client Error - class ClientError < ConnectionError; end # :nodoc: + class ClientError < ConnectionError # :nodoc: + end # 400 Bad Request - class BadRequest < ClientError; end # :nodoc + class BadRequest < ClientError # :nodoc: + end # 401 Unauthorized - class UnauthorizedAccess < ClientError; end # :nodoc + class UnauthorizedAccess < ClientError # :nodoc: + end # 403 Forbidden - class ForbiddenAccess < ClientError; end # :nodoc + class ForbiddenAccess < ClientError # :nodoc: + end # 404 Not Found - class ResourceNotFound < ClientError; end # :nodoc: + class ResourceNotFound < ClientError # :nodoc: + end # 409 Conflict - class ResourceConflict < ClientError; end # :nodoc: + class ResourceConflict < ClientError # :nodoc: + end # 410 Gone - class ResourceGone < ClientError; end # :nodoc: + class ResourceGone < ClientError # :nodoc: + end # 5xx Server Error - class ServerError < ConnectionError; end # :nodoc: + class ServerError < ConnectionError # :nodoc: + end # 405 Method Not Allowed class MethodNotAllowed < ClientError # :nodoc: -- cgit v1.2.3