createsend 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.
Files changed (55) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +3 -0
  3. data/README.md +3 -0
  4. data/Rakefile +23 -0
  5. data/config.example.yaml +2 -0
  6. data/createsend.gemspec +26 -0
  7. data/lib/campaign.rb +90 -0
  8. data/lib/client.rb +117 -0
  9. data/lib/createsend.rb +103 -0
  10. data/lib/list.rb +99 -0
  11. data/lib/subscriber.rb +49 -0
  12. data/lib/template.rb +38 -0
  13. data/test/campaign_test.rb +98 -0
  14. data/test/client_test.rb +107 -0
  15. data/test/createsend_test.rb +96 -0
  16. data/test/fixtures/active_subscribers.json +67 -0
  17. data/test/fixtures/add_subscriber.json +1 -0
  18. data/test/fixtures/apikey.json +3 -0
  19. data/test/fixtures/bounced_subscribers.json +9 -0
  20. data/test/fixtures/campaign_bounces.json +16 -0
  21. data/test/fixtures/campaign_clicks.json +23 -0
  22. data/test/fixtures/campaign_lists.json +10 -0
  23. data/test/fixtures/campaign_opens.json +32 -0
  24. data/test/fixtures/campaign_summary.json +9 -0
  25. data/test/fixtures/campaign_unsubscribes.json +9 -0
  26. data/test/fixtures/campaigns.json +18 -0
  27. data/test/fixtures/client_details.json +25 -0
  28. data/test/fixtures/clients.json +10 -0
  29. data/test/fixtures/countries.json +247 -0
  30. data/test/fixtures/create_campaign.json +1 -0
  31. data/test/fixtures/create_client.json +1 -0
  32. data/test/fixtures/create_custom_field.json +1 -0
  33. data/test/fixtures/create_list.json +1 -0
  34. data/test/fixtures/create_template.json +1 -0
  35. data/test/fixtures/custom_api_error.json +4 -0
  36. data/test/fixtures/custom_fields.json +20 -0
  37. data/test/fixtures/drafts.json +14 -0
  38. data/test/fixtures/import_subscribers.json +7 -0
  39. data/test/fixtures/list_details.json +7 -0
  40. data/test/fixtures/list_stats.json +26 -0
  41. data/test/fixtures/lists.json +10 -0
  42. data/test/fixtures/segments.json +10 -0
  43. data/test/fixtures/subscriber_details.json +20 -0
  44. data/test/fixtures/subscriber_history.json +45 -0
  45. data/test/fixtures/suppressionlist.json +12 -0
  46. data/test/fixtures/systemdate.json +3 -0
  47. data/test/fixtures/template_details.json +6 -0
  48. data/test/fixtures/templates.json +14 -0
  49. data/test/fixtures/timezones.json +99 -0
  50. data/test/fixtures/unsubscribed_subscribers.json +21 -0
  51. data/test/helper.rb +36 -0
  52. data/test/list_test.rb +107 -0
  53. data/test/subscriber_test.rb +73 -0
  54. data/test/template_test.rb +38 -0
  55. metadata +256 -0
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class SubscriberTest < Test::Unit::TestCase
4
+ context "when an api caller is authenticated" do
5
+ setup do
6
+ @api_key = '123123123123123123123'
7
+ CreateSend.api_key @api_key
8
+ @list_id = "d98h2938d9283d982u3d98u88"
9
+ @subscriber = Subscriber.new @list_id, "subscriber@example.com"
10
+ end
11
+
12
+ should "get a subscriber by list id and email address" do
13
+ email = "subscriber@example.com"
14
+ stub_get(@api_key, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", "subscriber_details.json")
15
+ subscriber = Subscriber.get @list_id, email
16
+ subscriber.EmailAddress.should == email
17
+ subscriber.Name.should == "Subscriber One"
18
+ subscriber.Date.should == "2010-10-25 10:28:00"
19
+ subscriber.State.should == "Active"
20
+ subscriber.CustomFields.size.should == 3
21
+ subscriber.CustomFields.first.Key.should == 'website'
22
+ subscriber.CustomFields.first.Value.should == 'http://example.com'
23
+ end
24
+
25
+ should "add a subscriber without custom fields" do
26
+ stub_post(@api_key, "subscribers/#{@list_id}.json", "add_subscriber.json")
27
+ email_address = Subscriber.add @list_id, "subscriber@example.com", "Subscriber", [], true
28
+ email_address.should == "subscriber@example.com"
29
+ end
30
+
31
+ should "add a subscriber with custom fields" do
32
+ stub_post(@api_key, "subscribers/#{@list_id}.json", "add_subscriber.json")
33
+ custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ]
34
+ email_address = Subscriber.add @list_id, "subscriber@example.com", "Subscriber", custom_fields, true
35
+ email_address.should == "subscriber@example.com"
36
+ end
37
+
38
+ should "import many subscribers at once" do
39
+ stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json")
40
+ subscribers = [
41
+ { :EmailAddress => "example+1@example.com", :Name => "Example One" },
42
+ { :EmailAddress => "example+2@example.com", :Name => "Example Two" },
43
+ { :EmailAddress => "example+3@example.com", :Name => "Example Three" },
44
+ ]
45
+ import_result = Subscriber.import @list_id, subscribers, true
46
+ import_result.FailureDetails.size.should == 0
47
+ import_result.TotalUniqueEmailsSubmitted.should == 3
48
+ import_result.TotalExistingSubscribers.should == 0
49
+ import_result.TotalNewSubscribers.should == 3
50
+ import_result.DuplicateEmailsInSubmission.size.should == 0
51
+ end
52
+
53
+ should "unsubscribe a subscriber" do
54
+ stub_post(@api_key, "subscribers/#{@subscriber.list_id}/unsubscribe.json", nil)
55
+ @subscriber.unsubscribe
56
+ end
57
+
58
+ should "get a subscriber's history" do
59
+ stub_get(@api_key, "subscribers/#{@subscriber.list_id}/history.json?email=#{CGI.escape(@subscriber.email_address)}", "subscriber_history.json")
60
+ history = @subscriber.history
61
+ history.size.should == 1
62
+ history.first.Name.should == "Campaign One"
63
+ history.first.Type.should == "Campaign"
64
+ history.first.ID.should == "fc0ce7105baeaf97f47c99be31d02a91"
65
+ history.first.Actions.size.should == 6
66
+ history.first.Actions.first.Event.should == "Open"
67
+ history.first.Actions.first.Date.should == "2010-10-12 13:18:00"
68
+ history.first.Actions.first.IPAddress.should == "192.168.126.87"
69
+ history.first.Actions.first.Detail.should == ""
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TemplateTest < Test::Unit::TestCase
4
+ context "when an api caller is authenticated" do
5
+ setup do
6
+ @api_key = '123123123123123123123'
7
+ CreateSend.api_key @api_key
8
+ @template = Template.new(:template_id => '98y2e98y289dh89h938389')
9
+ end
10
+
11
+ should "create a template" do
12
+ client_id = '87y8d7qyw8d7yq8w7ydwqwd'
13
+ stub_post(@api_key, "templates/#{client_id}.json", "create_template.json")
14
+ template_id = Template.create client_id, "Template One", "http://templates.org/index.html",
15
+ "http://templates.org/files.zip", "http://templates.org/screenshot.jpg"
16
+ template_id.should == "98y2e98y289dh89h938389"
17
+ end
18
+
19
+ should "get details of a template" do
20
+ stub_get(@api_key, "templates/#{@template.template_id}.json", "template_details.json")
21
+ t = @template.details
22
+ t.TemplateID.should == "98y2e98y289dh89h938389"
23
+ t.Name.should == "Template One"
24
+ t.PreviewURL.should == "http://preview.createsend.com/createsend/templates/previewTemplate.aspx?ID=01AF532CD8889B33&d=r&c=E816F55BFAD1A753"
25
+ t.ScreenshotURL.should == "http://preview.createsend.com/ts/r/14/833/263/14833263.jpg?0318092600"
26
+ end
27
+
28
+ should "update a template" do
29
+ stub_put(@api_key, "templates/#{@template.template_id}.json", nil)
30
+ @template.update "Template One Updated", "http://templates.org/index.html", "http://templates.org/files.zip", "http://templates.org/screenshot.jpg"
31
+ end
32
+
33
+ should "delete a template" do
34
+ stub_delete(@api_key, "templates/#{@template.template_id}.json", nil)
35
+ @template.delete
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,256 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: createsend
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - James Dennes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-27 00:00:00 +11:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 9
28
+ segments:
29
+ - 1
30
+ - 3
31
+ version: "1.3"
32
+ type: :development
33
+ prerelease: false
34
+ name: fakeweb
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 15
43
+ segments:
44
+ - 0
45
+ - 4
46
+ - 0
47
+ version: 0.4.0
48
+ type: :development
49
+ prerelease: false
50
+ name: jnunemaker-matchy
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 25
59
+ segments:
60
+ - 0
61
+ - 9
62
+ version: "0.9"
63
+ type: :development
64
+ prerelease: false
65
+ name: mocha
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 21
74
+ segments:
75
+ - 2
76
+ - 11
77
+ version: "2.11"
78
+ type: :development
79
+ prerelease: false
80
+ name: shoulda
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 15
89
+ segments:
90
+ - 0
91
+ - 4
92
+ - 0
93
+ version: 0.4.0
94
+ type: :runtime
95
+ prerelease: false
96
+ name: hashie
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 5
105
+ segments:
106
+ - 0
107
+ - 6
108
+ - 1
109
+ version: 0.6.1
110
+ type: :runtime
111
+ prerelease: false
112
+ name: httparty
113
+ version_requirements: *id006
114
+ description: A wrapper for the CreateSend API v3
115
+ email:
116
+ - jdennes@gmail.com
117
+ executables: []
118
+
119
+ extensions: []
120
+
121
+ extra_rdoc_files: []
122
+
123
+ files:
124
+ - .gitignore
125
+ - Gemfile
126
+ - README.md
127
+ - Rakefile
128
+ - config.example.yaml
129
+ - createsend.gemspec
130
+ - lib/campaign.rb
131
+ - lib/client.rb
132
+ - lib/createsend.rb
133
+ - lib/list.rb
134
+ - lib/subscriber.rb
135
+ - lib/template.rb
136
+ - test/campaign_test.rb
137
+ - test/client_test.rb
138
+ - test/createsend_test.rb
139
+ - test/fixtures/active_subscribers.json
140
+ - test/fixtures/add_subscriber.json
141
+ - test/fixtures/apikey.json
142
+ - test/fixtures/bounced_subscribers.json
143
+ - test/fixtures/campaign_bounces.json
144
+ - test/fixtures/campaign_clicks.json
145
+ - test/fixtures/campaign_lists.json
146
+ - test/fixtures/campaign_opens.json
147
+ - test/fixtures/campaign_summary.json
148
+ - test/fixtures/campaign_unsubscribes.json
149
+ - test/fixtures/campaigns.json
150
+ - test/fixtures/client_details.json
151
+ - test/fixtures/clients.json
152
+ - test/fixtures/countries.json
153
+ - test/fixtures/create_campaign.json
154
+ - test/fixtures/create_client.json
155
+ - test/fixtures/create_custom_field.json
156
+ - test/fixtures/create_list.json
157
+ - test/fixtures/create_template.json
158
+ - test/fixtures/custom_api_error.json
159
+ - test/fixtures/custom_fields.json
160
+ - test/fixtures/drafts.json
161
+ - test/fixtures/import_subscribers.json
162
+ - test/fixtures/list_details.json
163
+ - test/fixtures/list_stats.json
164
+ - test/fixtures/lists.json
165
+ - test/fixtures/segments.json
166
+ - test/fixtures/subscriber_details.json
167
+ - test/fixtures/subscriber_history.json
168
+ - test/fixtures/suppressionlist.json
169
+ - test/fixtures/systemdate.json
170
+ - test/fixtures/template_details.json
171
+ - test/fixtures/templates.json
172
+ - test/fixtures/timezones.json
173
+ - test/fixtures/unsubscribed_subscribers.json
174
+ - test/helper.rb
175
+ - test/list_test.rb
176
+ - test/subscriber_test.rb
177
+ - test/template_test.rb
178
+ has_rdoc: true
179
+ homepage: http://github.com/campaignmonitor/createsend-ruby/
180
+ licenses: []
181
+
182
+ post_install_message:
183
+ rdoc_options: []
184
+
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ hash: 3
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ hash: 23
202
+ segments:
203
+ - 1
204
+ - 3
205
+ - 6
206
+ version: 1.3.6
207
+ requirements: []
208
+
209
+ rubyforge_project:
210
+ rubygems_version: 1.3.7
211
+ signing_key:
212
+ specification_version: 3
213
+ summary: Wrapper for the CreateSend API v3
214
+ test_files:
215
+ - test/campaign_test.rb
216
+ - test/client_test.rb
217
+ - test/createsend_test.rb
218
+ - test/fixtures/active_subscribers.json
219
+ - test/fixtures/add_subscriber.json
220
+ - test/fixtures/apikey.json
221
+ - test/fixtures/bounced_subscribers.json
222
+ - test/fixtures/campaign_bounces.json
223
+ - test/fixtures/campaign_clicks.json
224
+ - test/fixtures/campaign_lists.json
225
+ - test/fixtures/campaign_opens.json
226
+ - test/fixtures/campaign_summary.json
227
+ - test/fixtures/campaign_unsubscribes.json
228
+ - test/fixtures/campaigns.json
229
+ - test/fixtures/client_details.json
230
+ - test/fixtures/clients.json
231
+ - test/fixtures/countries.json
232
+ - test/fixtures/create_campaign.json
233
+ - test/fixtures/create_client.json
234
+ - test/fixtures/create_custom_field.json
235
+ - test/fixtures/create_list.json
236
+ - test/fixtures/create_template.json
237
+ - test/fixtures/custom_api_error.json
238
+ - test/fixtures/custom_fields.json
239
+ - test/fixtures/drafts.json
240
+ - test/fixtures/import_subscribers.json
241
+ - test/fixtures/list_details.json
242
+ - test/fixtures/list_stats.json
243
+ - test/fixtures/lists.json
244
+ - test/fixtures/segments.json
245
+ - test/fixtures/subscriber_details.json
246
+ - test/fixtures/subscriber_history.json
247
+ - test/fixtures/suppressionlist.json
248
+ - test/fixtures/systemdate.json
249
+ - test/fixtures/template_details.json
250
+ - test/fixtures/templates.json
251
+ - test/fixtures/timezones.json
252
+ - test/fixtures/unsubscribed_subscribers.json
253
+ - test/helper.rb
254
+ - test/list_test.rb
255
+ - test/subscriber_test.rb
256
+ - test/template_test.rb