Class: ResponsysClient
- Inherits:
-
Object
show all
- Defined in:
- lib/responsys_client.rb
Defined Under Namespace
Classes: MethodsNotSupportedError, ResponsysTimeoutError, TooManyMembersError
Constant Summary
collapse
- MAX_MEMBERS =
200
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#assign_session ⇒ Object
-
#create_folder(folder_name) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ ResponsysClient
constructor
Creates a client object to connect to Responsys via SOAP API.
-
#launch_campaign(folder_name, campaign_name) ⇒ Object
-
#list_folders ⇒ Object
-
#login ⇒ Object
-
#logout ⇒ Object
-
#save_members(folder_name, list_name, members, attributes = Responsys::Member.fields) ⇒ Object
-
#trigger_campaign(folder_name, campaign_name, email, options = {}) ⇒ Object
-
#trigger_user_campaign(campaign_name, recipient_info, options = {}) ⇒ Object
-
#with_session ⇒ Object
-
#with_timeout ⇒ Object
Constructor Details
#initialize(username, password, options = {}) ⇒ ResponsysClient
Creates a client object to connect to Responsys via SOAP API
<username> - The login username <password> - The login password <options…> - Hash of additional options
:keep_alive => true|false - (Default=false) Keep session alive for multiple requests
:wiredump_dev => IO - Dump all messages (reply and responses) to IO
30
31
32
33
34
35
36
|
# File 'lib/responsys_client.rb', line 30
def initialize(username, password, options = {})
@username = username
@password = password
@keep_alive = options[:keep_alive]
@responsys_client = ResponsysWS.new
@responsys_client.wiredump_dev = options[:wiredump_dev] if options[:wiredump_dev]
end
|
Instance Attribute Details
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
20
21
22
|
# File 'lib/responsys_client.rb', line 20
def keep_alive
@keep_alive
end
|
#session_id ⇒ Object
Returns the value of attribute session_id.
19
20
21
|
# File 'lib/responsys_client.rb', line 19
def session_id
@session_id
end
|
Instance Method Details
#assign_session ⇒ Object
49
50
51
52
53
|
# File 'lib/responsys_client.rb', line 49
def assign_session
= SessionHeader.new
.sessionId = @session_id
@responsys_client.headerhandler.add
end
|
#create_folder(folder_name) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/responsys_client.rb', line 70
def create_folder(folder_name)
with_session do
create_folder_request = CreateFolder.new
create_folder_request.folderName = folder_name
@responsys_client.createFolder create_folder_request
end
end
|
#launch_campaign(folder_name, campaign_name) ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/responsys_client.rb', line 106
def launch_campaign(folder_name, campaign_name)
with_session do
launch_campaign = LaunchCampaign.new
interact_object = InteractObject.new
interact_object.folderName = folder_name
interact_object.objectName = campaign_name
launch_campaign.campaign = interact_object
@responsys_client.launchCampaign launch_campaign
end
end
|
#list_folders ⇒ Object
64
65
66
67
68
|
# File 'lib/responsys_client.rb', line 64
def list_folders
with_session do
@responsys_client.listFolders ListFolders.new
end
end
|
#login ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/responsys_client.rb', line 38
def login
with_application_error do
login_request = Login.new
login_request.username = @username
login_request.password = @password
response = @responsys_client.login login_request
@session_id = response.result.sessionId
assign_session
end
end
|
#logout ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/responsys_client.rb', line 55
def logout
begin
logout_request = Logout.new
@responsys_client.logout logout_request
ensure
@session_id = nil
end
end
|
#save_members(folder_name, list_name, members, attributes = Responsys::Member.fields) ⇒ Object
#trigger_campaign(folder_name, campaign_name, email, options = {}) ⇒ Object
117
118
119
|
# File 'lib/responsys_client.rb', line 117
def trigger_campaign(folder_name, campaign_name, email, options = {})
trigger_user_campaign(campaign_name, {:email => email}, options)
end
|
#trigger_user_campaign(campaign_name, recipient_info, options = {}) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/responsys_client.rb', line 121
def trigger_user_campaign(campaign_name, recipient_info, options = {})
options[:foo] = :bar if options.size == 0
with_session do
trigger_campaign_message = TriggerCampaignMessage.new
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.optionalData = []
recipient_data.recipient = recipient
options.each_pair do |k, v|
optional_data = OptionalData.new
optional_data.name = k
optional_data.value = v
recipient_data.optionalData << optional_data
end
interact_object = InteractObject.new
interact_object.folderName = 'ignored'
interact_object.objectName = campaign_name
trigger_campaign_message.campaign = interact_object
trigger_campaign_message.recipientData = recipient_data
@responsys_client.triggerCampaignMessage trigger_campaign_message
end
end
|
#with_session ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/responsys_client.rb', line 154
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
148
149
150
151
152
|
# File 'lib/responsys_client.rb', line 148
def with_timeout
Timeout::timeout(60, ResponsysTimeoutError) do
yield
end
end
|