responsys-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'responsys-client'
5
+ s.version = '0.0.2'
6
+ s.platform = Gem::Platform::RUBY
7
+ s.summary = 'Ruby SOAP Client For Responsys API'
8
+ s.description = 'Ruby SOAP Client For Responsys API'
9
+
10
+ s.authors = ['Christopher Sun', 'Leo Romanovsky']
11
+ s.email = 'leoromanovsky@gmail.com'
12
+ s.homepage = 'http://github.com/leoromanovsky/responsys-client'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- test/*`.split("\n")
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency('mumboe-soap4r', '~> 1.5.8.5')
19
+ s.add_dependency('fastercsv', '~> 1.5.4')
20
+ s.add_dependency('mocha', '~> 0.9.12')
21
+ end
@@ -0,0 +1,4 @@
1
+ # Enter your username and password for testing from Responsys
2
+ # Rename this file to config.yml to run tests
3
+ username: "USERNAME"
4
+ password: "PASSWORD"
data/test/feedback.csv ADDED
@@ -0,0 +1,4 @@
1
+ REASON,CUSTOMER_ID_,EMAIL_ADDRESS_,EMAIL_PERMISSION_STATUS_,USER_TYPE,LAST_NAME,HOW_HEARD,ACCOUNT_CREATION_DATE,AFFILIATE,FIRST_NAME,GENDER,DATE_OF_BIRTH,COUNTRY_,POSTAL_CODE_,BUSINESS_TYPE
2
+ INVALID FORMAT FOR EMAIL ADDRESS,253,hahahaha%40gmail.com+a618bb@animoto.com,OPTIN,,Korhonen,,2009-01-27,N,Christopher,M,1982-04-05,United States,10005,
3
+ INVALID FORMAT FOR EMAIL ADDRESS,324,ewrewrewrwer@s.cdsdf,OPTIN,,sdfsd,,2009-02-12,N,dsfs,M,1983-11-05,United States,sdfsdf,
4
+ INVALID FORMAT FOR EMAIL ADDRESS,878,chris.sun%40animoto.com+d169ae@animoto.com,OPTOUT,business,Sun,Magazine,2009-10-15,Y,Christopher,M,1975-06-06,United States,10069,other
data/test/import.txt ADDED
@@ -0,0 +1,4 @@
1
+ "EVENT_TYPE_ID","ACCOUNT_ID","LIST_ID","RIID","CUSTOMER_ID","EVENT_CAPTURED_DT","EVENT_STORED_DT","CAMPAIGN_ID","LAUNCH_ID","EMAIL_FORMAT","SOURCE","REASON","EMAIL","CONTACT_INFO"
2
+ "7","50209","1012","1407280","855006","15-Jul-2011 04:42:32","15-Jul-2011 04:42:47","1345","1387","M","Unsubscribe Page/Link","Unsubscribe Page","leigh.walters@united.com","leigh.walters@united.com"
3
+ "7","50209","1012","1438565","886389","15-Jul-2011 04:45:47","15-Jul-2011 04:46:02","1345","1387","M","Unsubscribe Page/Link","Unsubscribe Page","gcandido@cox.net","gcandido@cox.net"
4
+ "7","50209","1012","4477551","3052672","15-Jul-2011 06:02:15","15-Jul-2011 06:02:30","0","","N","Exchange - Webservice","WS:MERGE","deleteduser@delete.animoto.com","deleteduser@delete.animoto.com"
@@ -0,0 +1,145 @@
1
+ require 'test_helper'
2
+ require 'member'
3
+
4
+ class MemberTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ SunDawg::Responsys::Member.clear_fields!
8
+ end
9
+
10
+ def test_parse_feedback_csv
11
+ SunDawg::Responsys::Member.add_field :customer_id, true
12
+ SunDawg::Responsys::Member.add_field :email_address, true
13
+ results = SunDawg::Responsys::Member.parse_feedback_csv("#{File.dirname(__FILE__)}/feedback.csv")
14
+ assert_equal 3, results.size
15
+ results.values.each do |reason|
16
+ assert_equal "INVALID FORMAT FOR EMAIL ADDRESS", reason
17
+ end
18
+ results.keys.each do |member|
19
+ assert member.instance_of?(SunDawg::Responsys::Member)
20
+ assert member.customer_id
21
+ assert member.email_address
22
+ end
23
+ end
24
+
25
+ def test_parse_import_file
26
+ SunDawg::Responsys::Member.add_field :customer_id, true
27
+ SunDawg::Responsys::Member.add_field :email, true
28
+ results = SunDawg::Responsys::Member.import_file("#{File.dirname(__FILE__)}/import.txt")
29
+ assert_equal 3, results.size
30
+ results.each do |member|
31
+ assert member.instance_of?(SunDawg::Responsys::Member)
32
+ end
33
+ [["855006", "leigh.walters@united.com"],
34
+ ["886389", "gcandido@cox.net"],
35
+ ["3052672", "deleteduser@delete.animoto.com"]].each do |expected|
36
+ actual = results.shift
37
+ assert_equal expected[0], actual.customer_id
38
+ assert_equal expected[1], actual.email
39
+ end
40
+ end
41
+
42
+ def test_attribute_methods
43
+ SunDawg::Responsys::Member.add_field :foo
44
+ member = SunDawg::Responsys::Member.new
45
+ member.foo = "bar"
46
+ assert_equal "bar", member.foo
47
+ assert_equal "bar", member.FOO
48
+ end
49
+
50
+ def test_fields
51
+ SunDawg::Responsys::Member.add_field :foo
52
+ SunDawg::Responsys::Member.add_field :bar
53
+ SunDawg::Responsys::Member.add_field :hello, true
54
+ # Fields should be unique and defined the first time
55
+ SunDawg::Responsys::Member.add_field :bar
56
+ SunDawg::Responsys::Member.add_field :hello
57
+ assert_equal [:foo, :bar, :hello], SunDawg::Responsys::Member.fields
58
+ assert_equal ["FOO", "BAR", "HELLO_"], SunDawg::Responsys::Member.responsys_fields
59
+ end
60
+
61
+ def test_has_field
62
+ SunDawg::Responsys::Member.add_field :foo
63
+ SunDawg::Responsys::Member.add_field :bar, true
64
+ assert SunDawg::Responsys::Member.has_field?(:foo)
65
+ assert SunDawg::Responsys::Member.has_field?(:bar)
66
+ assert !SunDawg::Responsys::Member.has_system_field?(:foo)
67
+ assert SunDawg::Responsys::Member.has_system_field?(:bar)
68
+ end
69
+
70
+ def test_responsys_fields
71
+ SunDawg::Responsys::Member.add_field :foo
72
+ SunDawg::Responsys::Member.add_field :bar
73
+ assert_equal ["FOO", "BAR"], SunDawg::Responsys::Member.responsys_fields
74
+ end
75
+
76
+ def test_from_responsys_field
77
+ assert_equal "foo", SunDawg::Responsys::Member.send(:from_responsys_field, "FOO")
78
+ assert_equal "foo_bar", SunDawg::Responsys::Member.send(:from_responsys_field, "FOO_BAR")
79
+ SunDawg::Responsys::Member.add_field :tweet, true
80
+ assert_equal "tweet", SunDawg::Responsys::Member.send(:from_responsys_field, "TWEET_")
81
+ end
82
+
83
+ def test_responsys_system_fields
84
+ SunDawg::Responsys::Member.add_field :foo, true
85
+ SunDawg::Responsys::Member.add_field :bar, true
86
+ SunDawg::Responsys::Member.add_field :woot
87
+ assert_equal ["FOO_", "BAR_", "WOOT"], SunDawg::Responsys::Member.responsys_fields
88
+ member = SunDawg::Responsys::Member.new
89
+ member.foo = "value_1"
90
+ member.bar = "value_2"
91
+ member.woot = 123
92
+ assert_equal ["value_1", "value_2", 123], member.values
93
+ end
94
+
95
+ def test_values
96
+ SunDawg::Responsys::Member.add_field :foo
97
+ SunDawg::Responsys::Member.add_field :bar
98
+ SunDawg::Responsys::Member.add_field :nernt
99
+ member = SunDawg::Responsys::Member.new
100
+ member.foo = "value_1"
101
+ member.bar = "value_2"
102
+ member.nernt = 123
103
+ assert_equal ["value_1", "value_2", 123], member.values
104
+ end
105
+
106
+ def test_attributes
107
+ SunDawg::Responsys::Member.add_field :foo
108
+ SunDawg::Responsys::Member.add_field :bar
109
+ member = SunDawg::Responsys::Member.new
110
+ member.attributes = {:foo => "value_1", :bar => "value_2"}
111
+ assert_equal "value_1", member.foo
112
+ assert_equal "value_2", member.bar
113
+ end
114
+
115
+ def test_to_csv_splitted_files
116
+ SunDawg::Responsys::Member.add_field :customer_id
117
+ SunDawg::Responsys::Member.add_field :foo
118
+ SunDawg::Responsys::Member.add_field :bar
119
+ SunDawg::Responsys::Member.extension_fields = {:file_a => [:foo], :file_b => [:bar]}
120
+ member = SunDawg::Responsys::Member.new
121
+ member.attributes = {:foo => "value_1", :bar => "value_2", :customer_id => 123}
122
+ SunDawg::Responsys::Member.expects(:build_csv_file).times(3)
123
+ SunDawg::Responsys::Member.to_csv_extension_files([member], "/tmp", :headers => true, :access => "w")
124
+ end
125
+
126
+ def test_member_fields
127
+ SunDawg::Responsys::Member.add_field :customer_id
128
+ SunDawg::Responsys::Member.add_field :foo
129
+ SunDawg::Responsys::Member.add_field :bar
130
+ SunDawg::Responsys::Member.add_field :chooch
131
+ SunDawg::Responsys::Member.add_field :nooch
132
+ SunDawg::Responsys::Member.extension_fields = {:file_a => [:foo], :file_b => [:bar]}
133
+ assert_equal [:customer_id, :chooch, :nooch], SunDawg::Responsys::Member.member_fields
134
+ end
135
+
136
+ def test_profile_fields
137
+ SunDawg::Responsys::Member.extension_fields = {
138
+ :file_a => [:foo],
139
+ :file_b => [:bar]
140
+ }
141
+ [:file_a, :file_b].each do |i|
142
+ SunDawg::Responsys::Member.extension_fields.keys.include?(i)
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,166 @@
1
+ require 'test_helper'
2
+ require 'responsys_client'
3
+
4
+ class ResponsysClientIntegrationTest < Test::Unit::TestCase
5
+ FOLDER_NAME = "Test_Gem"
6
+ CAMPAIGN_NAME = "GemCampaignEmail"
7
+ CAMPAIGN_TRANSACTION_NAME = "GemTransactionalEmail"
8
+ LIST_NAME = "GemList"
9
+ EMAIL = "gem.test@responsys.client.gem.com"
10
+
11
+ def setup
12
+ config = YAML.load_file("test/config.yml")
13
+ @username = config["username"]
14
+ @password = config["password"]
15
+ @client = SunDawg::ResponsysClient.new(@username, @password) #, :wiredump_dev => STDOUT)
16
+ SunDawg::Responsys::Member.clear_fields!
17
+ end
18
+
19
+ class << self
20
+ def with_integration
21
+ return unless INTEGRATION
22
+ yield
23
+ end
24
+ end
25
+
26
+ def test_client
27
+ assert @client
28
+ end
29
+
30
+ with_integration do
31
+ def test_invalid_login
32
+ error = assert_raise AccountFault do
33
+ SunDawg::ResponsysClient.new("foo", "bar").login
34
+ end
35
+ assert_equal ExceptionCode::INVALID_USER_NAME, error.exception_code
36
+ end
37
+
38
+ def test_login
39
+ assert_nothing_raised do
40
+ @client.login
41
+ assert @client.session_id
42
+ end
43
+ end
44
+
45
+ def test_list_folders
46
+ results = @client.list_folders
47
+ assert results.size
48
+ results.each do |result|
49
+ assert result.name
50
+ end
51
+ end
52
+
53
+ def test_create_folder
54
+ folder_name = "test_folder_#{Time.now.to_i}"
55
+ @client.keep_alive = true
56
+ response = @client.create_folder folder_name
57
+ assert response.result
58
+ results = @client.list_folders
59
+ assert results.map { |i| i.name }.include? folder_name
60
+ end
61
+
62
+ def test_save_members
63
+ SunDawg::Responsys::Member.add_field :customer_id, true
64
+ SunDawg::Responsys::Member.add_field :email_address, true
65
+ SunDawg::Responsys::Member.add_field :email_permission_status, true
66
+ SunDawg::Responsys::Member.add_field :city, true
67
+ SunDawg::Responsys::Member.add_field :state, true
68
+ member = SunDawg::Responsys::Member.new
69
+ member.customer_id = Time.now.to_i
70
+ member.email_address = "sundawg.#{Time.now.to_i}@sundawg.net"
71
+ member.email_permission_status = "I"
72
+ member.city = "San Francisco"
73
+ member.state = "CA"
74
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
75
+ assert response.result
76
+ end
77
+
78
+ def test_save_members_with_attributes
79
+ SunDawg::Responsys::Member.add_field :customer_id, true
80
+ SunDawg::Responsys::Member.add_field :email_address, true
81
+ SunDawg::Responsys::Member.add_field :email_permission_status, true
82
+ SunDawg::Responsys::Member.add_field :city, true
83
+ SunDawg::Responsys::Member.add_field :state, true
84
+ member = SunDawg::Responsys::Member.new
85
+ member.customer_id = Time.now.to_i
86
+ member.email_address = "lol.cats.sundawg.#{Time.now.to_i}@sundawg.net"
87
+ member.email_permission_status = PermissionStatus::OPTIN
88
+ member.city = "San Francisco"
89
+ member.state = "CA"
90
+ member.expects(:state).never
91
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member], [:customer_id, :email_address, :city]
92
+ assert response.result
93
+ end
94
+
95
+
96
+ def test_keep_session
97
+ SunDawg::Responsys::Member.add_field :customer_id, true
98
+ SunDawg::Responsys::Member.add_field :email_address, true
99
+ SunDawg::Responsys::Member.add_field :email_permission_status, true
100
+ SunDawg::Responsys::Member.add_field :city, true
101
+ SunDawg::Responsys::Member.add_field :state, true
102
+
103
+ member = SunDawg::Responsys::Member.new
104
+ member.customer_id = Time.now.to_i
105
+ member.email_address = "sundawg-montgomery@sundawg.net"
106
+ member.email_permission_status = PermissionStatus::OPTIN
107
+ member.city = "Montgomery"
108
+ member.state = "AL"
109
+
110
+ # When the keep_alive option has not been set (default) then the client
111
+ # must reconnect for every request or a FaultError will be raised on
112
+ # multiple requests
113
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
114
+ assert response.result
115
+ error = assert_raise SOAP::FaultError do
116
+ @client.save_members FOLDER_NAME, LIST_NAME, [member]
117
+ end
118
+
119
+ # When the keep_alive option has been set then the client does not need
120
+ # to reconnect for every request
121
+ @client = SunDawg::ResponsysClient.new(@username, @password, :keep_alive => true)
122
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
123
+ assert response.result
124
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
125
+ assert response.result
126
+
127
+ # When the keep_alive option has not been set (default) then the client
128
+ # does not need to reconnect for every request if keep_alive is set
129
+ @client = SunDawg::ResponsysClient.new(@username, @password)
130
+ @client.keep_alive = true
131
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
132
+ assert response.result
133
+ response = @client.save_members FOLDER_NAME, LIST_NAME, [member]
134
+ assert response.result
135
+ end
136
+
137
+ def test_launch_campaign
138
+ begin
139
+ response = @client.launch_campaign FOLDER_NAME, CAMPAIGN_NAME
140
+ assert response.result
141
+ rescue CampaignFault => e
142
+ # Responsys does not allow campaigns to be launched less than 15 minute attempts
143
+ assert_equal "Launch attempt failed: A campaign cannot be launched more than once per 15 minutes.", e.exception_message
144
+ end
145
+ end
146
+
147
+ def test_trigger_campaign_with_optional_data
148
+ response = @client.trigger_campaign(
149
+ FOLDER_NAME,
150
+ CAMPAIGN_TRANSACTION_NAME,
151
+ EMAIL,
152
+ {:name => "Fred"}
153
+ )
154
+ assert response.first.success
155
+ end
156
+
157
+ def test_trigger_campaign_without_optional_data
158
+ response = @client.trigger_campaign(
159
+ FOLDER_NAME,
160
+ CAMPAIGN_TRANSACTION_NAME,
161
+ EMAIL
162
+ )
163
+ assert response.first.success
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'responsys_client'
3
+
4
+ class ResponsysClientTest < Test::Unit::TestCase
5
+ def setup
6
+ SunDawg::Responsys::Member.clear_fields!
7
+ end
8
+
9
+ def test_instantiation
10
+ assert SunDawg::ResponsysClient.new("foo", "bar")
11
+ end
12
+
13
+ def test_instantiation_with_options
14
+ assert SunDawg::ResponsysClient.new("foo", "bar", :wiredump_dev => STDOUT)
15
+ end
16
+
17
+ def test_save_members_throws_too_many_members_error
18
+ SunDawg::Responsys::Member.add_field :customer_id
19
+ SunDawg::Responsys::Member.add_field :email_address
20
+ SunDawg::Responsys::Member.add_field :email_permission_status
21
+ members = []
22
+ (SunDawg::ResponsysClient::MAX_MEMBERS + 1).times do
23
+ members << SunDawg::Responsys::Member.new
24
+ end
25
+ assert_raises SunDawg::ResponsysClient::TooManyMembersError do
26
+ SunDawg::ResponsysClient.new("foo", "bar").save_members("folder", "list", members)
27
+ end
28
+ end
29
+
30
+ def test_save_members_throws_methods_not_supported_error_with_no_email_address
31
+ SunDawg::Responsys::Member.add_field :email_address
32
+ member = SunDawg::Responsys::Member.new
33
+ assert_raises SunDawg::ResponsysClient::MethodsNotSupportedError do
34
+ SunDawg::ResponsysClient.new("foo", "bar").save_members("folder", "list", [member])
35
+ end
36
+ end
37
+
38
+ def test_save_members_throws_methods_not_supported_error_with_no_email_permission_status
39
+ SunDawg::Responsys::Member.add_field :email_permission_status
40
+ member = SunDawg::Responsys::Member.new
41
+ assert_raises SunDawg::ResponsysClient::MethodsNotSupportedError do
42
+ SunDawg::ResponsysClient.new("foo", "bar").save_members("folder", "list", [member])
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+
5
+ INTEGRATION = false unless defined?(INTEGRATION)
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: responsys-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Sun
9
+ - Leo Romanovsky
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-11-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mumboe-soap4r
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.8.5
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.5.8.5
31
+ - !ruby/object:Gem::Dependency
32
+ name: fastercsv
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.5.4
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.12
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.9.12
63
+ description: Ruby SOAP Client For Responsys API
64
+ email: leoromanovsky@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - README.rdoc
71
+ - Rakefile
72
+ - lib/member.rb
73
+ - lib/responsys_client.rb
74
+ - lib/stub/ResponsysWSServiceClient.rb
75
+ - lib/stub/default.rb
76
+ - lib/stub/defaultDriver.rb
77
+ - lib/stub/defaultMappingRegistry.rb
78
+ - lib/wsdl/wsdl_4_11_2011.wsdl
79
+ - responsys-client.gemspec
80
+ - test/config.yml.sample
81
+ - test/feedback.csv
82
+ - test/import.txt
83
+ - test/member_test.rb
84
+ - test/responsys_client_integration_test.rb
85
+ - test/responsys_client_test.rb
86
+ - test/test_helper.rb
87
+ homepage: http://github.com/leoromanovsky/responsys-client
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Ruby SOAP Client For Responsys API
111
+ test_files:
112
+ - test/config.yml.sample
113
+ - test/feedback.csv
114
+ - test/import.txt
115
+ - test/member_test.rb
116
+ - test/responsys_client_integration_test.rb
117
+ - test/responsys_client_test.rb
118
+ - test/test_helper.rb
119
+ has_rdoc: