Class: Exactly::Client
- Inherits:
-
Object
- Object
- Exactly::Client
- Defined in:
- lib/exactly/client.rb
Instance Method Summary collapse
- #client ⇒ Object
- #delete_from_data_extension(customer_key, properties) ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #triggered_send(customer_key, attributes) ⇒ Object
- #upsert_data_extension(customer_key, properties) ⇒ Object
- #upsert_subscriber(customer_key, email, lists = []) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
28 29 30 |
# File 'lib/exactly/client.rb', line 28 def initialize(username, password) client.wsse.credentials username, password end |
Instance Method Details
#client ⇒ Object
32 33 34 |
# File 'lib/exactly/client.rb', line 32 def client @client ||= ::Savon::Client.new("https://webservice.s6.exacttarget.com/etframework.wsdl") end |
#delete_from_data_extension(customer_key, properties) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/exactly/client.rb', line 95 def delete_from_data_extension(customer_key, properties) client.request "DeleteRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do http.headers['SOAPAction'] = 'Delete' soap.body = { "DeleteOptions" => {}, "Objects" => { "CustomerKey" => customer_key, "Keys" => { "Key" => properties.map do |k, v| { "Name" => k, "Value" => v } end } }, :attributes! => { "Objects" => { "xsi:type" => "DataExtensionObject" }} } end end |
#triggered_send(customer_key, attributes) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/exactly/client.rb', line 113 def triggered_send(customer_key, attributes) attributes_without_email = attributes.reject{|k,v| k == :email} response = client.request "CreateRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do http.headers['SOAPAction'] = 'Create' soap.body = { "Objects" => { "TriggeredSendDefinition" => { "CustomerKey" => customer_key }, "Subscribers" => { "EmailAddress" => attributes[:email], "SubscriberKey" => attributes[:subscriber_key], "Attributes" => attributes_without_email.map do |k, v| { "Name" => k, "Value" => v } end } }, :attributes! => { "Objects" => { "xsi:type" => "TriggeredSend" }} } end if response.to_hash[:create_response][:overall_status] != 'OK' raise Exactly::TriggeredSendFailed.new(response) end end |
#upsert_data_extension(customer_key, properties) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/exactly/client.rb', line 67 def upsert_data_extension(customer_key, properties) response = client.request "UpdateRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do http.headers['SOAPAction'] = 'Update' soap.body = { "Options" => { "SaveOptions" => [ "SaveOption" => { "PropertyName" => "*", "SaveAction" => "UpdateAdd" } ] }, "Objects" => { "CustomerKey" => customer_key, "Properties" => { "Property" => properties.map do |k, v| { "Name" => k, "Value" => v } end } }, :attributes! => { "Objects" => { "xsi:type" => "DataExtensionObject" }} } end if response.to_hash[:update_response][:overall_status] != 'OK' raise Exactly::UpsertDataExtensionFailed.new(response) end end |
#upsert_subscriber(customer_key, email, lists = []) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/exactly/client.rb', line 36 def upsert_subscriber(customer_key, email, lists = []) response = client.request "CreateRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do http.headers['SOAPAction'] = 'Create' body = { "Options" => { "SaveOptions" => [ "SaveOption" => { "PropertyName" => "*", "SaveAction" => "UpdateAdd" } ] }, "Objects" => { "CustomerKey" => customer_key, "EmailAddress" => email, "Lists" => Array(lists).map{|list_id| { "ID" => list_id, "Status" => "Active" } } }, :attributes! => { "Objects" => { "xsi:type" => "Subscriber" }} } soap.body = body end if response.to_hash[:create_response][:overall_status] != 'OK' raise Exactly::UpsertSubscriberFailed.new(response) end rescue Savon::SOAP::Fault => ex raise Exactly::SoapFaultError, "Error: Could not upsert subscriber #{customer_key}/#{email} to ExactTarget: #{ex.message}" end |