responsys 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/lib/metal/ResponsysWSServiceClient.rb +520 -0
- data/lib/metal/default.rb +2467 -0
- data/lib/metal/defaultDriver.rb +295 -0
- data/lib/metal/defaultMappingRegistry.rb +2167 -0
- data/lib/responsys.rb +133 -0
- data/responsys.gemspec +16 -0
- data/test/test_responsys.rb +6 -0
- metadata +71 -0
data/lib/responsys.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'metal/defaultDriver.rb'
|
2
|
+
require 'metal/defaultMappingRegistry.rb'
|
3
|
+
|
4
|
+
class Responsys
|
5
|
+
TIMEOUT = 20
|
6
|
+
MAX_MEMBERS = 200
|
7
|
+
|
8
|
+
class ResponsysTimeoutError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
class MethodsNotSupportedError < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :session_id
|
15
|
+
|
16
|
+
# Creates a client object to connect to Responsys via SOAP API
|
17
|
+
#
|
18
|
+
# <username> - The login username
|
19
|
+
# <password> - The login password
|
20
|
+
def initialize(username, password)
|
21
|
+
@username = username
|
22
|
+
@password = password
|
23
|
+
@client = ResponsysWS.new
|
24
|
+
@keep_alive = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def login
|
28
|
+
with_application_error do
|
29
|
+
login_request = Login.new
|
30
|
+
login_request.username = @username
|
31
|
+
login_request.password = @password
|
32
|
+
response = @client.login login_request
|
33
|
+
@session_id = response.result.sessionId
|
34
|
+
assign_session
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def assign_session
|
39
|
+
session_header_request = SessionHeader.new(@session_id)
|
40
|
+
@client.headerhandler << session_header_request
|
41
|
+
end
|
42
|
+
|
43
|
+
def logout
|
44
|
+
begin
|
45
|
+
logout_request = Logout.new
|
46
|
+
@client.logout logout_request
|
47
|
+
ensure
|
48
|
+
@session_id = nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Sends a campaign email to the list of recipients
|
53
|
+
#
|
54
|
+
# <campaign_name> - The type of email being sent.
|
55
|
+
# <recipients> - A list of recipients to send the email to.
|
56
|
+
|
57
|
+
# Each element in the list is a hash:
|
58
|
+
# {
|
59
|
+
# id: athlete_id,
|
60
|
+
# email: email address
|
61
|
+
# }
|
62
|
+
#
|
63
|
+
def send_email(campaign_name, recipients, recipient_options = nil)
|
64
|
+
trigger_campaign_message = TriggerCampaignMessage.new
|
65
|
+
interact_object = InteractObject.new
|
66
|
+
interact_object.folderName = 'ignored'
|
67
|
+
interact_object.objectName = campaign_name
|
68
|
+
trigger_campaign_message.campaign = interact_object
|
69
|
+
trigger_campaign_message.recipientData = []
|
70
|
+
|
71
|
+
recipients.each_with_index do |recipient_info, i|
|
72
|
+
#options = recipient_options[i]
|
73
|
+
|
74
|
+
# Responsys requires something in the optional data for SOAP bindings to work
|
75
|
+
options = {foo: :bar}
|
76
|
+
|
77
|
+
recipient = Recipient.new
|
78
|
+
recipient.emailAddress = recipient_info[:email] if recipient_info[:email]
|
79
|
+
recipient.customerId = recipient_info[:id] if recipient_info[:id]
|
80
|
+
recipient_data = RecipientData.new
|
81
|
+
recipient_data.recipient = recipient
|
82
|
+
recipient_data.optionalData = []
|
83
|
+
options.each_pair do |k, v|
|
84
|
+
optional_data = OptionalData.new
|
85
|
+
optional_data.name = k
|
86
|
+
v.gsub!(/[[:cntrl:]]/, ' ') if v.is_a? String
|
87
|
+
optional_data.value = v
|
88
|
+
recipient_data.optionalData << optional_data
|
89
|
+
end
|
90
|
+
|
91
|
+
trigger_campaign_message.recipientData << recipient_data
|
92
|
+
end
|
93
|
+
|
94
|
+
with_session do
|
95
|
+
@client.triggerCampaignMessage(trigger_campaign_message)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def with_timeout
|
100
|
+
Timeout::timeout(TIMEOUT, ResponsysTimeoutError) do
|
101
|
+
yield
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def with_session
|
106
|
+
begin
|
107
|
+
with_timeout do
|
108
|
+
login if @session_id.nil?
|
109
|
+
end
|
110
|
+
with_application_error do
|
111
|
+
with_timeout do
|
112
|
+
yield
|
113
|
+
end
|
114
|
+
end
|
115
|
+
ensure
|
116
|
+
with_timeout do
|
117
|
+
logout unless @keep_alive
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
protected
|
123
|
+
|
124
|
+
def with_application_error
|
125
|
+
begin
|
126
|
+
yield
|
127
|
+
rescue SOAP::FaultError => e
|
128
|
+
inner_e = e.detail[e.faultstring.data]
|
129
|
+
raise inner_e if inner_e
|
130
|
+
raise e
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/responsys.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'responsys'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.summary = 'Responsys Interact API client.'
|
6
|
+
s.description = 'A client for interacting with the Responsys API.'
|
7
|
+
s.author = 'Leo Romanovsky'
|
8
|
+
s.email = 'leoromanovsky@gmail.com'
|
9
|
+
s.homepage = 'http://github.com/leoromanovsky/responsys_client'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
|
15
|
+
s.add_dependency('mumboe-soap4r', '~> 1.5.8.5')
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: responsys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leo Romanovsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mumboe-soap4r
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.8.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.8.5
|
30
|
+
description: A client for interacting with the Responsys API.
|
31
|
+
email: leoromanovsky@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/metal/ResponsysWSServiceClient.rb
|
39
|
+
- lib/metal/default.rb
|
40
|
+
- lib/metal/defaultDriver.rb
|
41
|
+
- lib/metal/defaultMappingRegistry.rb
|
42
|
+
- lib/responsys.rb
|
43
|
+
- responsys.gemspec
|
44
|
+
- test/test_responsys.rb
|
45
|
+
homepage: http://github.com/leoromanovsky/responsys_client
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Responsys Interact API client.
|
69
|
+
test_files:
|
70
|
+
- test/test_responsys.rb
|
71
|
+
has_rdoc:
|