class AffiliateWindow::Client
Attributes
savon_client[RW]
Public Class Methods
new(account_id:, affiliate_api_password:)
click to toggle source
# File lib/affiliate_window/client.rb, line 3 def initialize(account_id:, affiliate_api_password:) self.savon_client = Savon.client( wsdl: "http://api.affiliatewindow.com/v6/AffiliateService?wsdl", namespace: "http://api.affiliatewindow.com/", soap_header: { "api:UserAuthentication" => { "api:iId" => account_id.to_s, "api:sPassword" => affiliate_api_password, "api:sType" => "affiliate", }, "api:getQuota" => true, }, ) end
Public Instance Methods
call(method, params, debug = false)
click to toggle source
# File lib/affiliate_window/client.rb, line 18 def call(method, params, debug = false) params = convert_to_soap_arrays(params) print_request(method, params) if debug savon_client.call(method, message: params) end
print_request(method, params)
click to toggle source
# File lib/affiliate_window/client.rb, line 25 def print_request(method, params) request = savon_client.build_request(method, message: params) document = REXML::Document.new(request.body) formatter = REXML::Formatters::Pretty.new formatter.write(document, $stdout) end
Private Instance Methods
convert_to_soap_arrays(params)
click to toggle source
# File lib/affiliate_window/client.rb, line 35 def convert_to_soap_arrays(params) params.each.with_object({}) do |(key, value), hash| value = value.is_a?(Array) ? { int: value } : value hash.merge!(key => value) end end