exactish_target 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'sham_rack'
3
+ require 'fake_exactish_target/app'
4
+ require 'exactish_target'
5
+
6
+ describe ExactishTarget do
7
+
8
+ def fake_exactish_target
9
+ @fake_exactish_target ||= FakeExactishTarget::App.new
10
+ end
11
+
12
+ before do
13
+ ShamRack.mount(fake_exactish_target, "exact-target.com")
14
+ end
15
+
16
+ describe "#create_subscriber" do
17
+
18
+ it "should not raise an error if the subscription request was successful" do
19
+ fake_exactish_target.mode = :happy
20
+ lambda {
21
+ ExactishTarget.new("username", "password", "http://exact-target.com/Service.asmx").create_subscriber("email", "country", "source")
22
+ }.should_not raise_error
23
+ end
24
+
25
+ it "should raise an error if the subscription request failed" do
26
+ fake_exactish_target.mode = :sad
27
+ lambda {
28
+ ExactishTarget.new("username", "password", "http://exact-target.com/Service.asmx").create_subscriber("email", "country", "source")
29
+ }.should raise_error(StandardError, /^Subscription request for email: "email", country: "country", source: "source" failed. Newsletter subscription has not been created.\s+Exception: #<StandardError: Exact Target Error/)
30
+ end
31
+
32
+ it "should raise an error if an invalid response is received from ET" do
33
+ fake_exactish_target.mode = :invalid
34
+ lambda {
35
+ ExactishTarget.new("username", "password", "http://exact-target.com/Service.asmx").create_subscriber("email", "country", "source")
36
+ }.should raise_error(StandardError, /^Subscription request for email: "email", country: "country", source: "source" failed. Newsletter subscription has not been created.\s+Exception: #<StandardError: Invalid response from Exact Target/)
37
+ end
38
+
39
+ end
40
+
41
+ describe "#create_subscriber_request_xml" do
42
+
43
+ before do
44
+ @client = ExactishTarget.new("the username", "the password", "http://exact-target.com/Service.asmx")
45
+ @xml = @client.create_subscriber_request_xml("email@gmail.com", "a country", "the source")
46
+ end
47
+
48
+ it "should include the ET credentials" do
49
+ @xml.should include("<n1:UsernameToken><n1:Username>the username</n1:Username><n1:Password>the password</n1:Password></n1:UsernameToken>")
50
+ end
51
+
52
+ it "should include the subscriber's email address" do
53
+ @xml.should include("<n2:EmailAddress>email@gmail.com</n2:EmailAddress>")
54
+ end
55
+
56
+ it "should use the subscriber's email address as the customer key" do
57
+ @xml.should include("<n2:CustomerKey>email@gmail.com</n2:CustomerKey>")
58
+ end
59
+
60
+ it "should include the subscriber's country" do
61
+ @xml.should include("<n2:Attributes><n2:Name>Country</n2:Name><n2:Value>a country</n2:Value></n2:Attributes>")
62
+ end
63
+
64
+ it "should include the source of the subscription" do
65
+ @xml.should include("<n2:Attributes><n2:Name>Source</n2:Name><n2:Value>the source</n2:Value></n2:Attributes>")
66
+ end
67
+
68
+ it "should include the Lonely Planet Newsletters flag set to true" do
69
+ @xml.should include("<n2:Attributes><n2:Name>Lonely Planet Newsletters</n2:Name><n2:Value>true</n2:Value></n2:Attributes>")
70
+ end
71
+
72
+ it "should include the Lonely Planet Marketing flag set to true" do
73
+ @xml.should include("<n2:Attributes><n2:Name>Lonely Planet Marketing</n2:Name><n2:Value>true</n2:Value></n2:Attributes>")
74
+ end
75
+
76
+ it "should xml-escape field values" do
77
+ xml = @client.create_subscriber_request_xml("<email@gmail.com>", "a country & something", "the sour&ce")
78
+ xml.should include("&lt;email@gmail.com&gt;")
79
+ xml.should include("a country &amp; something")
80
+ xml.should include("sour&amp;ce")
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,8 @@
1
+ require 'rr'
2
+ require 'pp'
3
+
4
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "support"))
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.mock_with :rr
8
+ end
@@ -0,0 +1,128 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'builder'
4
+
5
+ module FakeExactishTarget
6
+
7
+ class App < Sinatra::Base
8
+
9
+ attr_accessor :mode
10
+
11
+ def initialize
12
+ @mode = :happy
13
+ end
14
+
15
+ post '/Service.asmx' do
16
+ send("#{mode}_response")
17
+ end
18
+
19
+ def happy_response
20
+ <<-XML.strip
21
+ <?xml version="1.0" encoding="utf-8"?>
22
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
23
+ <soap:Header>
24
+ <wsa:Action>CreateResponse</wsa:Action>
25
+ <wsa:MessageID>urn:uuid:d97e2a9a-48a7-4f38-b2c5-7c30c0abf37c</wsa:MessageID>
26
+ <wsa:RelatesTo>urn:uuid:259526f3-cfea-4628-8bce-f49714556f45</wsa:RelatesTo>
27
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
28
+ <wsse:Security>
29
+ <wsu:Timestamp wsu:Id="Timestamp-507733bc-b23a-454d-837b-c173836d26e9">
30
+ <wsu:Created>2011-02-22T00:32:45Z</wsu:Created>
31
+ <wsu:Expires>2011-02-22T00:37:45Z</wsu:Expires>
32
+ </wsu:Timestamp>
33
+ </wsse:Security>
34
+ </soap:Header>
35
+ <soap:Body>
36
+ <CreateResponse xmlns="http://exacttarget.com/wsdl/partnerAPI">
37
+ <Results>
38
+ <StatusCode>OK</StatusCode>
39
+ <StatusMessage>Created Subscriber.</StatusMessage>
40
+ <OrdinalID>0</OrdinalID>
41
+ <NewID>921310</NewID>
42
+ <Object xsi:type="Subscriber">
43
+ <PartnerKey xsi:nil="true"/>
44
+ <ID>921310</ID>
45
+ <ObjectID xsi:nil="true"/>
46
+ <CustomerKey>api-test-13@bh.exacttarget.com</CustomerKey>
47
+ <EmailAddress>api-test-13@bh.exacttarget.com</EmailAddress>
48
+ <Attributes>
49
+ <Name>Country</Name>
50
+ <Value>Australia</Value>
51
+ </Attributes>
52
+ <Attributes>
53
+ <Name>Source</Name>
54
+ <Value>Over the rainbow</Value>
55
+ </Attributes>
56
+ </Object>
57
+ </Results>
58
+ <RequestID>dd6710a8-5d74-48fb-a8db-c10622860a68</RequestID>
59
+ <OverallStatus>OK</OverallStatus>
60
+ </CreateResponse>
61
+ </soap:Body>
62
+ </soap:Envelope>
63
+ XML
64
+ end
65
+
66
+ def sad_response
67
+ <<-XML.strip
68
+ <?xml version="1.0" encoding="utf-8"?>
69
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
70
+ <soap:Header>
71
+ <wsa:Action>CreateResponse</wsa:Action>
72
+ <wsa:MessageID>urn:uuid:5ebdc5c1-dc28-499e-85d6-76a45eb33fc5</wsa:MessageID>
73
+ <wsa:RelatesTo>urn:uuid:59f069b9-293a-41cd-a836-fd46a6f95343</wsa:RelatesTo>
74
+ <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
75
+ <wsse:Security>
76
+ <wsu:Timestamp wsu:Id="Timestamp-d0da59eb-829d-46d9-a45c-bd5e062be276">
77
+ <wsu:Created>2011-02-22T00:37:18Z</wsu:Created>
78
+ <wsu:Expires>2011-02-22T00:42:18Z</wsu:Expires>
79
+ </wsu:Timestamp>
80
+ </wsse:Security>
81
+ </soap:Header>
82
+ <soap:Body>
83
+ <CreateResponse xmlns="http://exacttarget.com/wsdl/partnerAPI">
84
+ <Results>
85
+ <StatusCode>Error</StatusCode>
86
+ <StatusMessage>The subscriber is already on the list</StatusMessage>
87
+ <OrdinalID>0</OrdinalID>
88
+ <ErrorCode>12014</ErrorCode>
89
+ <NewID>0</NewID>
90
+ <Object xsi:type="Subscriber">
91
+ <PartnerKey xsi:nil="true"/>
92
+ <ObjectID xsi:nil="true"/>
93
+ <CustomerKey>api-test-13@bh.exacttarget.com</CustomerKey>
94
+ <EmailAddress>api-test-13@bh.exacttarget.com</EmailAddress>
95
+ <Attributes>
96
+ <Name>Country</Name>
97
+ <Value>Australia</Value>
98
+ </Attributes>
99
+ <Attributes>
100
+ <Name>Source</Name>
101
+ <Value>Over the rainbow</Value>
102
+ </Attributes>
103
+ </Object>
104
+ </Results>
105
+ <RequestID>beb6f073-5a3a-4a09-a167-7410e2957b14</RequestID>
106
+ <OverallStatus>Error</OverallStatus>
107
+ </CreateResponse>
108
+ </soap:Body>
109
+ </soap:Envelope>
110
+ XML
111
+ end
112
+
113
+ def invalid_response
114
+ <<-XML.strip
115
+ <?xml version="1.0" encoding="utf-8"?>
116
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
117
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
118
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
119
+ xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
120
+ xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
121
+ xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
122
+ </soap:Envelope>
123
+ XML
124
+ end
125
+
126
+ end
127
+
128
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exactish_target
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 2
10
+ version: 0.2.2
11
+ platform: ruby
12
+ authors:
13
+ - Lonely Planet
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-12 00:00:00 +10:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ name: builder
24
+ prerelease: false
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - "="
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 0
35
+ version: 3.0.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ name: shoulda
40
+ prerelease: false
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ name: rspec
54
+ prerelease: false
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 27
61
+ segments:
62
+ - 1
63
+ - 3
64
+ - 0
65
+ version: 1.3.0
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ name: rr
70
+ prerelease: false
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 33
77
+ segments:
78
+ - 0
79
+ - 10
80
+ - 11
81
+ version: 0.10.11
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ name: sham_rack
86
+ prerelease: false
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 27
93
+ segments:
94
+ - 1
95
+ - 3
96
+ - 0
97
+ version: 1.3.0
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ type: :development
101
+ name: sinatra
102
+ prerelease: false
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 51
109
+ segments:
110
+ - 0
111
+ - 9
112
+ - 4
113
+ version: 0.9.4
114
+ requirement: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ type: :development
117
+ name: jeweler
118
+ prerelease: false
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 7
125
+ segments:
126
+ - 1
127
+ - 5
128
+ - 2
129
+ version: 1.5.2
130
+ requirement: *id007
131
+ description: Very simple Exact Target SOAP client. Only supports subscriber creation at this point
132
+ email: daniel.vydra@lonelyplanet.com.au
133
+ executables: []
134
+
135
+ extensions: []
136
+
137
+ extra_rdoc_files:
138
+ - LICENSE.txt
139
+ - README.md
140
+ files:
141
+ - .rvmrc
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE.txt
145
+ - README.md
146
+ - Rakefile
147
+ - VERSION
148
+ - exactish_target.gemspec
149
+ - lib/exactish_target.rb
150
+ - rdoc/ExactishTarget.html
151
+ - rdoc/created.rid
152
+ - rdoc/index.html
153
+ - rdoc/lib/exactish_target_rb.html
154
+ - rdoc/rdoc.css
155
+ - spec/exact_target_spec.rb
156
+ - spec/spec_helper.rb
157
+ - spec/support/fake_exactish_target/app.rb
158
+ has_rdoc: true
159
+ homepage: https://github.com/lonelyplanet/exactish_target
160
+ licenses: []
161
+
162
+ post_install_message:
163
+ rdoc_options: []
164
+
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ requirements: []
186
+
187
+ rubyforge_project:
188
+ rubygems_version: 1.4.2
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: Exact Target client
192
+ test_files:
193
+ - spec/exact_target_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/support/fake_exactish_target/app.rb