Class: Responsys
- Inherits:
-
Object
- Object
- Responsys
- Defined in:
- lib/responsys.rb
Defined Under Namespace
Classes: MethodsNotSupportedError, ResponsysTimeoutError, TooManyMembersError
Constant Summary collapse
- TIMEOUT =
180
- MAX_MEMBERS =
200
Instance Attribute Summary collapse
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#timeout_threshold ⇒ Object
Returns the value of attribute timeout_threshold.
Instance Method Summary collapse
- #assign_session ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Responsys
constructor
Creates a client object to connect to Responsys via SOAP API.
- #login ⇒ Object
- #logout ⇒ Object
-
#send_email(campaign_name, recipients) ⇒ Object
Each element in the list is a hash: { id: athlete_id, email: email address, options: {} }.
- #with_session ⇒ Object
- #with_timeout ⇒ Object
Constructor Details
#initialize(username, password, options = {}) ⇒ Responsys
Creates a client object to connect to Responsys via SOAP API
<username> - The login username <password> - The login password <options>
timeout_threshold - number of seconds (default 180)
26 27 28 29 30 31 32 33 |
# File 'lib/responsys.rb', line 26 def initialize(username, password, = {}) @username = username @password = password @client = ResponsysWS.new @keep_alive = false self.timeout_threshold = [:timeout_threshold] || TIMEOUT end |
Instance Attribute Details
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
17 18 19 |
# File 'lib/responsys.rb', line 17 def session_id @session_id end |
#timeout_threshold ⇒ Object
Returns the value of attribute timeout_threshold.
18 19 20 |
# File 'lib/responsys.rb', line 18 def timeout_threshold @timeout_threshold end |
Instance Method Details
#assign_session ⇒ Object
55 56 57 58 |
# File 'lib/responsys.rb', line 55 def assign_session session_header_request = SessionHeader.new(@session_id) @client.headerhandler << session_header_request end |
#login ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/responsys.rb', line 44 def login with_application_error do login_request = Login.new login_request.username = @username login_request.password = @password response = @client.login(login_request) @session_id = response.result.sessionId assign_session end end |
#logout ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/responsys.rb', line 60 def logout begin logout_request = Logout.new @client.logout(logout_request) ensure @session_id = nil end end |
#send_email(campaign_name, recipients) ⇒ Object
Each element in the list is a hash:
{
id: athlete_id,
email: email address,
options: {}
}
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/responsys.rb', line 80 def send_email(campaign_name, recipients) raise TooManyMembersError if recipients.size > MAX_MEMBERS = TriggerCampaignMessage.new interact_object = InteractObject.new interact_object.folderName = 'ignored' interact_object.objectName = campaign_name .campaign = interact_object .recipientData = [] recipients.each do |recipient_info| = recipient_info.has_key?('options') ? recipient_info['options'] : {foo: 'bar'} recipient = Recipient.new recipient.emailAddress = recipient_info['email'] if recipient_info['email'] recipient.customerId = recipient_info['id'] if recipient_info['id'] recipient_data = RecipientData.new recipient_data.recipient = recipient recipient_data.optionalData = [] .each_pair do |k, v| optional_data = OptionalData.new optional_data.name = k v.gsub!(/[[:cntrl:]]/, ' ') if v.is_a? String optional_data.value = v recipient_data.optionalData << optional_data end .recipientData << recipient_data end with_session do @client.triggerCampaignMessage() end end |
#with_session ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/responsys.rb', line 121 def with_session begin with_timeout do login if @session_id.nil? end with_application_error do with_timeout do yield end end ensure with_timeout do logout unless @keep_alive end end end |
#with_timeout ⇒ Object
115 116 117 118 119 |
# File 'lib/responsys.rb', line 115 def with_timeout Timeout::timeout(timeout_threshold, ResponsysTimeoutError) do yield end end |