exact-target 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # Add support for String#underscore if ActiveSupport not available
2
+ # as well as Object#blank?
3
+
4
+ unless String.instance_methods.map(&:to_sym).include?(:underscore)
5
+ class String
6
+ def underscore
7
+ gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase
12
+ end
13
+ end
14
+ end
15
+
16
+ unless Object.instance_methods.map(&:to_sym).include?(:blank?)
17
+ class Object
18
+ def blank?
19
+ respond_to?(:empty?) ? empty? : !self
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ describe 'ExactTarget::NetHttpsHack' do
2
+
3
+ it "should ignore those annoying cert warnings" do
4
+ http = Net::HTTP.new(anything)
5
+ http.instance_variable_get(:@ssl_context).verify_mode.should == OpenSSL::SSL::VERIFY_NONE
6
+ end
7
+
8
+ end
@@ -0,0 +1,15 @@
1
+ describe ExactTarget::ResponseHandler do
2
+
3
+ before(:all) do
4
+ @handler = ExactTarget::ResponseHandler.new(stub :config)
5
+ end
6
+
7
+ it "should throw error when failure handling id result" do
8
+ info = stub(:info, :text => 'BOGUS')
9
+ resp = stub(:response, :xpath => [info], :to_s => 'BOGUS<s>')
10
+ expect {
11
+ @handler.send(:handle_id_result, resp, :info_tag, :id_tag, /success/i)
12
+ }.should raise_error(ExactTarget::Error, 'ExactTarget error #0: Unsupported id result: BOGUS<s>')
13
+ end
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+ describe 'ExactTarget::StringExt' do
2
+
3
+ specify :underscore do
4
+ "Foo::BarExt-Stuff".underscore.should == 'foo/bar_ext_stuff'
5
+ end
6
+
7
+ specify :blank? do
8
+ "foo".blank?.should be_false
9
+ "".blank?.should be_true
10
+ nil.blank?.should be_true
11
+ end
12
+
13
+ end
@@ -0,0 +1,133 @@
1
+ ---
2
+ accountinfo_retrieve_attrbs:
3
+ request: <system_name>accountinfo</system_name><action>retrieve_attrbs</action><search_type></search_type><search_value></search_value>
4
+ response: <profile><attribute><name>A1</name><description>A1 description</description><default_value/><data_type>text</data_type><required>False</required><min_size>0</min_size><max_size>100</max_size><subscriber_editable>1</subscriber_editable><display>A1 name</display></attribute><attribute><name>A2</name><description>A2 description</description><default_value>HTML</default_value><data_type>text</data_type><required>True</required><min_size>0</min_size><max_size>2000</max_size><subscriber_editable>1</subscriber_editable><display>A2 name</display><values><value>HTML</value><value>Text</value></values></attribute></profile>
5
+
6
+ list_retrieve:
7
+ epub test:
8
+ request: <system_name>list</system_name><action>retrieve</action><search_type>listname</search_type><search_value>epub test</search_value>
9
+ response: <list><listid>42</listid><listid>47</listid></list>
10
+ 42:
11
+ request: <system_name>list</system_name><action>retrieve</action><search_type>listid</search_type><search_value>42</search_value>
12
+ response: <list><list_name>My Test List</list_name><list_type>Private</list_type><modified>1/25/2010 1:26:58 PM</modified><subscriber_count>15287</subscriber_count><active_total>9426</active_total><held_count>120</held_count><bounce_count>4145</bounce_count><unsub_count>1596</unsub_count></list>
13
+
14
+ list_add:
15
+ request: <system_name>list</system_name><action>add</action><search_type></search_type><search_value></search_value><list_type>private</list_type><list_name>Epub Test</list_name>
16
+ response: <list><list_info>List was added successfully</list_info><list_description>53</list_description></list>
17
+
18
+ list_edit:
19
+ request: <system_name>list</system_name><action>edit</action><search_type>listid</search_type><search_value>42</search_value><list_name>Epub Test - RENAME</list_name>
20
+ response: <list><list_info>List was modified successfully</list_info><list_description>42</list_description></list>
21
+
22
+ list_import:
23
+ request: <system_name>list</system_name><action>import</action><search_type>listid</search_type><search_values><search_value>72</search_value><search_value>33</search_value><search_value>99</search_value></search_values><file_name>sometestfile.txt</file_name><email_address>testme@nowhere.com</email_address><file_type>tab</file_type><column_headings>true</column_headings><file_mapping><field>some_field</field><field>other_field</field></file_mapping><import_type>0</import_type><returnid>true</returnid><encrypted>false</encrypted><encrypt_format></encrypt_format>
24
+ response: <list><import_info>Your file is being imported. You will receive an email when it completes.</import_info><importid>841</importid></list>
25
+
26
+ list_importstatus:
27
+ request: <system_name>list</system_name><action>import</action><sub_action>importstatus</sub_action><search_value>119792</search_value>
28
+ response: <list><import_info>Complete</import_info><importid>979804</importid></list>
29
+
30
+ list_retrieve_sub:
31
+ request: <system_name>list</system_name><action>retrieve_sub</action><search_type>listid</search_type><search_value>42</search_value><search_status>Active</search_status>
32
+ response: <list><subscribers><subscriber><Email__Address>bob@example.com</Email__Address><Status>Active</Status><Email__Type>HTML</Email__Type><First__Name>Bob</First__Name><Last__Name/></subscriber><subscriber><Email__Address>mary@example.com</Email__Address><Status>Active</Status><Email__Type>HTML</Email__Type><First__Name>Mary</First__Name><Last__Name>Smith</Last__Name></subscriber></subscribers></list>
33
+
34
+ list_delete:
35
+ request: <system_name>list</system_name><action>delete</action><search_type>listid</search_type><search_value>42</search_value>
36
+ response: <list><list_info>List was deleted successfully</list_info><list_description>42</list_description></list>
37
+
38
+ list_retrievegroups:
39
+ request: <system_name>list</system_name><action>retrievegroups</action><search_type>groups</search_type><search_value></search_value>
40
+ response: <list><groups><group><parentlistID>41</parentlistID><groupID>12</groupID><groupName>yyy</groupName><description>xxx</description></group><group><parentlistID>77</parentlistID><groupID>875</groupID><groupName>test group</groupName><description>test desc</description></group></groups></list>
41
+
42
+ list_refresh_group:
43
+ request: <system_name>list</system_name><action>refresh_group</action><sub_action></sub_action><search_value>3514</search_value><search_value2></search_value2>
44
+ response: <list><groupRefresh><groupID>3514</groupID><groupAsyncID>6127</groupAsyncID></groupRefresh></list>
45
+
46
+ batch_inquire:
47
+ request: <system_name>batch</system_name><action>inquire</action><sub_action></sub_action><search_type>batchid</search_type><search_value>8912</search_value><search_value2></search_value2>
48
+ response: <Batch><batchid>40594104</batchid><status>Completed</status><filename></filename></Batch>
49
+
50
+ ####################################################################################
51
+
52
+ subscriber_add:
53
+ request: <system_name>subscriber</system_name><action>add</action><search_type>listid</search_type><search_value>1234</search_value><search_value2></search_value2><values><Email__Address>someone@somehwere.com</Email__Address><Email__Type>HTML</Email__Type><First__Name>Some</First__Name><Last__Name>One</Last__Name><Title>Director of HR</Title><Region>Midwest</Region><status>active</status><ChannelMemberID>5678</ChannelMemberID></values><update>true</update>
54
+ response: <subscriber><subscriber_info>Subscriber was added/updated successfully</subscriber_info><subscriber_description>12334566</subscriber_description></subscriber>
55
+
56
+ subscriber_edit:
57
+ request: <system_name>subscriber</system_name><action>edit</action><search_type>listid</search_type><search_value>63718</search_value><search_value2>user@email.com</search_value2><values><Email__Address>someone@somehwere.com</Email__Address><Email__Type>HTML</Email__Type><First__Name>Some</First__Name><Last__Name>One</Last__Name><Title>Director of HR</Title><Region>Midwest</Region><status>unsub</status><reason>insert your unsubscribe reason here</reason><ChannelMemberID>5678</ChannelMemberID></values>
58
+ response: <subscriber><subscriber_info>Subscriber was added/updated successfully</subscriber_info><subscriber_description>12334566</subscriber_description></subscriber>
59
+
60
+ subscriber_retrieve:
61
+ '123456, someone@example.com':
62
+ request: <system_name>subscriber</system_name><action>retrieve</action><search_type>listid</search_type><search_value>123456</search_value><search_value2>someone@example.com</search_value2>
63
+ response: <subscriber><subid>125704849</subid><listid>63718</listid><list_name>Newsletter List</list_name><Email__Address>jdoe@example.com</Email__Address><Status>Active</Status><Email__Type>HTML</Email__Type><First__Name>John</First__Name><Last__Name>Doe</Last__Name><Title/><Region/><showChannelID>123456</showChannelID></subscriber>
64
+
65
+ 123456789:
66
+ request: <system_name>subscriber</system_name><action>retrieve</action><search_type>subid</search_type><search_value>123456789</search_value><search_value2></search_value2>
67
+ response: <subscriber><subid>125704849</subid><listid>63718</listid><list_name>NewsletterList</list_name><Email__Address>jdoe@example.com</Email__Address><Status>Active</Status><Email__Type>HTML</Email__Type><First__Name>John</First__Name><Last__Name>Doe</Last__Name><Title/><Region/></subscriber><subscriber><subid>125504849</subid><listid>63719</listid><list_name>TechnologyUpdate</list_name><Email__Address>jdoe@example.com</Email__Address><Status>Active</Status><Email__Type>HTML</Email__Type><First__Name>John</First__Name><Last__Name>Doe</Last__Name><Title/><Region/></subscriber>
68
+
69
+ subscriber_delete:
70
+ '112233445566, bob@hotmail.com':
71
+ request: <system_name>subscriber</system_name><action>delete</action><search_type>listid</search_type><search_value>112233445566</search_value><search_value2>bob@hotmail.com</search_value2>
72
+ response: <subscriber><subscriber_info> Subscriber Deleted Successfully </subscriber_info></subscriber>
73
+
74
+ 112233445566:
75
+ request: <system_name>subscriber</system_name><action>delete</action><search_type>subid</search_type><search_value>112233445566</search_value><search_value2></search_value2>
76
+ response: <subscriber><subscriber_info> Subscriber Deleted Successfully </subscriber_info></subscriber>
77
+
78
+ subscriber_masterunsub:
79
+ request: <system_name>subscriber</system_name><action>masterunsub</action><search_type>emailaddress</search_type><search_value><emailaddress>Email1@example.com</emailaddress><emailaddress>Email2@example.com</emailaddress><emailaddress>Email3@example.com</emailaddress></search_value>
80
+ response: <subscriber><subscriberunsub><emailaddress>Email1@example.com</emailaddress><status>masterunsub</status></subscriberunsub><subscriberunsub><emailaddress>Email2@example.com</emailaddress><status>masterunsub</status></subscriberunsub><subscriberunsub><emailaddress>Email3@example.com</emailaddress><status>masterunsub</status></subscriberunsub></subscriber>
81
+
82
+ ####################################################################################
83
+
84
+ email_retrieve:
85
+ '':
86
+ request: <system_name>email</system_name><action>retrieve</action><sub_action>all</sub_action><search_type></search_type><search_value></search_value><search_value2></search_value2><daterange></daterange>
87
+ response: <email><emaillist><emailid>104022</emailid><emailname>HTML Training</emailname><emailsubject>Northern Outfitters</emailsubject><emailcreateddate>3/1/2004</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>138167</emailid><emailname>Conversion Tracking</emailname><emailsubject>Conversion Tracking Advanced Test</emailsubject><emailcreateddate>9/23/2003</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>205449</emailid><emailname>ET 04 Demo Email</emailname><emailsubject>ET 04 Demo Email</emailsubject><emailcreateddate>3/19/2004</emailcreateddate><categoryid>75163</categoryid></emaillist></email>
88
+
89
+ 'Welcome to Fortune One!':
90
+ request: <system_name>email</system_name><action>retrieve</action><sub_action>all</sub_action><search_type>emailname</search_type><search_value>Welcome to Fortune One!</search_value><search_value2></search_value2><daterange></daterange>
91
+ response: <email><emaillist><emailid>104022</emailid><emailname>HTML Training</emailname><emailsubject>Northern Outfitters</emailsubject><emailcreateddate>3/1/2004</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>138167</emailid><emailname>Conversion Tracking</emailname><emailsubject>Conversion Tracking Advanced Test</emailsubject><emailcreateddate>9/23/2003</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>205449</emailid><emailname>ET 04 Demo Email</emailname><emailsubject>ET 04 Demo Email</emailsubject><emailcreateddate>3/19/2004</emailcreateddate><categoryid>75163</categoryid></emaillist></email>
92
+
93
+ HASH:
94
+ request: <system_name>email</system_name><action>retrieve</action><sub_action>all</sub_action><search_type>daterange</search_type><search_value></search_value><search_value2></search_value2><daterange><startdate>9/15/2008</startdate><enddate>10/15/2008</enddate></daterange>
95
+ response: <email><emaillist><emailid>104022</emailid><emailname>HTML Training</emailname><emailsubject>Northern Outfitters</emailsubject><emailcreateddate>3/1/2004</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>138167</emailid><emailname>Conversion Tracking</emailname><emailsubject>Conversion Tracking Advanced Test</emailsubject><emailcreateddate>9/23/2003</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>205449</emailid><emailname>ET 04 Demo Email</emailname><emailsubject>ET 04 Demo Email</emailsubject><emailcreateddate>3/19/2004</emailcreateddate><categoryid>75163</categoryid></emaillist></email>
96
+
97
+ 'Welcome to Fortune One!, HASH':
98
+ request: <system_name>email</system_name><action>retrieve</action><sub_action>all</sub_action><search_type>emailnameanddaterange</search_type><search_value>Welcome to Fortune One!</search_value><search_value2></search_value2><daterange><startdate>9/15/2008</startdate><enddate>10/15/2008</enddate></daterange>
99
+ response: <email><emaillist><emailid>104022</emailid><emailname>HTML Training</emailname><emailsubject>Northern Outfitters</emailsubject><emailcreateddate>3/1/2004</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>138167</emailid><emailname>Conversion Tracking</emailname><emailsubject>Conversion Tracking Advanced Test</emailsubject><emailcreateddate>9/23/2003</emailcreateddate><categoryid>75163</categoryid></emaillist><emaillist><emailid>205449</emailid><emailname>ET 04 Demo Email</emailname><emailsubject>ET 04 Demo Email</emailsubject><emailcreateddate>3/19/2004</emailcreateddate><categoryid>75163</categoryid></emaillist></email>
100
+
101
+ email_add:
102
+ 'Your body email name, Your email subject line, HASH':
103
+ request: <system_name>email</system_name><action>add</action><sub_action>HTMLPaste</sub_action><category/><email_name>Your body email name</email_name><email_subject>Your email subject line</email_subject><email_body><![CDATA[Your HTML email body]]></email_body>
104
+ response: <email><emailID>44180</emailID></email>
105
+
106
+ 'Your file email name, Your email subject line, HASH':
107
+ request: <system_name>email</system_name><action>add</action><sub_action>HTMLPaste</sub_action><category/><email_name>Your file email name</email_name><email_subject>Your email subject line</email_subject><file_name>Filename</file_name>
108
+ response: <email><emailID>44180</emailID></email>
109
+
110
+ email_add_text:
111
+ '155324, HASH':
112
+ request: <system_name>email</system_name><action>add</action><sub_action>text</sub_action><search_type>emailid</search_type><search_value>155324</search_value><email_body><![CDATA[Your text email body]]></email_body>
113
+ response: <email><email_info>Email updated successfully/email_info></email>
114
+
115
+ '155325, HASH':
116
+ request: <system_name>email</system_name><action>add</action><sub_action>text</sub_action><search_type>emailid</search_type><search_value>155325</search_value><file_name>Filename</file_name>
117
+ response: <email><email_info>Email updated successfully/email_info></email>
118
+
119
+ email_retrieve_body:
120
+ request: <system_name>email</system_name><action>retrieve</action><sub_action>htmlemail</sub_action><search_type>emailid</search_type><search_value>12344556</search_value><search_value2/><search_value3/>
121
+ response: <email><emailid>932890</emailid><htmlbody><![CDATA[<h1>...BODY...</h1>]]></htmlbody></email>
122
+
123
+ ####################################################################################
124
+
125
+ job_send:
126
+ request: <system_name>job</system_name><action>send</action><search_type>emailid</search_type><search_value>112233</search_value><from_name>FrName</from_name><from_email>fr.email@nowhere.com</from_email><additional>addit</additional><multipart_mime>true</multipart_mime><track_links>false</track_links><send_date>5/3/2011</send_date><send_time>17:35</send_time><lists><list>12345</list><list>12346</list></lists><suppress><list>35612</list></suppress><test_send>true</test_send>
127
+ response: <job><job_info>Job was successfully created.</job_info><job_description>2030602</job_description></job>
128
+
129
+ 'BOGUS, , ':
130
+ request: <system_name>job</system_name><action>send</action><search_type>emailid</search_type><search_value>BOGUS</search_value><from_name></from_name><from_email></from_email><additional></additional><multipart_mime>false</multipart_mime><track_links>true</track_links><send_date>immediate</send_date><send_time></send_time><lists></lists><suppress></suppress><test_send>false</test_send>
131
+ response: <list><error>68</error><error_description>File does not exist.</error_description></list>
132
+
133
+ ####################################################################################
@@ -0,0 +1,382 @@
1
+ require 'rubygems'
2
+ require 'exact_target'
3
+ require 'yaml'
4
+
5
+ describe ExactTarget do
6
+
7
+ def self.test_et(method, *args, &block)
8
+ desc = method.to_s
9
+ desc << " with #{args.inspect}" unless args.empty?
10
+ specify(desc) do
11
+ @res = et_request(method, args.map { |a| a.is_a?(Proc) ? a.call : a }, desc)
12
+ instance_eval(&block)
13
+ end
14
+ end
15
+
16
+ #################################################################
17
+
18
+ before(:all) do
19
+ @logger = mock(:logger)
20
+ @xml = YAML.load(File.read __FILE__.sub('_spec.rb', '_data.yml'))
21
+ ExactTarget.configure do |config|
22
+ config.base_url = 'https://base.url.com/foo'
23
+ config.username = 'a_user'
24
+ config.password = 'a_pass'
25
+ config.logger = @logger
26
+ end
27
+ end
28
+
29
+ before(:each) do
30
+ @atts = ['Email Address', 'Status', 'Email Type', 'First Name',
31
+ 'Last Name', 'Title', 'Region'].map do |a|
32
+ stub :att, :name => a
33
+ end
34
+ end
35
+
36
+ @example_subscriber = Proc.new do
37
+ ExactTarget::Subscriber.new.tap do |sub|
38
+ sub.email_address = 'someone@somehwere.com'
39
+ sub.status = 'active'
40
+ sub.email_type = 'HTML'
41
+ sub.first_name = 'Some'
42
+ sub.last_name = 'One'
43
+ sub.title = 'Director of HR'
44
+ sub.region = 'Midwest'
45
+ end
46
+ end
47
+
48
+ specify "Subscriber constant" do
49
+ ExactTarget.should_receive(:subscriber_class).and_return('SC')
50
+ ExactTarget::Subscriber.should == 'SC'
51
+ expect { ExactTarget::BogusConstant }.should raise_error
52
+ end
53
+
54
+ specify :subscriber_class do
55
+ ExactTarget.should_receive(:accountinfo_retrieve_attrbs).once.and_return(@atts)
56
+ clazz = ExactTarget.send(:subscriber_class)
57
+ clazz.should == ExactTarget.send(:subscriber_class)
58
+ s = clazz.new
59
+ s.first_name = 'Da'
60
+ s.Email__Address = 'foo@bar.com'
61
+ s.region = 42
62
+ s.First__Name.should == 'Da'
63
+ s.email_address.should == 'foo@bar.com'
64
+ s.to_s.should == 'foo@bar.com'
65
+ end
66
+
67
+ test_et :accountinfo_retrieve_attrbs do
68
+ @res.size.should == 2
69
+
70
+ @res = @res.last
71
+ @res.is_a?(ExactTarget::ListProfileAttribute).should be_true
72
+ @res.default_value.should == 'HTML'
73
+ @res.min_size.should == 0
74
+ @res.max_size.should == 2000
75
+ @res.values.should == %w(HTML Text)
76
+ @res.display.should == 'A2 name'
77
+ @res.required.should be_true
78
+ @res.name.should == 'A2'
79
+ @res.subscriber_editable.should == 1
80
+ @res.data_type.should == 'text'
81
+ @res.description.should == 'A2 description'
82
+ @res.to_s.should == 'A2'
83
+ end
84
+
85
+ test_et :list_retrieve, 'epub test' do
86
+ @res.should == [42, 47]
87
+ end
88
+
89
+ test_et :list_retrieve, 42 do
90
+ @res.should be_a(ExactTarget::ListInformation)
91
+ @res.unsub_count.should == 1596
92
+ @res.subscriber_count.should == 15287
93
+ @res.bounce_count.should == 4145
94
+ @res.modified.should be_a(DateTime)
95
+ @res.held_count.should == 120
96
+ @res.list_type.should == 'Private'
97
+ @res.active_total.should == 9426
98
+ @res.list_name.should == 'My Test List'
99
+ @res.to_s.should == 'My Test List'
100
+ end
101
+
102
+ test_et :list_add, "Epub Test", :private do
103
+ @res.should == 53
104
+ end
105
+
106
+ test_et :list_edit, 42, "Epub Test - RENAME" do
107
+ @res.should == 42
108
+ end
109
+
110
+ test_et :list_import, [72, 33, 99], 'sometestfile.txt',
111
+ %w(some_field other_field),
112
+ :email_address => 'testme@nowhere.com' do
113
+ @res.should == 841
114
+ end
115
+
116
+ test_et :list_importstatus, 119792 do
117
+ @res.should == 'Complete'
118
+ end
119
+
120
+ test_et :list_retrieve_sub, 42, 'Active' do
121
+ @res.size.should == 2
122
+
123
+ @res = @res.last
124
+ @res.status.should == "Active"
125
+ @res.first_name.should == "Mary"
126
+ @res.last_name.should == "Smith"
127
+ @res.email_type.should == "HTML"
128
+ @res.email_address.should == "mary@example.com"
129
+ @res.to_s.should == "mary@example.com"
130
+ end
131
+
132
+ test_et :list_delete, 42 do
133
+ @res.should == 42
134
+ end
135
+
136
+ test_et :list_retrievegroups do
137
+ @res.size.should == 2
138
+
139
+ @res = @res.last
140
+ @res.should be_a(ExactTarget::ListGroupInformation)
141
+ @res.group_id.should == 875
142
+ @res.parentlist_id.should == 77
143
+ @res.description.should == "test desc"
144
+ @res.group_name.should == "test group"
145
+ @res.to_s.should == "test group"
146
+ end
147
+
148
+ test_et :list_refresh_group, 3514 do
149
+ @res.should == 6127
150
+ end
151
+
152
+ test_et :batch_inquire, 8912 do
153
+ @res.should == 'Completed'
154
+ end
155
+
156
+ #################################################################
157
+
158
+ test_et :subscriber_add, 1234, @example_subscriber, :status => 'active', :ChannelMemberID => 5678 do
159
+ @res.should == 12334566
160
+ end
161
+
162
+ test_et :subscriber_edit, 63718, 'user@email.com', @example_subscriber,
163
+ :status => 'unsub',
164
+ :reason => 'insert your unsubscribe reason here',
165
+ :ChannelMemberID => 5678 do
166
+ @res.should == 12334566
167
+ end
168
+
169
+ test_et :subscriber_retrieve, 123456, 'someone@example.com' do
170
+ @res.size.should == 1
171
+
172
+ @res = @res.last
173
+ @res.should be_a(ExactTarget::SubscriberInformation)
174
+ @res.subid.should == 125704849
175
+ @res.listid.should == 63718
176
+ @res.list_name.should == 'Newsletter List'
177
+
178
+ @res = @res.subscriber
179
+ @res.email_address.should == "jdoe@example.com"
180
+ @res.first_name.should == "John"
181
+ @res.region.should == ""
182
+ @res.email_type.should == "HTML"
183
+ @res.title.should == ""
184
+ @res.status.should == "Active"
185
+ @res.last_name.should == "Doe"
186
+ end
187
+
188
+ test_et :subscriber_retrieve, 123456789 do
189
+ @res.size.should == 2
190
+
191
+ @res = @res.last
192
+ @res.should be_a(ExactTarget::SubscriberInformation)
193
+ @res.subid.should == 125504849
194
+ @res.listid.should == 63719
195
+ @res.list_name.should == 'TechnologyUpdate'
196
+
197
+ @res = @res.subscriber
198
+ @res.email_address.should == "jdoe@example.com"
199
+ @res.first_name.should == "John"
200
+ @res.region.should == ""
201
+ @res.email_type.should == "HTML"
202
+ @res.title.should == ""
203
+ @res.status.should == "Active"
204
+ @res.last_name.should == "Doe"
205
+ end
206
+
207
+ test_et :subscriber_delete, 112233445566, 'bob@hotmail.com' do
208
+ @res.should be_true
209
+ end
210
+
211
+ test_et :subscriber_delete, 112233445566 do
212
+ @res.should be_true
213
+ end
214
+
215
+ test_et :subscriber_masterunsub,
216
+ %w(Email1@example.com Email2@example.com Email3@example.com) do
217
+ @res.size.should == 3
218
+ (1..3).each do |i|
219
+ @res["Email#{i}@example.com"].should == "masterunsub"
220
+ end
221
+ end
222
+
223
+ #################################################################
224
+
225
+ test_et :email_retrieve do
226
+ verify_email_retrieve
227
+ end
228
+
229
+ test_et :email_retrieve, 'Welcome to Fortune One!' do
230
+ verify_email_retrieve
231
+ end
232
+
233
+ test_et :email_retrieve, :start_date => Date.parse('2008-09-15'),
234
+ :end_date => Date.parse('2008-10-15') do
235
+ verify_email_retrieve
236
+ end
237
+
238
+ test_et :email_retrieve, 'Welcome to Fortune One!',
239
+ :start_date => Date.parse('2008-09-15'),
240
+ :end_date => Date.parse('2008-10-15') do
241
+ verify_email_retrieve
242
+ end
243
+
244
+ def verify_email_retrieve
245
+ @res.size.should == 3
246
+
247
+ @res = @res.last
248
+ @res.emailid.should == 205449
249
+ @res.emailname.should == 'ET 04 Demo Email'
250
+ @res.emailsubject.should == 'ET 04 Demo Email'
251
+ @res.emailcreateddate.should == Date.parse('2004-03-19')
252
+ @res.categoryid.should == 75163
253
+ @res.to_s.should == 'ET 04 Demo Email'
254
+ end
255
+
256
+ test_et :email_add, 'Your body email name',
257
+ 'Your email subject line',
258
+ :body => 'Your HTML email body' do
259
+ @res.should == 44180
260
+ end
261
+
262
+ test_et :email_add, 'Your file email name',
263
+ 'Your email subject line',
264
+ :file => 'Filename' do
265
+ @res.should == 44180
266
+ end
267
+
268
+ test_et :email_add_text, 155324, :body => 'Your text email body' do
269
+ @res.should be_true
270
+ end
271
+
272
+ test_et :email_add_text, 155325, :file => 'Filename' do
273
+ @res.should be_true
274
+ end
275
+
276
+ test_et :email_retrieve_body, 12344556 do
277
+ @res.should == '<h1>...BODY...</h1>'
278
+ end
279
+
280
+ #################################################################
281
+
282
+ test_et :job_send, 112233, [12345, 12346],
283
+ :suppress_ids => 35612,
284
+ :from_name => 'FrName',
285
+ :from_email => 'fr.email@nowhere.com',
286
+ :additional => 'addit',
287
+ :multipart_mime => true,
288
+ :track_links => false,
289
+ :send_date => '5/3/2011',
290
+ :send_time => '17:35',
291
+ :test_send => true do
292
+ @res.should == 2030602
293
+ end
294
+
295
+ specify "job_send with error" do
296
+ expect do
297
+ et_request :job_send, [:BOGUS, nil, nil], "job send with error"
298
+ end.should raise_error(
299
+ ExactTarget::Error,
300
+ 'ExactTarget error #68: File does not exist.'
301
+ )
302
+ end
303
+
304
+ #################################################################
305
+
306
+ context :send_to_exact_target do
307
+ before(:each) do
308
+ @path = '/foo?qf=xml&xml=%3Csomexml/%3E'
309
+ @http = mock('Net::HTTP')
310
+ @http.should_receive(:use_ssl=).with(true)
311
+ @http.should_receive(:open_timeout=).with(2)
312
+ @http.should_receive(:read_timeout=).with(5)
313
+ Net::HTTP.should_receive(:new).with('base.url.com', 443).and_return(@http)
314
+ end
315
+
316
+ specify :success do
317
+ resp = stub('Net::HTTPSuccess', :is_a? => true, :body => 'xyz')
318
+ @http.should_receive(:get).with(@path).and_return(resp)
319
+ ExactTarget.send_to_exact_target('<somexml/>').should == 'xyz'
320
+ end
321
+
322
+ specify :error do
323
+ resp = stub('Net::HTTPFailure', :error! => 'err')
324
+ @http.should_receive(:get).with(@path).and_return(resp)
325
+ ExactTarget.send_to_exact_target('<somexml/>').should == 'err'
326
+ end
327
+ end
328
+
329
+ specify "method_missing should throw normal error when bogus method" do
330
+ expect { ExactTarget.bogus }.should raise_error
331
+ end
332
+
333
+ #################################################################
334
+
335
+ private
336
+
337
+ def et_request(method, args, desc)
338
+ request, response = et_xml(method, args, desc)
339
+ request = <<-END.gsub(/>\s+</m, '><').strip
340
+ <?xml version="1.0"?>
341
+ <exacttarget>
342
+ <authorization>
343
+ <username>a_user</username>
344
+ <password>a_pass</password>
345
+ </authorization>
346
+ <system>
347
+ #{request}
348
+ </system>
349
+ </exacttarget>
350
+ END
351
+ response = <<-END.gsub(/>\s+</m, '><').strip
352
+ <?xml version='1.0'?>
353
+ <exacttarget>
354
+ <system>
355
+ #{response}
356
+ </system>
357
+ </exacttarget>
358
+ END
359
+ @logger.should_receive(:debug).twice
360
+ ExactTarget.should_receive(:send_to_exact_target).with(request).and_return(response)
361
+ unless method == :accountinfo_retrieve_attrbs
362
+ ExactTarget.stub :accountinfo_retrieve_attrbs => @atts
363
+ end
364
+ ExactTarget.send(method, *args)
365
+ end
366
+
367
+ def et_xml(method, args, desc)
368
+ xml = @xml[method.to_s] || {}
369
+ args = args.map { |a| a.is_a?(Hash) ? 'HASH' : a }
370
+ if args.size == 1 and xml.has_key?(k = args.first)
371
+ xml = xml[k]
372
+ elsif xml.has_key?(k = args.join(', '))
373
+ xml = xml[k]
374
+ elsif xml.has_key?(k = args.hash)
375
+ xml = xml[k]
376
+ end
377
+ %w(request response).map do |k|
378
+ xml[k] or raise "Can not determine #{k} xml for #{desc}"
379
+ end
380
+ end
381
+
382
+ end