contactology 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.markdown CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.1.2 / 2011-08-25
2
+
3
+ [full changelog](http://github.com/nbibler/contactology/compare/v0.1.1...v0.1.2)
4
+
5
+ * Enhancement
6
+ * Campaign.find_by_name now returns the newest, matching campaign
7
+ * Campaign#start_time is now returned as a Time instance
8
+
9
+ * Bug fixes
10
+ * SendResult now captures generic API errors
11
+ * Campaign children now have proper reference of their parent properties
12
+
1
13
  ### 0.1.1 / 2011-08-25
2
14
 
3
15
  [full changelog](http://github.com/nbibler/contactology/compare/v0.1.0...v0.1.1)
@@ -75,7 +75,10 @@ module Contactology
75
75
  'campaignName' => name
76
76
  },
77
77
  :on_success => Proc.new { |r|
78
- new_campaign_from_response(r.values.first) unless r.nil?
78
+ unless r.nil?
79
+ data = r.values.max { |a,b| a['startTime'] <=> b['startTime'] }
80
+ new_campaign_from_response(data)
81
+ end
79
82
  }
80
83
  }))
81
84
  end
@@ -115,6 +118,12 @@ module Contactology
115
118
  save(options) || raise(InvalidObjectError)
116
119
  end
117
120
 
121
+ def start_time
122
+ if self['start_time']
123
+ Time.strptime(self['start_time'] + 'Z', '%Y-%m-%d %H:%M:%S%Z')
124
+ end
125
+ end
126
+
118
127
  def preview(options = {})
119
128
  self.class.query('Campaign_Preview', options.merge({
120
129
  'campaignId' => id,
@@ -4,6 +4,32 @@ require 'contactology/campaign'
4
4
  require 'contactology/campaigns'
5
5
 
6
6
  class Contactology::Campaigns::Standard < Contactology::Campaign
7
+ property :content
8
+ property :content_type, :from => :contentType
9
+ property :id, :from => :campaignId
10
+ property :name, :from => :campaignName
11
+ property :recipient_name, :from => :recipientName
12
+ property :recipients
13
+ property :reply_to_email, :from => :replyToEmail
14
+ property :reply_to_name, :from => :replyToName
15
+ property :sender_email, :from => :senderEmail
16
+ property :sender_name, :from => :senderName
17
+ property :status
18
+ property :subject
19
+ property :type
20
+ property :start_time, :from => :startTime
21
+ property :authenticate
22
+ property :track_replies, :from => :trackReplies
23
+ property :show_in_archive, :from => :showInArchive
24
+ property :view_in_browser, :from => :viewInBrowser
25
+ property :track_opens, :from => :trackOpens
26
+ property :track_click_thru_html, :from => :trackClickThruHTML
27
+ property :track_click_thru_text, :from => :trackClickThruText
28
+ property :google_analytics_name, :from => :googleAnalyticsName
29
+ property :automatic_tweet, :from => :automaticTweet
30
+ property :click_tale_name, :from => :clickTaleName
31
+ property :click_tale_custom_fields, :from => :clickTaleCustomFields
32
+ property :custom_fields, :from => :customFields
7
33
  property :content, :required => true
8
34
  property :name, :from => :campaignName, :required => true
9
35
  property :recipients, :required => true
@@ -4,6 +4,32 @@ require 'contactology/campaign'
4
4
  require 'contactology/campaigns'
5
5
 
6
6
  class Contactology::Campaigns::Transactional < Contactology::Campaign
7
+ property :content
8
+ property :content_type, :from => :contentType
9
+ property :id, :from => :campaignId
10
+ property :name, :from => :campaignName
11
+ property :recipient_name, :from => :recipientName
12
+ property :recipients
13
+ property :reply_to_email, :from => :replyToEmail
14
+ property :reply_to_name, :from => :replyToName
15
+ property :sender_email, :from => :senderEmail
16
+ property :sender_name, :from => :senderName
17
+ property :status
18
+ property :subject
19
+ property :type
20
+ property :start_time, :from => :startTime
21
+ property :authenticate
22
+ property :track_replies, :from => :trackReplies
23
+ property :show_in_archive, :from => :showInArchive
24
+ property :view_in_browser, :from => :viewInBrowser
25
+ property :track_opens, :from => :trackOpens
26
+ property :track_click_thru_html, :from => :trackClickThruHTML
27
+ property :track_click_thru_text, :from => :trackClickThruText
28
+ property :google_analytics_name, :from => :googleAnalyticsName
29
+ property :automatic_tweet, :from => :automaticTweet
30
+ property :click_tale_name, :from => :clickTaleName
31
+ property :click_tale_custom_fields, :from => :clickTaleCustomFields
32
+ property :custom_fields, :from => :customFields
7
33
  property :test_contact, :from => :testContact
8
34
  property :test_replacements, :from => :testReplacements
9
35
 
@@ -171,7 +171,7 @@ module Contactology
171
171
  :email => email,
172
172
  :on_timeout => false,
173
173
  :on_error => false,
174
- :on_success => Proc.new { |response| response }
174
+ :on_success => Proc.new { |r| r }
175
175
  }))
176
176
 
177
177
  if response
@@ -11,8 +11,7 @@ module Contactology
11
11
  attr_reader :issues
12
12
 
13
13
  def initialize(response)
14
- @success = response['success']
15
- @issues = Issues.new(response['issues'])
14
+ load_response response
16
15
  end
17
16
 
18
17
  ##
@@ -33,5 +32,23 @@ module Contactology
33
32
  def score
34
33
  @issues.score
35
34
  end
35
+
36
+
37
+ private
38
+
39
+
40
+ def load_response(response)
41
+ unless erred_response?(response)
42
+ @success = response['success']
43
+ @issues = Issues.new(response['issues'])
44
+ else
45
+ @success = false
46
+ @issues = Issues.new({'issues' => [{'text' => response['message']}]})
47
+ end
48
+ end
49
+
50
+ def erred_response?(response)
51
+ response['result'] && response['result'] == 'error'
52
+ end
36
53
  end
37
54
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Contactology
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -0,0 +1,316 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: https://api.emailcampaigns.net:443/2/REST/?key=%{API_KEY}&method=List_Add_Public&name=send-standard-campaign-failure
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ user-agent:
11
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
12
+ response: !ruby/struct:VCR::Response
13
+ status: !ruby/struct:VCR::ResponseStatus
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ x-powered-by:
18
+ - PHP/5.2.10
19
+ set-cookie:
20
+ - PHPSESSID=d72aaca736a25f691286fb17d65ac320; path=/
21
+ expires:
22
+ - Thu, 19 Nov 1981 08:52:00 GMT
23
+ cache-control:
24
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
25
+ pragma:
26
+ - no-cache
27
+ content-type:
28
+ - text/plain;charset=UTF-8
29
+ transfer-encoding:
30
+ - chunked
31
+ date:
32
+ - Thu, 25 Aug 2011 17:37:48 GMT
33
+ server:
34
+ - lighttpd/1.4.28
35
+ body: "59"
36
+ http_version: "1.1"
37
+ - !ruby/struct:VCR::HTTPInteraction
38
+ request: !ruby/struct:VCR::Request
39
+ method: :get
40
+ uri: https://api.emailcampaigns.net:443/2/REST/?key=%{API_KEY}&listId=59&method=List_Get_Info
41
+ body:
42
+ headers:
43
+ accept:
44
+ - application/json
45
+ user-agent:
46
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
47
+ response: !ruby/struct:VCR::Response
48
+ status: !ruby/struct:VCR::ResponseStatus
49
+ code: 200
50
+ message: OK
51
+ headers:
52
+ x-powered-by:
53
+ - PHP/5.2.10
54
+ set-cookie:
55
+ - PHPSESSID=a275ffcf5c8044078a176546ac3ee319; path=/
56
+ expires:
57
+ - Thu, 19 Nov 1981 08:52:00 GMT
58
+ cache-control:
59
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
60
+ pragma:
61
+ - no-cache
62
+ content-type:
63
+ - text/plain;charset=UTF-8
64
+ transfer-encoding:
65
+ - chunked
66
+ date:
67
+ - Thu, 25 Aug 2011 17:37:48 GMT
68
+ server:
69
+ - lighttpd/1.4.28
70
+ body: "{\"listId\":\"59\",\"name\":\"send-standard-campaign-failure\",\"description\":null,\"type\":\"public\",\"optIn\":false}"
71
+ http_version: "1.1"
72
+ - !ruby/struct:VCR::HTTPInteraction
73
+ request: !ruby/struct:VCR::Request
74
+ method: :get
75
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Add&optionalParameters%5BupdateCustomFields%5D=true
76
+ body:
77
+ headers:
78
+ accept:
79
+ - application/json
80
+ user-agent:
81
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
82
+ response: !ruby/struct:VCR::Response
83
+ status: !ruby/struct:VCR::ResponseStatus
84
+ code: 200
85
+ message: OK
86
+ headers:
87
+ x-powered-by:
88
+ - PHP/5.2.10
89
+ set-cookie:
90
+ - PHPSESSID=2f169f359021b89c4d8195e1f13fb7c5; path=/
91
+ expires:
92
+ - Thu, 19 Nov 1981 08:52:00 GMT
93
+ cache-control:
94
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
95
+ pragma:
96
+ - no-cache
97
+ content-type:
98
+ - text/plain;charset=UTF-8
99
+ transfer-encoding:
100
+ - chunked
101
+ date:
102
+ - Thu, 25 Aug 2011 17:37:48 GMT
103
+ server:
104
+ - lighttpd/1.4.28
105
+ body: "true"
106
+ http_version: "1.1"
107
+ - !ruby/struct:VCR::HTTPInteraction
108
+ request: !ruby/struct:VCR::Request
109
+ method: :get
110
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&listId=59&method=List_Subscribe
111
+ body:
112
+ headers:
113
+ accept:
114
+ - application/json
115
+ user-agent:
116
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
117
+ response: !ruby/struct:VCR::Response
118
+ status: !ruby/struct:VCR::ResponseStatus
119
+ code: 200
120
+ message: OK
121
+ headers:
122
+ x-powered-by:
123
+ - PHP/5.2.10
124
+ set-cookie:
125
+ - PHPSESSID=43f07662c8fd27c72ab0dbddad476593; path=/
126
+ expires:
127
+ - Thu, 19 Nov 1981 08:52:00 GMT
128
+ cache-control:
129
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
130
+ pragma:
131
+ - no-cache
132
+ content-type:
133
+ - text/plain;charset=UTF-8
134
+ transfer-encoding:
135
+ - chunked
136
+ date:
137
+ - Thu, 25 Aug 2011 17:37:48 GMT
138
+ server:
139
+ - lighttpd/1.4.28
140
+ body: "true"
141
+ http_version: "1.1"
142
+ - !ruby/struct:VCR::HTTPInteraction
143
+ request: !ruby/struct:VCR::Request
144
+ method: :get
145
+ uri: https://api.emailcampaigns.net:443/2/REST/?campaignName=factory%20campaign&key=%{API_KEY}&method=Campaign_Create_Standard&senderEmail=nate@envylabs.com&senderName=Nate%20Bibler&subject=Factory%20Campaign%20Message&content%5Btext%5D=This%20is%20a%20good%20message!%20%7BCOMPANY_ADDRESS%7D&recipients%5Blist%5D=59
146
+ body:
147
+ headers:
148
+ accept:
149
+ - application/json
150
+ user-agent:
151
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
152
+ response: !ruby/struct:VCR::Response
153
+ status: !ruby/struct:VCR::ResponseStatus
154
+ code: 200
155
+ message: OK
156
+ headers:
157
+ x-powered-by:
158
+ - PHP/5.2.10
159
+ set-cookie:
160
+ - PHPSESSID=129be28999c284873e00b6c3f3f0ee38; path=/
161
+ expires:
162
+ - Thu, 19 Nov 1981 08:52:00 GMT
163
+ cache-control:
164
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
165
+ pragma:
166
+ - no-cache
167
+ content-type:
168
+ - text/plain;charset=UTF-8
169
+ transfer-encoding:
170
+ - chunked
171
+ date:
172
+ - Thu, 25 Aug 2011 17:37:52 GMT
173
+ server:
174
+ - lighttpd/1.4.28
175
+ body: "55"
176
+ http_version: "1.1"
177
+ - !ruby/struct:VCR::HTTPInteraction
178
+ request: !ruby/struct:VCR::Request
179
+ method: :get
180
+ uri: https://api.emailcampaigns.net:443/2/REST/?key=%{API_KEY}&method=Campaign_Send
181
+ body:
182
+ headers:
183
+ accept:
184
+ - application/json
185
+ user-agent:
186
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
187
+ response: !ruby/struct:VCR::Response
188
+ status: !ruby/struct:VCR::ResponseStatus
189
+ code: 200
190
+ message: OK
191
+ headers:
192
+ x-powered-by:
193
+ - PHP/5.2.10
194
+ set-cookie:
195
+ - PHPSESSID=9f35f41205970e499cff347aee24aba1; path=/
196
+ expires:
197
+ - Thu, 19 Nov 1981 08:52:00 GMT
198
+ cache-control:
199
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
200
+ pragma:
201
+ - no-cache
202
+ content-type:
203
+ - text/plain;charset=UTF-8
204
+ transfer-encoding:
205
+ - chunked
206
+ date:
207
+ - Thu, 25 Aug 2011 17:37:53 GMT
208
+ server:
209
+ - lighttpd/1.4.28
210
+ body: "{\"result\":\"error\",\"message\":\"Missing parameter campaignId for Campaign_Send\",\"code\":2}"
211
+ http_version: "1.1"
212
+ - !ruby/struct:VCR::HTTPInteraction
213
+ request: !ruby/struct:VCR::Request
214
+ method: :get
215
+ uri: https://api.emailcampaigns.net:443/2/REST/?key=%{API_KEY}&listId=59&method=List_Delete
216
+ body:
217
+ headers:
218
+ accept:
219
+ - application/json
220
+ user-agent:
221
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
222
+ response: !ruby/struct:VCR::Response
223
+ status: !ruby/struct:VCR::ResponseStatus
224
+ code: 200
225
+ message: OK
226
+ headers:
227
+ x-powered-by:
228
+ - PHP/5.2.10
229
+ set-cookie:
230
+ - PHPSESSID=51966a7f79053c9eb8315f6c8407b9df; path=/
231
+ expires:
232
+ - Thu, 19 Nov 1981 08:52:00 GMT
233
+ cache-control:
234
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
235
+ pragma:
236
+ - no-cache
237
+ content-type:
238
+ - text/plain;charset=UTF-8
239
+ transfer-encoding:
240
+ - chunked
241
+ date:
242
+ - Thu, 25 Aug 2011 17:37:54 GMT
243
+ server:
244
+ - lighttpd/1.4.28
245
+ body: "true"
246
+ http_version: "1.1"
247
+ - !ruby/struct:VCR::HTTPInteraction
248
+ request: !ruby/struct:VCR::Request
249
+ method: :get
250
+ uri: https://api.emailcampaigns.net:443/2/REST/?email=factory-contact@example.com&key=%{API_KEY}&method=Contact_Delete
251
+ body:
252
+ headers:
253
+ accept:
254
+ - application/json
255
+ user-agent:
256
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
257
+ response: !ruby/struct:VCR::Response
258
+ status: !ruby/struct:VCR::ResponseStatus
259
+ code: 200
260
+ message: OK
261
+ headers:
262
+ x-powered-by:
263
+ - PHP/5.2.10
264
+ set-cookie:
265
+ - PHPSESSID=003ae36116b60e2ebe920963943f7bb4; path=/
266
+ expires:
267
+ - Thu, 19 Nov 1981 08:52:00 GMT
268
+ cache-control:
269
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
270
+ pragma:
271
+ - no-cache
272
+ content-type:
273
+ - text/plain;charset=UTF-8
274
+ transfer-encoding:
275
+ - chunked
276
+ date:
277
+ - Thu, 25 Aug 2011 17:37:59 GMT
278
+ server:
279
+ - lighttpd/1.4.28
280
+ body: "true"
281
+ http_version: "1.1"
282
+ - !ruby/struct:VCR::HTTPInteraction
283
+ request: !ruby/struct:VCR::Request
284
+ method: :get
285
+ uri: https://api.emailcampaigns.net:443/2/REST/?key=%{API_KEY}&method=Campaign_Delete
286
+ body:
287
+ headers:
288
+ accept:
289
+ - application/json
290
+ user-agent:
291
+ - contactology/0.1.1 (Rubygems; Ruby 1.9.2 x86_64-darwin10.7.1)
292
+ response: !ruby/struct:VCR::Response
293
+ status: !ruby/struct:VCR::ResponseStatus
294
+ code: 200
295
+ message: OK
296
+ headers:
297
+ x-powered-by:
298
+ - PHP/5.2.10
299
+ set-cookie:
300
+ - PHPSESSID=479707cd9875b97d16b46972cb91467b; path=/
301
+ expires:
302
+ - Thu, 19 Nov 1981 08:52:00 GMT
303
+ cache-control:
304
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
305
+ pragma:
306
+ - no-cache
307
+ content-type:
308
+ - text/plain;charset=UTF-8
309
+ transfer-encoding:
310
+ - chunked
311
+ date:
312
+ - Thu, 25 Aug 2011 17:37:47 GMT
313
+ server:
314
+ - lighttpd/1.4.28
315
+ body: "{\"result\":\"error\",\"message\":\"Missing parameter campaignId for Campaign_Delete\",\"code\":2}"
316
+ http_version: "1.1"
@@ -74,6 +74,33 @@ describe Contactology::Campaigns::Standard do
74
74
  its(:issues) { should_not be_empty }
75
75
  its(:score) { should be < 100 }
76
76
  end
77
+
78
+ context 'when unsuccessful (attributes missing)' do
79
+ use_vcr_cassette 'campaigns/standard/send_campaign/failure_missing_attributes', record: :new_episodes
80
+ let(:list) { Factory :list, :name => 'send-standard-campaign-failure' }
81
+ let(:contact) { Factory :contact }
82
+ let(:campaign) { Factory :standard_campaign, :recipients => list }
83
+
84
+ before(:each) { list.subscribe(contact); campaign.id = nil }
85
+ after(:each) { list.destroy; contact.destroy; campaign.destroy }
86
+
87
+ subject { campaign.send_campaign }
88
+
89
+ it { should be_instance_of Contactology::SendResult }
90
+ it { should_not be_successful }
91
+
92
+ context 'issues' do
93
+ subject { campaign.send_campaign.issues }
94
+
95
+ it { should_not be_empty }
96
+
97
+ it 'contains a message about the missing ID' do
98
+ subject.any? { |i|
99
+ i.text == 'Missing parameter campaignId for Campaign_Send'
100
+ }.should be_true
101
+ end
102
+ end
103
+ end
77
104
  end
78
105
 
79
106
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: contactology
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathaniel Bibler
@@ -169,6 +169,7 @@ files:
169
169
  - spec/fixtures/net/campaigns/standard/create/invalid.yml
170
170
  - spec/fixtures/net/campaigns/standard/create/success.yml
171
171
  - spec/fixtures/net/campaigns/standard/send_campaign/failure.yml
172
+ - spec/fixtures/net/campaigns/standard/send_campaign/failure_missing_attributes.yml
172
173
  - spec/fixtures/net/campaigns/standard/send_campaign/success.yml
173
174
  - spec/fixtures/net/campaigns/transactional/create/failure.yml
174
175
  - spec/fixtures/net/campaigns/transactional/create/success.yml
@@ -257,6 +258,7 @@ test_files:
257
258
  - spec/fixtures/net/campaigns/standard/create/invalid.yml
258
259
  - spec/fixtures/net/campaigns/standard/create/success.yml
259
260
  - spec/fixtures/net/campaigns/standard/send_campaign/failure.yml
261
+ - spec/fixtures/net/campaigns/standard/send_campaign/failure_missing_attributes.yml
260
262
  - spec/fixtures/net/campaigns/standard/send_campaign/success.yml
261
263
  - spec/fixtures/net/campaigns/transactional/create/failure.yml
262
264
  - spec/fixtures/net/campaigns/transactional/create/success.yml