diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-09-28 07:57:26 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-28 11:38:35 +0800 |
commit | 71acc2737aa346ee57f9fc21252a508ae83367a4 (patch) | |
tree | ddb12b7813d20b4003c874604620d0aef7ace31a /activeresource/lib/active_resource | |
parent | b7934afe326f8bba9cdcacdfac93062dff155efe (diff) | |
download | rails-71acc2737aa346ee57f9fc21252a508ae83367a4.tar.gz rails-71acc2737aa346ee57f9fc21252a508ae83367a4.tar.bz2 rails-71acc2737aa346ee57f9fc21252a508ae83367a4.zip |
Move uri parser to AS as URI.parser method to reuse it in AP and ARes.
Diffstat (limited to 'activeresource/lib/active_resource')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 17 | ||||
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 10 |
2 files changed, 12 insertions, 15 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index cd279d890e..b5b46d7431 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -12,6 +12,7 @@ require 'active_support/core_ext/object/duplicable' require 'set' require 'uri' +require 'active_support/core_ext/uri' require 'active_resource/exceptions' require 'active_resource/connection' require 'active_resource/formats' @@ -414,8 +415,8 @@ module ActiveResource @site = nil else @site = create_site_uri_from(site) - @user = uri_parser.unescape(@site.user) if @site.user - @password = uri_parser.unescape(@site.password) if @site.password + @user = URI.parser.unescape(@site.user) if @site.user + @password = URI.parser.unescape(@site.password) if @site.password end end @@ -588,7 +589,7 @@ module ActiveResource # Default value is <tt>site.path</tt>. def prefix=(value = '/') # Replace :placeholders with '#{embedded options[:lookups]}' - prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.escape options[#{key}].to_s}" } + prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.parser.escape options[#{key}].to_s}" } # Clear prefix parameters in case they have been cached @prefix_parameters = nil @@ -635,7 +636,7 @@ module ActiveResource check_prefix_options(prefix_options) prefix_options, query_options = split_options(prefix_options) if query_options.nil? - "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}" + "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}.#{format.extension}#{query_string(query_options)}" end # Gets the new element path for REST resources. @@ -916,12 +917,12 @@ module ActiveResource # Accepts a URI and creates the site URI from that. def create_site_uri_from(site) - site.is_a?(URI) ? site.dup : uri_parser.parse(site) + site.is_a?(URI) ? site.dup : URI.parser.parse(site) end # Accepts a URI and creates the proxy URI from that. def create_proxy_uri_from(proxy) - proxy.is_a?(URI) ? proxy.dup : uri_parser.parse(proxy) + proxy.is_a?(URI) ? proxy.dup : URI.parser.parse(proxy) end # contains a set of the current prefix parameters. @@ -946,10 +947,6 @@ module ActiveResource [ prefix_options, query_options ] end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end attr_accessor :attributes #:nodoc: diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index c587225e24..480f2fbecb 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/benchmark' +require 'active_support/core_ext/uri' require 'net/https' require 'date' require 'time' @@ -31,21 +32,20 @@ module ActiveResource def initialize(site, format = ActiveResource::Formats::XmlFormat) raise ArgumentError, 'Missing site URI' unless site @user = @password = nil - @uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI self.site = site self.format = format end # Set URI for remote service. def site=(site) - @site = site.is_a?(URI) ? site : @uri_parser.parse(site) - @user = @uri_parser.unescape(@site.user) if @site.user - @password = @uri_parser.unescape(@site.password) if @site.password + @site = site.is_a?(URI) ? site : URI.parser.parse(site) + @user = URI.parser.unescape(@site.user) if @site.user + @password = URI.parser.unescape(@site.password) if @site.password end # Set the proxy for remote service. def proxy=(proxy) - @proxy = proxy.is_a?(URI) ? proxy : @uri_parser.parse(proxy) + @proxy = proxy.is_a?(URI) ? proxy : URI.parser.parse(proxy) end # Sets the user for remote service. |