diff options
Diffstat (limited to 'activeresource/lib/active_resource/connection.rb')
-rw-r--r-- | activeresource/lib/active_resource/connection.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index e4e6da50c9..cf4681b25b 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -55,7 +55,7 @@ module ActiveResource # This class is used by ActiveResource::Base to interface with REST # services. class Connection - attr_reader :site + attr_reader :site, :user, :password attr_accessor :format class << self @@ -68,6 +68,7 @@ module ActiveResource # attribute to the URI for the remote resource service. def initialize(site, format = ActiveResource::Formats[:xml]) raise ArgumentError, 'Missing site URI' unless site + @user = @password = nil self.site = site self.format = format end @@ -75,6 +76,18 @@ module ActiveResource # Set URI for remote service. def site=(site) @site = site.is_a?(URI) ? site : URI.parse(site) + @user = @site.user if @site.user + @password = @site.password if @site.password + end + + # Set user for remote service. + def user=(user) + @user = user + end + + # Set password for remote service. + def password=(password) + @password = password end # Execute a GET request. @@ -166,9 +179,9 @@ module ActiveResource authorization_header.update(default_header).update(headers) end - # Sets authorization header; authentication information is pulled from credentials provided with site URI. + # Sets authorization header def authorization_header - (@site.user || @site.password ? { 'Authorization' => 'Basic ' + ["#{@site.user}:#{ @site.password}"].pack('m').delete("\r\n") } : {}) + (@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {}) end def logger #:nodoc: |