createsend 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ rdoc
3
3
  pkg
4
4
  *.gem
5
5
  example.rb
6
+ /.buildpath
7
+ /.project
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- createsend (1.0.3)
4
+ createsend (1.1.0)
5
5
  hashie (~> 1.0)
6
6
  httparty (~> 0.8)
7
7
  json
@@ -13,6 +13,8 @@ require 'createsend/list'
13
13
  require 'createsend/segment'
14
14
  require 'createsend/subscriber'
15
15
  require 'createsend/template'
16
+ require 'createsend/person'
17
+ require 'createsend/administrator'
16
18
 
17
19
  module CreateSend
18
20
 
@@ -110,6 +112,23 @@ module CreateSend
110
112
  response = CreateSend.get('/timezones.json')
111
113
  response.parsed_response
112
114
  end
115
+
116
+ # Gets the administrators
117
+ def administrators
118
+ response = CreateSend.get('/admins.json')
119
+ response.map{|item| Hashie::Mash.new(item)}
120
+ end
121
+
122
+ def get_primary_contact
123
+ response = CreateSend.get('/primarycontact.json')
124
+ Hashie::Mash.new(response)
125
+ end
126
+
127
+ def set_primary_contact(email)
128
+ options = { :query => { :email => email } }
129
+ response = CreateSend.put("/primarycontact.json", options)
130
+ Hashie::Mash.new(response)
131
+ end
113
132
 
114
133
  def self.get(*args); handle_response super end
115
134
  def self.post(*args); handle_response super end
@@ -0,0 +1,49 @@
1
+ require 'createsend'
2
+ require 'json'
3
+
4
+ module CreateSend
5
+ # Represents an administrator and associated functionality.
6
+ class Administrator
7
+ attr_reader :email_address
8
+
9
+ def initialize(email_address)
10
+ @email_address = email_address
11
+ end
12
+
13
+ # Gets an adminsitrator by email address.
14
+ def self.get(email_address)
15
+ options = { :query => { :email => email_address } }
16
+ response = CreateSend.get "/admins.json", options
17
+ Hashie::Mash.new(response)
18
+ end
19
+
20
+ # Adds an adminstrator to the account
21
+ def self.add(email_address, name)
22
+ options = { :body => {
23
+ :EmailAddress => email_address,
24
+ :Name => name
25
+ }.to_json }
26
+ response = CreateSend.post "/admins.json", options
27
+ Hashie::Mash.new(response)
28
+ end
29
+
30
+ # Updates the administator details
31
+ def update(new_email_address, name)
32
+ options = {
33
+ :query => { :email => @email_address },
34
+ :body => {
35
+ :EmailAddress => new_email_address,
36
+ :Name => name
37
+ }.to_json }
38
+ CreateSend.put '/admins.json', options
39
+ # Update @email_address, so this object can continue to be used reliably
40
+ @email_address = new_email_address
41
+ end
42
+
43
+ # deletes this administrator from the account
44
+ def delete
45
+ options = { :query => { :email => @email_address } }
46
+ CreateSend.delete '/admins.json', options
47
+ end
48
+ end
49
+ end
@@ -12,6 +12,9 @@ module CreateSend
12
12
 
13
13
  # Creates a client.
14
14
  def self.create(company, contact_name, email, timezone, country)
15
+ warn "[DEPRECATION] Use person.add or person.update to set the name on a particular person in a client. For now, we will create a default person with the name provided." unless contact_name.to_s == ''
16
+ warn "[DEPRECATION] Use person.add or person.update to set the email on a particular person in a client. For now, we will create a default person with the email provided." unless email.to_s == ''
17
+
15
18
  options = { :body => {
16
19
  :CompanyName => company,
17
20
  :ContactName => contact_name,
@@ -56,6 +59,23 @@ module CreateSend
56
59
  response = get 'segments'
57
60
  response.map{|item| Hashie::Mash.new(item)}
58
61
  end
62
+
63
+ # Gets the people associated with this client
64
+ def people
65
+ response = get "people"
66
+ response.map{|item| Hashie::Mash.new(item)}
67
+ end
68
+
69
+ def get_primary_contact
70
+ response = get "primarycontact"
71
+ Hashie::Mash.new(response)
72
+ end
73
+
74
+ def set_primary_contact(email)
75
+ options = { :query => { :email => email } }
76
+ response = put "primarycontact", options
77
+ Hashie::Mash.new(response)
78
+ end
59
79
 
60
80
  # Gets this client's suppression list.
61
81
  def suppressionlist(page=1, page_size=1000, order_field="email", order_direction="asc")
@@ -76,6 +96,9 @@ module CreateSend
76
96
 
77
97
  # Sets the basic details for this client.
78
98
  def set_basics(company, contact_name, email, timezone, country)
99
+ warn "[DEPRECATION] Use person.update to set name on a particular person in a client. This will fail if there are multiple persons in a client." unless contact_name.to_s == ''
100
+ warn "[DEPRECATION] Use person.update to set email on a particular person in a client. This will fail if there are multiple persons in a client." unless email.to_s == ''
101
+
79
102
  options = { :body => {
80
103
  :CompanyName => company,
81
104
  :ContactName => contact_name,
@@ -85,15 +108,6 @@ module CreateSend
85
108
  put 'setbasics', options
86
109
  end
87
110
 
88
- # Sets the access settings for this client.
89
- def set_access(username, password, access_level)
90
- options = { :body => {
91
- :Username => username,
92
- :Password => password,
93
- :AccessLevel => access_level }.to_json }
94
- put 'setaccess', options
95
- end
96
-
97
111
  # Sets the PAYG billing settings for this client.
98
112
  def set_payg_billing(currency, can_purchase_credits, client_pays, markup_percentage,
99
113
  markup_on_delivery=0, markup_per_recipient=0, markup_on_design_spam_test=0)
@@ -116,6 +130,18 @@ module CreateSend
116
130
  :MarkupPercentage => markup_percentage }.to_json }
117
131
  put 'setmonthlybilling', options
118
132
  end
133
+
134
+ # THIS METHOD IS DEPRECATED. It should only be used with existing integrations.
135
+ # Sets the access settings for this client.
136
+ def set_access(username, password, access_level)
137
+ warn "[DEPRECATION] `set_access` is deprecated. Use Person.update to set access on a particular person in a client."
138
+
139
+ options = { :body => {
140
+ :Username => username,
141
+ :Password => password,
142
+ :AccessLevel => access_level }.to_json }
143
+ put 'setaccess', options
144
+ end
119
145
 
120
146
  # Deletes this client.
121
147
  def delete
@@ -0,0 +1,58 @@
1
+ require 'createsend'
2
+ require 'json'
3
+
4
+ module CreateSend
5
+ # Represents a person and associated functionality.
6
+ class Person
7
+ attr_reader :client_id
8
+ attr_reader :email_address
9
+
10
+ def initialize(client_id, email_address)
11
+ @client_id = client_id
12
+ @email_address = email_address
13
+ end
14
+
15
+ # Gets a person by client ID and email address.
16
+ def self.get(client_id, email_address)
17
+ options = { :query => { :email => email_address } }
18
+ response = CreateSend.get "/clients/#{client_id}/people.json", options
19
+ Hashie::Mash.new(response)
20
+ end
21
+
22
+ # Adds a person to the client. password is optional. if ommitted, an
23
+ # email invitation will be sent to the person
24
+ def self.add(client_id, email_address, name, access_level, password)
25
+ options = { :body => {
26
+ :EmailAddress => email_address,
27
+ :Name => name,
28
+ :AccessLevel => access_level,
29
+ :Password => password }.to_json }
30
+ response = CreateSend.post "/clients/#{client_id}/people.json", options
31
+ Hashie::Mash.new(response)
32
+ end
33
+
34
+ # Updates the person details. password is optional and will only be updated if supplied
35
+ def update(new_email_address, name, access_level, password)
36
+ options = {
37
+ :query => { :email => @email_address },
38
+ :body => {
39
+ :EmailAddress => new_email_address,
40
+ :Name => name,
41
+ :AccessLevel => access_level,
42
+ :Password => password }.to_json }
43
+ CreateSend.put uri_for(client_id), options
44
+ # Update @email_address, so this object can continue to be used reliably
45
+ @email_address = new_email_address
46
+ end
47
+
48
+ # deletes this person from the client
49
+ def delete
50
+ options = { :query => { :email => @email_address } }
51
+ CreateSend.delete uri_for(client_id), options
52
+ end
53
+
54
+ def uri_for(client_id)
55
+ "/clients/#{client_id}/people.json"
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module CreateSend
2
- VERSION = "1.0.4" unless defined?(CreateSend::VERSION)
2
+ VERSION = "1.1.0" unless defined?(CreateSend::VERSION)
3
3
  end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class AdministratorTest < 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
+ @admin = CreateSend::Administrator.new "admin@example.com"
9
+ end
10
+
11
+ should "get a administrator by email address" do
12
+ email = "admin@example.com"
13
+ stub_get(@api_key, "admins.json?email=#{CGI.escape(email)}", "admin_details.json")
14
+ admin = CreateSend::Administrator.get email
15
+ admin.EmailAddress.should == email
16
+ admin.Name.should == "Admin One"
17
+ admin.Status.should == "Active"
18
+ end
19
+
20
+ should "add an administrator" do
21
+ stub_post(@api_key, "admins.json", "add_admin.json")
22
+ result = CreateSend::Administrator.add "admin@example.com", "Admin"
23
+ result.EmailAddress.should == "admin@example.com"
24
+ end
25
+
26
+ should "update an administrator" do
27
+ email = "admin@example.com"
28
+ new_email = "new_email_address@example.com"
29
+ stub_put(@api_key, "admins.json?email=#{CGI.escape(email)}", nil)
30
+ @admin.update new_email, "Admin Name"
31
+ @admin.email_address.should == new_email
32
+ end
33
+
34
+ should "delete an admin" do
35
+ stub_delete(@api_key, "admins.json?email=#{CGI.escape(@admin.email_address)}", nil)
36
+ @admin.delete
37
+ end
38
+ end
39
+ end
@@ -94,6 +94,16 @@ class ClientTest < Test::Unit::TestCase
94
94
  res.Results.first.Date.should == "2010-10-26 10:55:31"
95
95
  res.Results.first.State.should == "Suppressed"
96
96
  end
97
+
98
+ should "get all people" do
99
+ stub_get(@api_key, "clients/#{@client.client_id}/people.json", "people.json")
100
+ people = @client.people
101
+ people.size.should == 2
102
+ people.first.EmailAddress.should == "person1@blackhole.com"
103
+ people.first.Name.should == "Person One"
104
+ people.first.Status.should == "Active"
105
+ people.first.AccessLevel.should == 31
106
+ end
97
107
 
98
108
  should "get all templates" do
99
109
  stub_get(@api_key, "clients/#{@client.client_id}/templates.json", "templates.json")
@@ -103,6 +113,19 @@ class ClientTest < Test::Unit::TestCase
103
113
  templates.first.Name.should == 'Template One'
104
114
  end
105
115
 
116
+ should "set primary contact" do
117
+ email = 'person@blackhole.com'
118
+ stub_put(@api_key, "clients/#{@client.client_id}/primarycontact.json?email=#{CGI.escape(email)}", 'client_set_primary_contact.json')
119
+ result = @client.set_primary_contact email
120
+ result.EmailAddress.should == email
121
+ end
122
+
123
+ should "get primary contact" do
124
+ stub_get(@api_key, "clients/#{@client.client_id}/primarycontact.json", 'client_get_primary_contact.json')
125
+ result = @client.get_primary_contact
126
+ result.EmailAddress.should == 'person@blackhole.com'
127
+ end
128
+
106
129
  should "set basics" do
107
130
  stub_put(@api_key, "clients/#{@client.client_id}/setbasics.json", nil)
108
131
  @client.set_basics "Client Company Name", "Client Contact Name", "client@example.com", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
@@ -54,6 +54,29 @@ class CreateSendTest < Test::Unit::TestCase
54
54
  timezones.size.should == 97
55
55
  assert timezones.include? "(GMT+12:00) Fiji"
56
56
  end
57
+
58
+ should "get all administrators" do
59
+ stub_get(@api_key, "admins.json", "administrators.json")
60
+ administrators = @cs.administrators
61
+ administrators.size.should == 2
62
+ administrators.first.EmailAddress.should == "admin1@blackhole.com"
63
+ administrators.first.Name.should == 'Admin One'
64
+ administrators.first.Status.should == 'Active'
65
+ end
66
+
67
+ should "set primary contact" do
68
+ email = 'admin@blackhole.com'
69
+ stub_put(@api_key, "primarycontact.json?email=#{CGI.escape(email)}", 'admin_set_primary_contact.json')
70
+ result = @cs.set_primary_contact email
71
+ result.EmailAddress.should == email
72
+ end
73
+
74
+ should "get primary contact" do
75
+ stub_get(@api_key, "primarycontact.json", 'admin_get_primary_contact.json')
76
+ result = @cs.get_primary_contact
77
+ result.EmailAddress.should == 'admin@blackhole.com'
78
+ end
79
+
57
80
  end
58
81
 
59
82
  context "when the CreateSend API responds with an error" do
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "admin@example.com"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "person@example.com"
3
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "EmailAddress": "admin@example.com",
3
+ "Name": "Admin One",
4
+ "Status": "Active"
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "admin@blackhole.com"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "admin@blackhole.com"
3
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "EmailAddress": "admin1@blackhole.com",
4
+ "Name": "Admin One",
5
+ "Status": "Active"
6
+ },
7
+ {
8
+ "EmailAddress": "admin2@blackhole.com",
9
+ "Name": "Admin Two",
10
+ "Status": "Active"
11
+ }
12
+ ]
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "person@blackhole.com"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "EmailAddress": "person@blackhole.com"
3
+ }
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "EmailAddress": "person1@blackhole.com",
4
+ "Name": "Person One",
5
+ "Status": "Active",
6
+ "AccessLevel": 31
7
+ },
8
+ {
9
+ "EmailAddress": "person2@blackhole.com",
10
+ "Name": "Person Two",
11
+ "Status": "Active",
12
+ "AccessLevel": 0
13
+ }
14
+ ]
@@ -0,0 +1,6 @@
1
+ {
2
+ "EmailAddress": "person@example.com",
3
+ "Name": "Person One",
4
+ "AccessLevel": 1023,
5
+ "Status": "Active"
6
+ }
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class PersonTest < 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
+ @client_id = "d98h2938d9283d982u3d98u88"
9
+ @person = CreateSend::Person.new @client_id, "person@example.com"
10
+ end
11
+
12
+ should "get a person by client id and email address" do
13
+ email = "person@example.com"
14
+ stub_get(@api_key, "clients/#{@client_id}/people.json?email=#{CGI.escape(email)}", "person_details.json")
15
+ person = CreateSend::Person.get @client_id, email
16
+ person.EmailAddress.should == email
17
+ person.Name.should == "Person One"
18
+ person.AccessLevel.should == 1023
19
+ person.Status.should == "Active"
20
+ end
21
+
22
+ should "add a person" do
23
+ stub_post(@api_key, "clients/#{@client_id}/people.json", "add_person.json")
24
+ result = CreateSend::Person.add @client_id, "person@example.com", "Person", 0, "Password"
25
+ result.EmailAddress.should == "person@example.com"
26
+ end
27
+
28
+ should "update a person" do
29
+ email = "person@example.com"
30
+ new_email = "new_email_address@example.com"
31
+ stub_put(@api_key, "clients/#{@client_id}/people.json?email=#{CGI.escape(email)}", nil)
32
+ @person.update new_email, "Person", 1023, "NewPassword"
33
+ @person.email_address.should == new_email
34
+ end
35
+
36
+ should "delete a person" do
37
+ stub_delete(@api_key, "clients/#{@person.client_id}/people.json?email=#{CGI.escape(@person.email_address)}", nil)
38
+ @person.delete
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: createsend
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.4
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Dennes
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-04 00:00:00 Z
13
+ date: 2012-07-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -119,18 +119,27 @@ files:
119
119
  - Rakefile
120
120
  - createsend.gemspec
121
121
  - lib/createsend.rb
122
+ - lib/createsend/administrator.rb
122
123
  - lib/createsend/campaign.rb
123
124
  - lib/createsend/client.rb
124
125
  - lib/createsend/list.rb
126
+ - lib/createsend/person.rb
125
127
  - lib/createsend/segment.rb
126
128
  - lib/createsend/subscriber.rb
127
129
  - lib/createsend/template.rb
128
130
  - lib/createsend/version.rb
131
+ - test/administrator_test.rb
129
132
  - test/campaign_test.rb
130
133
  - test/client_test.rb
131
134
  - test/createsend_test.rb
132
135
  - test/fixtures/active_subscribers.json
136
+ - test/fixtures/add_admin.json
137
+ - test/fixtures/add_person.json
133
138
  - test/fixtures/add_subscriber.json
139
+ - test/fixtures/admin_details.json
140
+ - test/fixtures/admin_get_primary_contact.json
141
+ - test/fixtures/admin_set_primary_contact.json
142
+ - test/fixtures/administrators.json
134
143
  - test/fixtures/apikey.json
135
144
  - test/fixtures/bounced_subscribers.json
136
145
  - test/fixtures/campaign_bounces.json
@@ -142,6 +151,8 @@ files:
142
151
  - test/fixtures/campaign_unsubscribes.json
143
152
  - test/fixtures/campaigns.json
144
153
  - test/fixtures/client_details.json
154
+ - test/fixtures/client_get_primary_contact.json
155
+ - test/fixtures/client_set_primary_contact.json
145
156
  - test/fixtures/clients.json
146
157
  - test/fixtures/countries.json
147
158
  - test/fixtures/create_campaign.json
@@ -161,6 +172,8 @@ files:
161
172
  - test/fixtures/list_stats.json
162
173
  - test/fixtures/list_webhooks.json
163
174
  - test/fixtures/lists.json
175
+ - test/fixtures/people.json
176
+ - test/fixtures/person_details.json
164
177
  - test/fixtures/scheduled_campaigns.json
165
178
  - test/fixtures/segment_details.json
166
179
  - test/fixtures/segment_subscribers.json
@@ -175,6 +188,7 @@ files:
175
188
  - test/fixtures/unsubscribed_subscribers.json
176
189
  - test/helper.rb
177
190
  - test/list_test.rb
191
+ - test/person_test.rb
178
192
  - test/segment_test.rb
179
193
  - test/subscriber_test.rb
180
194
  - test/template_test.rb
@@ -206,11 +220,18 @@ signing_key:
206
220
  specification_version: 3
207
221
  summary: A library which implements the complete functionality of v3 of the createsend API.
208
222
  test_files:
223
+ - test/administrator_test.rb
209
224
  - test/campaign_test.rb
210
225
  - test/client_test.rb
211
226
  - test/createsend_test.rb
212
227
  - test/fixtures/active_subscribers.json
228
+ - test/fixtures/add_admin.json
229
+ - test/fixtures/add_person.json
213
230
  - test/fixtures/add_subscriber.json
231
+ - test/fixtures/admin_details.json
232
+ - test/fixtures/admin_get_primary_contact.json
233
+ - test/fixtures/admin_set_primary_contact.json
234
+ - test/fixtures/administrators.json
214
235
  - test/fixtures/apikey.json
215
236
  - test/fixtures/bounced_subscribers.json
216
237
  - test/fixtures/campaign_bounces.json
@@ -222,6 +243,8 @@ test_files:
222
243
  - test/fixtures/campaign_unsubscribes.json
223
244
  - test/fixtures/campaigns.json
224
245
  - test/fixtures/client_details.json
246
+ - test/fixtures/client_get_primary_contact.json
247
+ - test/fixtures/client_set_primary_contact.json
225
248
  - test/fixtures/clients.json
226
249
  - test/fixtures/countries.json
227
250
  - test/fixtures/create_campaign.json
@@ -241,6 +264,8 @@ test_files:
241
264
  - test/fixtures/list_stats.json
242
265
  - test/fixtures/list_webhooks.json
243
266
  - test/fixtures/lists.json
267
+ - test/fixtures/people.json
268
+ - test/fixtures/person_details.json
244
269
  - test/fixtures/scheduled_campaigns.json
245
270
  - test/fixtures/segment_details.json
246
271
  - test/fixtures/segment_subscribers.json
@@ -255,6 +280,7 @@ test_files:
255
280
  - test/fixtures/unsubscribed_subscribers.json
256
281
  - test/helper.rb
257
282
  - test/list_test.rb
283
+ - test/person_test.rb
258
284
  - test/segment_test.rb
259
285
  - test/subscriber_test.rb
260
286
  - test/template_test.rb