createsend 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,12 @@
1
1
  [
2
2
  {
3
3
  "ListID": "a58ee1d3039b8bec838e6d1482a8a965",
4
- "Name": "Segment One"
4
+ "SegmentID": "46aa5e01fd43381863d4e42cf277d3a9",
5
+ "Title": "Segment One"
5
6
  },
6
7
  {
7
8
  "ListID": "8dffb94c60c5faa3d40f496f2aa58a8a",
8
- "Name": "Segment Two"
9
+ "SegmentID": "dhw9q8jd9q8wd09quw0d909wid9i09iq",
10
+ "Title": "Segment Two"
9
11
  }
10
12
  ]
@@ -1,12 +1,36 @@
1
- [
2
- {
3
- "EmailAddress": "subs+098u0qu0qwd@example.com",
4
- "Date": "2009-11-25 13:23:20",
5
- "State": "Suppressed"
6
- },
7
- {
8
- "EmailAddress": "subs+3018006@example.com",
9
- "Date": "2009-11-10 11:50:04",
10
- "State": "Suppressed"
11
- }
12
- ]
1
+ {
2
+ "Results": [
3
+ {
4
+ "EmailAddress": "example+1@example.com",
5
+ "Date": "2010-10-26 10:55:31",
6
+ "State": "Suppressed"
7
+ },
8
+ {
9
+ "EmailAddress": "example+2@example.com",
10
+ "Date": "2010-10-26 10:55:31",
11
+ "State": "Suppressed"
12
+ },
13
+ {
14
+ "EmailAddress": "example+3@example.com",
15
+ "Date": "2010-10-26 10:55:31",
16
+ "State": "Suppressed"
17
+ },
18
+ {
19
+ "EmailAddress": "subscriber@example.com",
20
+ "Date": "2010-10-25 13:11:04",
21
+ "State": "Suppressed"
22
+ },
23
+ {
24
+ "EmailAddress": "subscriberone@example.com",
25
+ "Date": "2010-10-25 13:04:15",
26
+ "State": "Suppressed"
27
+ }
28
+ ],
29
+ "ResultsOrderedBy": "email",
30
+ "OrderDirection": "asc",
31
+ "PageNumber": 1,
32
+ "PageSize": 1000,
33
+ "RecordsOnThisPage": 5,
34
+ "TotalNumberOfRecords": 5,
35
+ "NumberOfPages": 1
36
+ }
@@ -1,21 +1,51 @@
1
- [
2
- {
3
- "EmailAddress": "subscriber@example.com",
4
- "Name": "Unsub One",
5
- "Date": "2010-10-25 13:11:00",
6
- "State": "Unsubscribed",
7
- "CustomFields": []
8
- },
9
- {
10
- "EmailAddress": "subscriberone@example.com",
11
- "Name": "Unsub Two",
12
- "Date": "2010-10-25 13:04:00",
13
- "State": "Unsubscribed",
14
- "CustomFields": [
15
- {
16
- "Key": "website",
17
- "Value": "http://google.com"
18
- }
19
- ]
20
- }
21
- ]
1
+ {
2
+ "Results": [
3
+ {
4
+ "EmailAddress": "subscriber@example.com",
5
+ "Name": "Unsub One",
6
+ "Date": "2010-10-25 13:11:00",
7
+ "State": "Unsubscribed",
8
+ "CustomFields": []
9
+ },
10
+ {
11
+ "EmailAddress": "subscriberone@example.com",
12
+ "Name": "Subscriber",
13
+ "Date": "2010-10-25 13:04:00",
14
+ "State": "Unsubscribed",
15
+ "CustomFields": [
16
+ {
17
+ "Key": "website",
18
+ "Value": "http://google.com"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "EmailAddress": "example+1@example.com",
24
+ "Name": "Example One",
25
+ "Date": "2010-10-26 10:56:00",
26
+ "State": "Unsubscribed",
27
+ "CustomFields": []
28
+ },
29
+ {
30
+ "EmailAddress": "example+2@example.com",
31
+ "Name": "Example Two",
32
+ "Date": "2010-10-26 10:56:00",
33
+ "State": "Unsubscribed",
34
+ "CustomFields": []
35
+ },
36
+ {
37
+ "EmailAddress": "example+3@example.com",
38
+ "Name": "Example Three",
39
+ "Date": "2010-10-26 10:56:00",
40
+ "State": "Unsubscribed",
41
+ "CustomFields": []
42
+ }
43
+ ],
44
+ "ResultsOrderedBy": "email",
45
+ "OrderDirection": "asc",
46
+ "PageNumber": 1,
47
+ "PageSize": 1000,
48
+ "RecordsOnThisPage": 5,
49
+ "TotalNumberOfRecords": 5,
50
+ "NumberOfPages": 1
51
+ }
@@ -37,6 +37,13 @@ class ListTest < Test::Unit::TestCase
37
37
  stub_delete(@api_key, "lists/#{@list.list_id}/customfields/#{CGI.escape(custom_field_key)}.json", nil)
38
38
  @list.delete_custom_field custom_field_key
39
39
  end
40
+
41
+ should "update the options of a multi-optioned custom field" do
42
+ custom_field_key = "[newdatefield]"
43
+ new_options = [ "one", "two", "three" ]
44
+ stub_put(@api_key, "lists/#{@list.list_id}/customfields/#{CGI.escape(custom_field_key)}/options.json", nil)
45
+ @list.update_custom_field_options custom_field_key, new_options, true
46
+ end
40
47
 
41
48
  should "get the details of a list" do
42
49
  stub_get(@api_key, "lists/#{@list.list_id}.json", "list_details.json")
@@ -57,6 +64,15 @@ class ListTest < Test::Unit::TestCase
57
64
  cfs.first.DataType.should == "Text"
58
65
  cfs.first.FieldOptions.should == []
59
66
  end
67
+
68
+ should "get the segments for a list" do
69
+ stub_get(@api_key, "lists/#{@list.list_id}/segments.json", "segments.json")
70
+ segments = @list.segments
71
+ segments.size.should == 2
72
+ segments.first.ListID.should == 'a58ee1d3039b8bec838e6d1482a8a965'
73
+ segments.first.SegmentID.should == '46aa5e01fd43381863d4e42cf277d3a9'
74
+ segments.first.Title.should == 'Segment One'
75
+ end
60
76
 
61
77
  should "get the stats for a list" do
62
78
  stub_get(@api_key, "lists/#{@list.list_id}/stats.json", "list_stats.json")
@@ -69,38 +85,62 @@ class ListTest < Test::Unit::TestCase
69
85
 
70
86
  should "get the active subscribers for a list" do
71
87
  min_date = "2010-01-01"
72
- stub_get(@api_key, "lists/#{@list.list_id}/active.json?date=#{CGI.escape(min_date)}", "active_subscribers.json")
73
- active = @list.active min_date
74
- active.size.should == 6
75
- active.first.EmailAddress.should == "subs+7t8787Y@example.com"
76
- active.first.Name.should == "Subscriber One"
77
- active.first.Date.should == "2010-10-25 10:28:00"
78
- active.first.State.should == "Active"
79
- active.first.CustomFields.size.should == 3
88
+ stub_get(@api_key, "lists/#{@list.list_id}/active.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
89
+ "active_subscribers.json")
90
+ res = @list.active min_date
91
+ res.ResultsOrderedBy.should == "email"
92
+ res.OrderDirection.should == "asc"
93
+ res.PageNumber.should == 1
94
+ res.PageSize.should == 1000
95
+ res.RecordsOnThisPage.should == 5
96
+ res.TotalNumberOfRecords.should == 5
97
+ res.NumberOfPages.should == 1
98
+ res.Results.size.should == 5
99
+ res.Results.first.EmailAddress.should == "subs+7t8787Y@example.com"
100
+ res.Results.first.Name.should =="Person One"
101
+ res.Results.first.Date.should == "2010-10-25 10:28:00"
102
+ res.Results.first.State.should == "Active"
103
+ res.Results.first.CustomFields.size.should == 3
80
104
  end
81
105
 
82
106
  should "get the unsubscribed subscribers for a list" do
83
107
  min_date = "2010-01-01"
84
- stub_get(@api_key, "lists/#{@list.list_id}/unsubscribed.json?date=#{CGI.escape(min_date)}", "unsubscribed_subscribers.json")
85
- unsub = @list.unsubscribed min_date
86
- unsub.size.should == 2
87
- unsub.first.EmailAddress.should == "subscriber@example.com"
88
- unsub.first.Name.should == "Unsub One"
89
- unsub.first.Date.should == "2010-10-25 13:11:00"
90
- unsub.first.State.should == "Unsubscribed"
91
- unsub.first.CustomFields.size.should == 0
108
+ stub_get(@api_key, "lists/#{@list.list_id}/unsubscribed.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
109
+ "unsubscribed_subscribers.json")
110
+ res = @list.unsubscribed min_date
111
+ res.ResultsOrderedBy.should == "email"
112
+ res.OrderDirection.should == "asc"
113
+ res.PageNumber.should == 1
114
+ res.PageSize.should == 1000
115
+ res.RecordsOnThisPage.should == 5
116
+ res.TotalNumberOfRecords.should == 5
117
+ res.NumberOfPages.should == 1
118
+ res.Results.size.should == 5
119
+ res.Results.first.EmailAddress.should == "subscriber@example.com"
120
+ res.Results.first.Name.should == "Unsub One"
121
+ res.Results.first.Date.should == "2010-10-25 13:11:00"
122
+ res.Results.first.State.should == "Unsubscribed"
123
+ res.Results.first.CustomFields.size.should == 0
92
124
  end
93
125
 
94
126
  should "get the bounced subscribers for a list" do
95
127
  min_date = "2010-01-01"
96
- stub_get(@api_key, "lists/#{@list.list_id}/bounced.json?date=#{CGI.escape(min_date)}", "bounced_subscribers.json")
97
- bounced = @list.bounced min_date
98
- bounced.size.should == 1
99
- bounced.first.EmailAddress.should == "bouncedsubscriber@example.com"
100
- bounced.first.Name.should == "Bounced One"
101
- bounced.first.Date.should == "2010-10-25 13:11:00"
102
- bounced.first.State.should == "Bounced"
103
- bounced.first.CustomFields.size.should == 0
128
+ stub_get(@api_key, "lists/#{@list.list_id}/bounced.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
129
+ "bounced_subscribers.json")
130
+ res = @list.bounced min_date
131
+ res.ResultsOrderedBy.should == "email"
132
+ res.OrderDirection.should == "asc"
133
+ res.PageNumber.should == 1
134
+ res.PageSize.should == 1000
135
+ res.RecordsOnThisPage.should == 1
136
+ res.TotalNumberOfRecords.should == 1
137
+ res.NumberOfPages.should == 1
138
+ res.Results.size.should == 1
139
+ res.Results.first.EmailAddress.should == "bouncedsubscriber@example.com"
140
+ res.Results.first.Name.should == "Bounced One"
141
+ res.Results.first.Date.should == "2010-10-25 13:11:00"
142
+ res.Results.first.State.should == "Bounced"
143
+ res.Results.first.CustomFields.size.should == 0
104
144
  end
105
145
 
106
146
  end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class SegmentTest < 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
+ @segment = Segment.new(:segment_id => '98y2e98y289dh89h938389')
9
+ end
10
+
11
+ should "create a new segment" do
12
+ list_id = "2983492834987394879837498"
13
+ rules = [ { :Subject => "EmailAddress", :Clauses => [ "CONTAINS example.com" ] } ]
14
+ stub_post(@api_key, "segments/#{list_id}.json", "create_segment.json")
15
+ res = Segment.create list_id, "new segment title", rules
16
+ res.should == "0246c2aea610a3545d9780bf6ab89006"
17
+ end
18
+
19
+ should "update a segment" do
20
+ rules = [ { :Subject => "Name", :Clauses => [ "EQUALS subscriber" ] } ]
21
+ stub_put(@api_key, "segments/#{@segment.segment_id}.json", nil)
22
+ @segment.update "new title for segment", rules
23
+ end
24
+
25
+ should "add a rule to a segment" do
26
+ clauses = [ "CONTAINS example.com" ]
27
+ stub_post(@api_key, "segments/#{@segment.segment_id}/rules.json", nil)
28
+ @segment.add_rule "EmailAddress", clauses
29
+ end
30
+
31
+ should "get the active subscribers for a particular segment in the list" do
32
+ min_date = "2010-01-01"
33
+ stub_get(@api_key, "segments/#{@segment.segment_id}/active.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}",
34
+ "segment_subscribers.json")
35
+ res = @segment.subscribers min_date
36
+ res.ResultsOrderedBy.should == "email"
37
+ res.OrderDirection.should == "asc"
38
+ res.PageNumber.should == 1
39
+ res.PageSize.should == 1000
40
+ res.RecordsOnThisPage.should == 2
41
+ res.TotalNumberOfRecords.should == 2
42
+ res.NumberOfPages.should == 1
43
+ res.Results.size.should == 2
44
+ res.Results.first.EmailAddress.should == "personone@example.com"
45
+ res.Results.first.Name.should == "Person One"
46
+ res.Results.first.Date.should == "2010-10-27 13:13:00"
47
+ res.Results.first.State.should == "Active"
48
+ res.Results.first.CustomFields.should == []
49
+ end
50
+
51
+ should "delete a segment" do
52
+ stub_delete(@api_key, "segments/#{@segment.segment_id}.json", nil)
53
+ @segment.delete
54
+ end
55
+
56
+ should "get the details of a segment" do
57
+ stub_get(@api_key, "segments/#{@segment.segment_id}.json", "segment_details.json")
58
+ res = @segment.details
59
+ res.ActiveSubscribers.should == 0
60
+ res.Rules.size.should == 2
61
+ res.Rules.first.Subject.should == "EmailAddress"
62
+ res.Rules.first.Clauses.size.should == 1
63
+ res.Rules.first.Clauses.first.should == "CONTAINS @hello.com"
64
+ res.ListID.should == "2bea949d0bf96148c3e6a209d2e82060"
65
+ res.SegmentID.should == "dba84a225d5ce3d19105d7257baac46f"
66
+ res.Title.should == "My Segment"
67
+ end
68
+
69
+ should "clear a segment's rules" do
70
+ stub_delete(@api_key, "segments/#{@segment.segment_id}/rules.json", nil)
71
+ @segment.clear_rules
72
+ end
73
+
74
+ end
75
+ end
@@ -50,6 +50,25 @@ class SubscriberTest < Test::Unit::TestCase
50
50
  import_result.DuplicateEmailsInSubmission.size.should == 0
51
51
  end
52
52
 
53
+ should "import many subscribers at once with partial success" do
54
+ # Stub request with 400 Bad Request as the expected response status
55
+ stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers_partial_success.json", 400)
56
+ subscribers = [
57
+ { :EmailAddress => "example+1@example", :Name => "Example One" },
58
+ { :EmailAddress => "example+2@example.com", :Name => "Example Two" },
59
+ { :EmailAddress => "example+3@example.com", :Name => "Example Three" },
60
+ ]
61
+ import_result = Subscriber.import @list_id, subscribers, true
62
+ import_result.FailureDetails.size.should == 1
63
+ import_result.FailureDetails.first.EmailAddress.should == "example+1@example"
64
+ import_result.FailureDetails.first.Code.should == 1
65
+ import_result.FailureDetails.first.Message.should == "Invalid Email Address"
66
+ import_result.TotalUniqueEmailsSubmitted.should == 3
67
+ import_result.TotalExistingSubscribers.should == 2
68
+ import_result.TotalNewSubscribers.should == 0
69
+ import_result.DuplicateEmailsInSubmission.size.should == 0
70
+ end
71
+
53
72
  should "unsubscribe a subscriber" do
54
73
  stub_post(@api_key, "subscribers/#{@subscriber.list_id}/unsubscribe.json", nil)
55
74
  @subscriber.unsubscribe
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: createsend
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Dennes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-27 00:00:00 +11:00
18
+ date: 2010-11-17 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -111,7 +111,7 @@ dependencies:
111
111
  prerelease: false
112
112
  name: httparty
113
113
  version_requirements: *id006
114
- description: A wrapper for the CreateSend API v3
114
+ description: A library which implements the complete functionality of v3 of the createsend API.
115
115
  email:
116
116
  - jdennes@gmail.com
117
117
  executables: []
@@ -123,6 +123,7 @@ extra_rdoc_files: []
123
123
  files:
124
124
  - .gitignore
125
125
  - Gemfile
126
+ - LICENSE
126
127
  - README.md
127
128
  - Rakefile
128
129
  - config.example.yaml
@@ -131,6 +132,7 @@ files:
131
132
  - lib/client.rb
132
133
  - lib/createsend.rb
133
134
  - lib/list.rb
135
+ - lib/segment.rb
134
136
  - lib/subscriber.rb
135
137
  - lib/template.rb
136
138
  - test/campaign_test.rb
@@ -142,8 +144,9 @@ files:
142
144
  - test/fixtures/bounced_subscribers.json
143
145
  - test/fixtures/campaign_bounces.json
144
146
  - test/fixtures/campaign_clicks.json
145
- - test/fixtures/campaign_lists.json
147
+ - test/fixtures/campaign_listsandsegments.json
146
148
  - test/fixtures/campaign_opens.json
149
+ - test/fixtures/campaign_recipients.json
147
150
  - test/fixtures/campaign_summary.json
148
151
  - test/fixtures/campaign_unsubscribes.json
149
152
  - test/fixtures/campaigns.json
@@ -154,14 +157,18 @@ files:
154
157
  - test/fixtures/create_client.json
155
158
  - test/fixtures/create_custom_field.json
156
159
  - test/fixtures/create_list.json
160
+ - test/fixtures/create_segment.json
157
161
  - test/fixtures/create_template.json
158
162
  - test/fixtures/custom_api_error.json
159
163
  - test/fixtures/custom_fields.json
160
164
  - test/fixtures/drafts.json
161
165
  - test/fixtures/import_subscribers.json
166
+ - test/fixtures/import_subscribers_partial_success.json
162
167
  - test/fixtures/list_details.json
163
168
  - test/fixtures/list_stats.json
164
169
  - test/fixtures/lists.json
170
+ - test/fixtures/segment_details.json
171
+ - test/fixtures/segment_subscribers.json
165
172
  - test/fixtures/segments.json
166
173
  - test/fixtures/subscriber_details.json
167
174
  - test/fixtures/subscriber_history.json
@@ -173,6 +180,7 @@ files:
173
180
  - test/fixtures/unsubscribed_subscribers.json
174
181
  - test/helper.rb
175
182
  - test/list_test.rb
183
+ - test/segment_test.rb
176
184
  - test/subscriber_test.rb
177
185
  - test/template_test.rb
178
186
  has_rdoc: true
@@ -210,7 +218,7 @@ rubyforge_project:
210
218
  rubygems_version: 1.3.7
211
219
  signing_key:
212
220
  specification_version: 3
213
- summary: Wrapper for the CreateSend API v3
221
+ summary: A library which implements the complete functionality of v3 of the createsend API.
214
222
  test_files:
215
223
  - test/campaign_test.rb
216
224
  - test/client_test.rb
@@ -221,8 +229,9 @@ test_files:
221
229
  - test/fixtures/bounced_subscribers.json
222
230
  - test/fixtures/campaign_bounces.json
223
231
  - test/fixtures/campaign_clicks.json
224
- - test/fixtures/campaign_lists.json
232
+ - test/fixtures/campaign_listsandsegments.json
225
233
  - test/fixtures/campaign_opens.json
234
+ - test/fixtures/campaign_recipients.json
226
235
  - test/fixtures/campaign_summary.json
227
236
  - test/fixtures/campaign_unsubscribes.json
228
237
  - test/fixtures/campaigns.json
@@ -233,14 +242,18 @@ test_files:
233
242
  - test/fixtures/create_client.json
234
243
  - test/fixtures/create_custom_field.json
235
244
  - test/fixtures/create_list.json
245
+ - test/fixtures/create_segment.json
236
246
  - test/fixtures/create_template.json
237
247
  - test/fixtures/custom_api_error.json
238
248
  - test/fixtures/custom_fields.json
239
249
  - test/fixtures/drafts.json
240
250
  - test/fixtures/import_subscribers.json
251
+ - test/fixtures/import_subscribers_partial_success.json
241
252
  - test/fixtures/list_details.json
242
253
  - test/fixtures/list_stats.json
243
254
  - test/fixtures/lists.json
255
+ - test/fixtures/segment_details.json
256
+ - test/fixtures/segment_subscribers.json
244
257
  - test/fixtures/segments.json
245
258
  - test/fixtures/subscriber_details.json
246
259
  - test/fixtures/subscriber_history.json
@@ -252,5 +265,6 @@ test_files:
252
265
  - test/fixtures/unsubscribed_subscribers.json
253
266
  - test/helper.rb
254
267
  - test/list_test.rb
268
+ - test/segment_test.rb
255
269
  - test/subscriber_test.rb
256
270
  - test/template_test.rb