lib/cupid/session.rb in cupid-0.0.6 vs lib/cupid/session.rb in cupid-0.0.7
- old
+ new
@@ -10,10 +10,11 @@
def initialize(*args)
options = args.extract_options!
@username = options[:username] ||= Cupid.username
@password = options[:password] ||= Cupid.password
+ @account = options[:account] ||= Cupid.account
@headers = {"Content-Type" => "application/x-www-form-urlencoded", "Connection" => "close"}
@api_uri = @api_wsdl = DEFAULTS[:soap_s4_url]
@api_uri = URI.parse(@api_uri)
@api_url = Net::HTTP.new(@api_uri.host, @api_uri.port)
@@ -21,41 +22,56 @@
@api_url.use_ssl = DEFAULTS[:use_ssl]
@wsa_soap_s4_to = DEFAULTS[:wsa_soap_s4_to]
end
private
- def build_request(type, method, body)
- client = Savon::Client.new(@api_wsdl)
- client.wsse.username = @username
- client.wsse.password = @password
- client.wsse.created_at = Time.now.utc
- client.wsse.expires_at = (Time.now + 120).utc
- header = {
- 'a:Action' => type,
- 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
- 'a:ReplyTo' => {
- 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
- },
- 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
- 'a:To' => @wsa_soap_s4_to
- }
+ def build_request(type, method, body)
+ client = Savon::Client.new(@api_wsdl)
+ client.wsse.username = @username
+ client.wsse.password = @password
+ client.wsse.created_at = Time.now.utc
+ client.wsse.expires_at = (Time.now + 120).utc
- namespaces = {
- 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
- 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
- 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
- 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
- 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
- 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
- }
+ header = {
+ 'a:Action' => type,
+ 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
+ 'a:ReplyTo' => {
+ 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
+ },
+ 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
+ 'a:To' => @wsa_soap_s4_to
+ }
- response = client.request type.downcase.to_sym do |soap|
- soap.input = [method, { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
- soap.header = header
- soap.env_namespace = :s
- soap.namespaces = namespaces
- soap.body = body
- end
+ namespaces = {
+ 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
+ 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
+ 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
+ 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
+ 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
+ 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
+ }
+
+ response = client.request type.downcase.to_sym do |soap|
+ soap.input = [method, { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
+ soap.header = header
+ soap.env_namespace = :s
+ soap.namespaces = namespaces
+ soap.body = body
end
+ end
+
+ def build_retrieve(id, object_type, properties, filters=nil)
+ body = {'RetrieveRequest' => {
+ 'ClientIDs' => {
+ 'ID' => id
+ },
+ 'ObjectType' => object_type,
+ 'Properties' => properties
+ }
+ }
+ body['RetrieveRequest'].merge! filters if filters
+
+ body
+ end
end
end
\ No newline at end of file