lib/exactly/client.rb in exactly-0.0.2 vs lib/exactly/client.rb in exactly-0.0.3
- old
+ new
@@ -1,6 +1,18 @@
module Exactly
+ class TriggeredSendFailed < StandardError
+ attr_reader :response
+ def initialize(response)
+ @response = response
+ super(message)
+ end
+
+ def message
+ @response.to_hash[:create_response][:results][:status_message]
+ end
+ end
+
class Client
def initialize(username, password)
client.wsse.credentials username, password
end
@@ -51,11 +63,11 @@
end
end
def triggered_send(customer_key, attributes)
attributes_without_email = attributes.reject{|k,v| k == :email}
- client.request "CreateRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do
+ response = client.request "CreateRequest", :xmlns => "http://exacttarget.com/wsdl/partnerAPI" do
http.headers['SOAPAction'] = 'Create'
soap.body = {
"Objects" => {
"TriggeredSendDefinition" => {
"CustomerKey" => customer_key
@@ -68,9 +80,12 @@
end
}
},
:attributes! => { "Objects" => { "xsi:type" => "TriggeredSend" }}
}
+ end
+ if response.to_hash[:create_response][:overall_status] != 'OK'
+ raise Exactly::TriggeredSendFailed.new(response)
end
end
end
end