Class: Rpx::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rpx/client.rb

Constant Summary collapse

NAMESPACES =
{
  "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
  "xmlns:tem"=>"http://tempuri.org/"
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.


8
9
10
11
# File 'lib/rpx/client.rb', line 8

def initialize(options={})
  @read_timeout = options.delete(:read_timeout){ Rpx.config.read_timeout || 120 }
  @debug = options.delete(:debug){false}
end

Instance Method Details

#add_attributes_if_present(xml, options, attributes) ⇒ Object


13
14
15
16
17
# File 'lib/rpx/client.rb', line 13

def add_attributes_if_present(xml, options, attributes)
  return add_attributes_if_present(xml, options, [attributes]) unless attributes.is_a? Array

  attributes.each{ |attribute|  xml.tem(attribute, options[attribute]) if options[attribute] }
end

#api_call(action_name, options) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rpx/client.rb', line 19

def api_call(action_name, options)
  raw_response = client.request action_name do
    soap.xml do |xml|
      xml.soapenv :Envelope, NAMESPACES do |xml|
        xml.soapenv :Header
        xml.soapenv :Body do |xml|
          xml.tem action_name do |xml|
            xml.tem :auth do |xml|
              xml.tem :siteid, options.fetch(:siteid)
              xml.tem :pmcid, options.fetch(:pmcid)
              xml.tem :username, Rpx.config.username
              xml.tem :password, Rpx.config.password
              xml.tem :licensekey, Rpx.config.licensekey
            end
            yield(xml)
          end
        end
      end
    end
  end

  resident_list_from_raw({ action_name: action_name, raw_response: raw_response })
end