Class: RestApi::UserAwareConnection

Inherits:
ActiveResource::PersistentConnection show all
Defined in:
app/models/rest_api/base.rb

Overview

A connection class that contains an authorization object to connect as

Constant Summary

Constants inherited from ActiveResource::PersistentConnection

ActiveResource::PersistentConnection::HTTP_FORMAT_HEADER_NAMES

Instance Attribute Summary collapse

Attributes inherited from ActiveResource::PersistentConnection

#auth_type, #connection_name, #format, #password, #proxy, #site, #ssl_options, #timeout, #user

Instance Method Summary collapse

Methods inherited from ActiveResource::PersistentConnection

#debug_output=, #delete, #get, #head, #patch, #post, #put, requests

Constructor Details

#initialize(connection, as) ⇒ UserAwareConnection

Returns a new instance of UserAwareConnection.



714
715
716
717
718
719
720
721
722
# File 'app/models/rest_api/base.rb', line 714

def initialize(connection, as)
  super connection.site, connection.format
  @connection = connection
  @as = as
  unless @as.respond_to? :to_headers
    @user = @as. if @as.respond_to? :login
    @password = @as.password if @as.respond_to? :password
  end
end

Instance Attribute Details

#asObject (readonly)

The authorization context



712
713
714
# File 'app/models/rest_api/base.rb', line 712

def as
  @as
end

Instance Method Details

#authorization_header(http_method, uri) ⇒ Object



724
725
726
727
728
729
730
731
732
# File 'app/models/rest_api/base.rb', line 724

def authorization_header(http_method, uri)
  headers = super
  if @as.respond_to? :to_headers
    headers.merge!(@as.to_headers)
  elsif @as.respond_to? :ticket and @as.ticket
    (headers['Cookie'] ||= '') << "rh_sso=#{@as.ticket}"
  end
  headers
end

#httpObject



734
735
736
# File 'app/models/rest_api/base.rb', line 734

def http
  @connection.send(:http)
end