createsend 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -9,11 +9,15 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
+ activesupport (3.2.8)
13
+ i18n (~> 0.6)
14
+ multi_json (~> 1.0)
12
15
  fakeweb (1.3.0)
13
16
  hashie (1.2.0)
14
17
  httparty (0.8.1)
15
18
  multi_json
16
19
  multi_xml
20
+ i18n (0.6.0)
17
21
  jnunemaker-matchy (0.4.0)
18
22
  json (1.6.1)
19
23
  metaclass (0.0.1)
@@ -22,11 +26,12 @@ GEM
22
26
  multi_json (1.0.3)
23
27
  multi_xml (0.4.1)
24
28
  rake (0.9.2.2)
25
- shoulda (3.0.1)
26
- shoulda-context (~> 1.0.0)
27
- shoulda-matchers (~> 1.0.0)
29
+ shoulda (3.1.1)
30
+ shoulda-context (~> 1.0)
31
+ shoulda-matchers (~> 1.2)
28
32
  shoulda-context (1.0.0)
29
- shoulda-matchers (1.0.0)
33
+ shoulda-matchers (1.2.0)
34
+ activesupport (>= 3.0.0)
30
35
 
31
36
  PLATFORMS
32
37
  ruby
@@ -37,4 +42,4 @@ DEPENDENCIES
37
42
  jnunemaker-matchy (~> 0.4)
38
43
  mocha (~> 0.9)
39
44
  rake
40
- shoulda (~> 3.0.1)
45
+ shoulda (~> 3.1.1)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 James Dennes
1
+ Copyright (c) 2010-2012 James Dennes
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
16
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
19
+ THE SOFTWARE.
data/createsend.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.add_development_dependency('fakeweb', '~> 1.3')
9
9
  s.add_development_dependency('jnunemaker-matchy', '~> 0.4')
10
10
  s.add_development_dependency('mocha', '~> 0.9')
11
- s.add_development_dependency('shoulda', '~> 3.0.1')
11
+ s.add_development_dependency('shoulda', '~> 3.1.1')
12
12
  s.add_runtime_dependency('json')
13
13
  s.add_runtime_dependency('hashie', '~> 1.0')
14
14
  s.add_runtime_dependency('httparty', '~> 0.8')
data/lib/createsend.rb CHANGED
@@ -18,39 +18,46 @@ require 'createsend/administrator'
18
18
 
19
19
  module CreateSend
20
20
 
21
- # Just allows callers to do CreateSend.api_key "..." rather than CreateSend::CreateSend.api_key "..." etc
21
+ # Just allows callers to do CreateSend.api_key "..." rather than
22
+ # CreateSend::CreateSend.api_key "..." etc
22
23
  class << self
23
24
  def api_key(api_key=nil)
24
25
  r = CreateSend.api_key api_key
25
26
  end
26
-
27
+
27
28
  def base_uri(uri)
28
29
  r = CreateSend.base_uri uri
29
30
  end
30
31
  end
31
32
 
32
- # Represents a CreateSend API error and contains specific data about the error.
33
+ # Represents a CreateSend API error. Contains specific data about the error.
33
34
  class CreateSendError < StandardError
34
35
  attr_reader :data
35
36
  def initialize(data)
36
37
  @data = data
37
38
  # @data should contain Code, Message and optionally ResultData
38
39
  extra = @data.ResultData ? "\nExtra result data: #{@data.ResultData}" : ""
39
- super "The CreateSend API responded with the following error - #{@data.Code}: #{@data.Message}#{extra}"
40
+ super "The CreateSend API responded with the following error"\
41
+ " - #{@data.Code}: #{@data.Message}#{extra}"
40
42
  end
41
43
  end
42
44
 
45
+ # Raised for HTTP response codes of 400...500
43
46
  class ClientError < StandardError; end
47
+ # Raised for HTTP response codes of 500...600
44
48
  class ServerError < StandardError; end
49
+ # Raised for HTTP response code of 400
45
50
  class BadRequest < CreateSendError; end
51
+ # Raised for HTTP response code of 401
46
52
  class Unauthorized < CreateSendError; end
53
+ # Raised for HTTP response code of 404
47
54
  class NotFound < ClientError; end
48
- class Unavailable < StandardError; end
49
55
 
50
56
  # Provides high level CreateSend functionality/data you'll probably need.
51
57
  class CreateSend
52
58
  include HTTParty
53
-
59
+
60
+ # Deals with an unfortunate situation where responses aren't valid json.
54
61
  class Parser::DealWithCreateSendInvalidJson < HTTParty::Parser
55
62
  # The createsend API returns an ID as a string when a 201 Created
56
63
  # response is returned. Unfortunately this is invalid json.
@@ -65,8 +72,8 @@ module CreateSend
65
72
  parser Parser::DealWithCreateSendInvalidJson
66
73
  @@base_uri = "https://api.createsend.com/api/v3"
67
74
  @@api_key = ""
68
- headers({
69
- 'User-Agent' => "createsend-ruby-#{VERSION}",
75
+ headers({
76
+ 'User-Agent' => "createsend-ruby-#{VERSION}",
70
77
  'Content-Type' => 'application/json; charset=utf-8',
71
78
  'Accept-Encoding' => 'gzip, deflate' })
72
79
  base_uri @@base_uri
@@ -80,7 +87,7 @@ module CreateSend
80
87
  end
81
88
 
82
89
  # Gets your CreateSend API key, given your site url, username and password.
83
- def apikey(site_url, username, password)
90
+ def apikey(site_url, username, password)
84
91
  site_url = CGI.escape(site_url)
85
92
  self.class.basic_auth username, password
86
93
  response = CreateSend.get("/apikey.json?SiteUrl=#{site_url}")
@@ -112,18 +119,18 @@ module CreateSend
112
119
  response = CreateSend.get('/timezones.json')
113
120
  response.parsed_response
114
121
  end
115
-
122
+
116
123
  # Gets the administrators
117
124
  def administrators
118
125
  response = CreateSend.get('/admins.json')
119
126
  response.map{|item| Hashie::Mash.new(item)}
120
127
  end
121
-
128
+
122
129
  def get_primary_contact
123
130
  response = CreateSend.get('/primarycontact.json')
124
131
  Hashie::Mash.new(response)
125
132
  end
126
-
133
+
127
134
  def set_primary_contact(email)
128
135
  options = { :query => { :email => email } }
129
136
  response = CreateSend.put("/primarycontact.json", options)
@@ -26,7 +26,7 @@ module CreateSend
26
26
  response = CreateSend.post "/admins.json", options
27
27
  Hashie::Mash.new(response)
28
28
  end
29
-
29
+
30
30
  # Updates the administator details
31
31
  def update(new_email_address, name)
32
32
  options = {
@@ -44,6 +44,6 @@ module CreateSend
44
44
  def delete
45
45
  options = { :query => { :email => @email_address } }
46
46
  CreateSend.delete '/admins.json', options
47
- end
47
+ end
48
48
  end
49
49
  end
@@ -11,9 +11,9 @@ module CreateSend
11
11
  end
12
12
 
13
13
  # Creates a new campaign for a client.
14
- def self.create(client_id, subject, name, from_name, from_email, reply_to, html_url,
15
- text_url, list_ids, segment_ids)
16
- options = { :body => {
14
+ def self.create(client_id, subject, name, from_name, from_email,
15
+ reply_to, html_url, text_url, list_ids, segment_ids)
16
+ options = { :body => {
17
17
  :Subject => subject,
18
18
  :Name => name,
19
19
  :FromName => from_name,
@@ -30,7 +30,8 @@ module CreateSend
30
30
  # Sends a preview of this campaign.
31
31
  def send_preview(recipients, personalize="fallback")
32
32
  options = { :body => {
33
- :PreviewRecipients => recipients.kind_of?(String) ? [ recipients ] : recipients,
33
+ :PreviewRecipients => recipients.kind_of?(String) ?
34
+ [ recipients ] : recipients,
34
35
  :Personalize => personalize }.to_json }
35
36
  response = post "sendpreview", options
36
37
  end
@@ -60,15 +61,17 @@ module CreateSend
60
61
  Hashie::Mash.new(response)
61
62
  end
62
63
 
63
- # Retrieves the lists and segments to which this campaaign will be (or was) sent.
64
+ # Retrieves the lists and segments to which this campaaign will
65
+ # be (or was) sent.
64
66
  def lists_and_segments
65
67
  response = get "listsandsegments", {}
66
68
  Hashie::Mash.new(response)
67
69
  end
68
70
 
69
71
  # Retrieves the recipients of this campaign.
70
- def recipients(page=1, page_size=1000, order_field="email", order_direction="asc")
71
- options = { :query => {
72
+ def recipients(page=1, page_size=1000, order_field="email",
73
+ order_direction="asc")
74
+ options = { :query => {
72
75
  :page => page,
73
76
  :pagesize => page_size,
74
77
  :orderfield => order_field,
@@ -78,8 +81,9 @@ module CreateSend
78
81
  end
79
82
 
80
83
  # Retrieves the opens for this campaign.
81
- def opens(date, page=1, page_size=1000, order_field="date", order_direction="asc")
82
- options = { :query => {
84
+ def opens(date, page=1, page_size=1000, order_field="date",
85
+ order_direction="asc")
86
+ options = { :query => {
83
87
  :date => date,
84
88
  :page => page,
85
89
  :pagesize => page_size,
@@ -90,8 +94,9 @@ module CreateSend
90
94
  end
91
95
 
92
96
  # Retrieves the subscriber clicks for this campaign.
93
- def clicks(date, page=1, page_size=1000, order_field="date", order_direction="asc")
94
- options = { :query => {
97
+ def clicks(date, page=1, page_size=1000, order_field="date",
98
+ order_direction="asc")
99
+ options = { :query => {
95
100
  :date => date,
96
101
  :page => page,
97
102
  :pagesize => page_size,
@@ -102,8 +107,9 @@ module CreateSend
102
107
  end
103
108
 
104
109
  # Retrieves the unsubscribes for this campaign.
105
- def unsubscribes(date, page=1, page_size=1000, order_field="date", order_direction="asc")
106
- options = { :query => {
110
+ def unsubscribes(date, page=1, page_size=1000, order_field="date",
111
+ order_direction="asc")
112
+ options = { :query => {
107
113
  :date => date,
108
114
  :page => page,
109
115
  :pagesize => page_size,
@@ -114,8 +120,9 @@ module CreateSend
114
120
  end
115
121
 
116
122
  # Retrieves the bounces for this campaign.
117
- def bounces(date="1900-01-01", page=1, page_size=1000, order_field="date", order_direction="asc")
118
- options = { :query => {
123
+ def bounces(date="1900-01-01", page=1, page_size=1000, order_field="date",
124
+ order_direction="asc")
125
+ options = { :query => {
119
126
  :date => date,
120
127
  :page => page,
121
128
  :pagesize => page_size,
@@ -11,14 +11,9 @@ module CreateSend
11
11
  end
12
12
 
13
13
  # Creates a client.
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
-
18
- options = { :body => {
19
- :CompanyName => company,
20
- :ContactName => contact_name,
21
- :EmailAddress => email,
14
+ def self.create(company, timezone, country)
15
+ options = { :body => {
16
+ :CompanyName => company,
22
17
  :TimeZone => timezone,
23
18
  :Country => country }.to_json }
24
19
  CreateSend.post "/clients.json", options
@@ -35,7 +30,7 @@ module CreateSend
35
30
  response = get 'campaigns'
36
31
  response.map{|item| Hashie::Mash.new(item)}
37
32
  end
38
-
33
+
39
34
  # Gets the currently scheduled campaigns belonging to this client.
40
35
  def scheduled
41
36
  response = get 'scheduled'
@@ -54,23 +49,32 @@ module CreateSend
54
49
  response.map{|item| Hashie::Mash.new(item)}
55
50
  end
56
51
 
52
+ # Gets the lists across a client, to which a subscriber with a particular
53
+ # email address belongs.
54
+ # email_address - A String representing the subcriber's email address
55
+ def lists_for_email(email_address)
56
+ options = { :query => { :email => email_address } }
57
+ response = get 'listsforemail', options
58
+ response.map{|item| Hashie::Mash.new(item)}
59
+ end
60
+
57
61
  # Gets the segments belonging to this client.
58
62
  def segments
59
63
  response = get 'segments'
60
64
  response.map{|item| Hashie::Mash.new(item)}
61
65
  end
62
-
66
+
63
67
  # Gets the people associated with this client
64
68
  def people
65
69
  response = get "people"
66
70
  response.map{|item| Hashie::Mash.new(item)}
67
71
  end
68
-
72
+
69
73
  def get_primary_contact
70
74
  response = get "primarycontact"
71
75
  Hashie::Mash.new(response)
72
76
  end
73
-
77
+
74
78
  def set_primary_contact(email)
75
79
  options = { :query => { :email => email } }
76
80
  response = put "primarycontact", options
@@ -78,8 +82,9 @@ module CreateSend
78
82
  end
79
83
 
80
84
  # Gets this client's suppression list.
81
- def suppressionlist(page=1, page_size=1000, order_field="email", order_direction="asc")
82
- options = { :query => {
85
+ def suppressionlist(page=1, page_size=1000, order_field="email",
86
+ order_direction="asc")
87
+ options = { :query => {
83
88
  :page => page,
84
89
  :pagesize => page_size,
85
90
  :orderfield => order_field,
@@ -95,23 +100,19 @@ module CreateSend
95
100
  end
96
101
 
97
102
  # Sets the basic details for this client.
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
-
102
- options = { :body => {
103
- :CompanyName => company,
104
- :ContactName => contact_name,
105
- :EmailAddress => email,
103
+ def set_basics(company, timezone, country)
104
+ options = { :body => {
105
+ :CompanyName => company,
106
106
  :TimeZone => timezone,
107
107
  :Country => country }.to_json }
108
108
  put 'setbasics', options
109
109
  end
110
110
 
111
111
  # Sets the PAYG billing settings for this client.
112
- def set_payg_billing(currency, can_purchase_credits, client_pays, markup_percentage,
113
- markup_on_delivery=0, markup_per_recipient=0, markup_on_design_spam_test=0)
114
- options = { :body => {
112
+ def set_payg_billing(currency, can_purchase_credits, client_pays,
113
+ markup_percentage, markup_on_delivery=0, markup_per_recipient=0,
114
+ markup_on_design_spam_test=0)
115
+ options = { :body => {
115
116
  :Currency => currency,
116
117
  :CanPurchaseCredits => can_purchase_credits,
117
118
  :ClientPays => client_pays,
@@ -124,24 +125,12 @@ module CreateSend
124
125
 
125
126
  # Sets the monthly billing settings for this client.
126
127
  def set_monthly_billing(currency, client_pays, markup_percentage)
127
- options = { :body => {
128
+ options = { :body => {
128
129
  :Currency => currency,
129
130
  :ClientPays => client_pays,
130
131
  :MarkupPercentage => markup_percentage }.to_json }
131
132
  put 'setmonthlybilling', options
132
133
  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
145
134
 
146
135
  # Deletes this client.
147
136
  def delete
@@ -11,12 +11,26 @@ module CreateSend
11
11
  end
12
12
 
13
13
  # Creates a new list for a client.
14
- def self.create(client_id, title, unsubscribe_page, confirmed_opt_in, confirmation_success_page)
14
+ # client_id - String representing the ID of the client for whom the list
15
+ # will be created
16
+ # title - String representing the list title/name
17
+ # unsubscribe_page - String representing the url of the unsubscribe
18
+ # confirmation page
19
+ # confirmed_opt_in - A Boolean representing whether this should be a
20
+ # confirmed opt-in (double opt-in) list
21
+ # confirmation_success_page - String representing the url of the
22
+ # confirmation success page
23
+ # unsubscribe_setting - A String which must be either "AllClientLists" or
24
+ # "OnlyThisList". See the documentation for details:
25
+ # http://www.campaignmonitor.com/api/lists/#creating_a_list
26
+ def self.create(client_id, title, unsubscribe_page, confirmed_opt_in,
27
+ confirmation_success_page, unsubscribe_setting="AllClientLists")
15
28
  options = { :body => {
16
29
  :Title => title,
17
30
  :UnsubscribePage => unsubscribe_page,
18
31
  :ConfirmedOptIn => confirmed_opt_in,
19
- :ConfirmationSuccessPage => confirmation_success_page }.to_json }
32
+ :ConfirmationSuccessPage => confirmation_success_page,
33
+ :UnsubscribeSetting => unsubscribe_setting }.to_json }
20
34
  response = CreateSend.post "/lists/#{client_id}.json", options
21
35
  response.parsed_response
22
36
  end
@@ -39,11 +53,13 @@ module CreateSend
39
53
  # Deletes a custom field associated with this list.
40
54
  def delete_custom_field(custom_field_key)
41
55
  custom_field_key = CGI.escape(custom_field_key)
42
- response = CreateSend.delete "/lists/#{list_id}/customfields/#{custom_field_key}.json", {}
56
+ response = CreateSend.delete(
57
+ "/lists/#{list_id}/customfields/#{custom_field_key}.json", {})
43
58
  end
44
59
 
45
60
  # Updates the options of a multi-optioned custom field on this list.
46
- def update_custom_field_options(custom_field_key, new_options, keep_existing_options)
61
+ def update_custom_field_options(custom_field_key, new_options,
62
+ keep_existing_options)
47
63
  custom_field_key = CGI.escape(custom_field_key)
48
64
  options = { :body => {
49
65
  :Options => new_options,
@@ -76,8 +92,9 @@ module CreateSend
76
92
  end
77
93
 
78
94
  # Gets the active subscribers for this list.
79
- def active(date, page=1, page_size=1000, order_field="email", order_direction="asc")
80
- options = { :query => {
95
+ def active(date, page=1, page_size=1000, order_field="email",
96
+ order_direction="asc")
97
+ options = { :query => {
81
98
  :date => date,
82
99
  :page => page,
83
100
  :pagesize => page_size,
@@ -88,8 +105,9 @@ module CreateSend
88
105
  end
89
106
 
90
107
  # Gets the bounced subscribers for this list.
91
- def bounced(date, page=1, page_size=1000, order_field="email", order_direction="asc")
92
- options = { :query => {
108
+ def bounced(date, page=1, page_size=1000, order_field="email",
109
+ order_direction="asc")
110
+ options = { :query => {
93
111
  :date => date,
94
112
  :page => page,
95
113
  :pagesize => page_size,
@@ -100,8 +118,9 @@ module CreateSend
100
118
  end
101
119
 
102
120
  # Gets the unsubscribed subscribers for this list.
103
- def unsubscribed(date, page=1, page_size=1000, order_field="email", order_direction="asc")
104
- options = { :query => {
121
+ def unsubscribed(date, page=1, page_size=1000, order_field="email",
122
+ order_direction="asc")
123
+ options = { :query => {
105
124
  :date => date,
106
125
  :page => page,
107
126
  :pagesize => page_size,
@@ -112,8 +131,9 @@ module CreateSend
112
131
  end
113
132
 
114
133
  # Gets the deleted subscribers for this list.
115
- def deleted(date, page=1, page_size=1000, order_field="email", order_direction="asc")
116
- options = { :query => {
134
+ def deleted(date, page=1, page_size=1000, order_field="email",
135
+ order_direction="asc")
136
+ options = { :query => {
117
137
  :date => date,
118
138
  :page => page,
119
139
  :pagesize => page_size,
@@ -124,12 +144,33 @@ module CreateSend
124
144
  end
125
145
 
126
146
  # Updates this list.
127
- def update(title, unsubscribe_page, confirmed_opt_in, confirmation_success_page)
147
+ # title - String representing the list title/name
148
+ # unsubscribe_page - String representing the url of the unsubscribe
149
+ # confirmation page
150
+ # confirmed_opt_in - A Boolean representing whether this should be a
151
+ # confirmed opt-in (double opt-in) list
152
+ # confirmation_success_page - String representing the url of the
153
+ # confirmation success page
154
+ # unsubscribe_setting - A String which must be either "AllClientLists" or
155
+ # "OnlyThisList". See the documentation for details:
156
+ # http://www.campaignmonitor.com/api/lists/#updating_a_list
157
+ # add_unsubscribes_to_supp_list - When unsubscribe_setting is
158
+ # "AllClientLists", a Boolean which represents whether unsubscribes from
159
+ # this list should be added to the suppression list
160
+ # scrub_active_with_supp_list - When unsubscribe_setting is
161
+ # "AllClientLists", a Boolean which represents whether active sunscribers
162
+ # should be scrubbed against the suppression list
163
+ def update(title, unsubscribe_page, confirmed_opt_in,
164
+ confirmation_success_page, unsubscribe_setting="AllClientLists",
165
+ add_unsubscribes_to_supp_list=false, scrub_active_with_supp_list=false)
128
166
  options = { :body => {
129
167
  :Title => title,
130
168
  :UnsubscribePage => unsubscribe_page,
131
169
  :ConfirmedOptIn => confirmed_opt_in,
132
- :ConfirmationSuccessPage => confirmation_success_page }.to_json }
170
+ :ConfirmationSuccessPage => confirmation_success_page,
171
+ :UnsubscribeSetting => unsubscribe_setting,
172
+ :AddUnsubscribesToSuppList => add_unsubscribes_to_supp_list,
173
+ :ScrubActiveWithSuppList => scrub_active_with_supp_list }.to_json }
133
174
  response = CreateSend.put "/lists/#{list_id}.json", options
134
175
  end
135
176
 
@@ -139,7 +180,7 @@ module CreateSend
139
180
  response.map{|item| Hashie::Mash.new(item)}
140
181
  end
141
182
 
142
- # Creates a new webhook for the specified events (an array of strings).
183
+ # Creates a new webhook for the specified events (an array of strings).
143
184
  # Valid events are "Subscribe", "Deactivate", and "Update".
144
185
  # Valid payload formats are "json", and "xml".
145
186
  def create_webhook(events, url, payload_format)
@@ -160,7 +201,8 @@ module CreateSend
160
201
 
161
202
  # Deletes a webhook associated with this list.
162
203
  def delete_webhook(webhook_id)
163
- response = CreateSend.delete "/lists/#{list_id}/webhooks/#{webhook_id}.json", {}
204
+ response = CreateSend.delete(
205
+ "/lists/#{list_id}/webhooks/#{webhook_id}.json", {})
164
206
  end
165
207
 
166
208
  # Activates a webhook associated with this list.
@@ -19,7 +19,7 @@ module CreateSend
19
19
  Hashie::Mash.new(response)
20
20
  end
21
21
 
22
- # Adds a person to the client. password is optional. if ommitted, an
22
+ # Adds a person to the client. password is optional. if ommitted, an
23
23
  # email invitation will be sent to the person
24
24
  def self.add(client_id, email_address, name, access_level, password)
25
25
  options = { :body => {
@@ -30,8 +30,9 @@ module CreateSend
30
30
  response = CreateSend.post "/clients/#{client_id}/people.json", options
31
31
  Hashie::Mash.new(response)
32
32
  end
33
-
34
- # Updates the person details. password is optional and will only be updated if supplied
33
+
34
+ # Updates the person details. password is optional and will only be
35
+ # updated if supplied
35
36
  def update(new_email_address, name, access_level, password)
36
37
  options = {
37
38
  :query => { :email => @email_address },
@@ -50,7 +51,7 @@ module CreateSend
50
51
  options = { :query => { :email => @email_address } }
51
52
  CreateSend.delete uri_for(client_id), options
52
53
  end
53
-
54
+
54
55
  def uri_for(client_id)
55
56
  "/clients/#{client_id}/people.json"
56
57
  end
@@ -36,7 +36,8 @@ module CreateSend
36
36
  end
37
37
 
38
38
  # Gets the active subscribers in this segment.
39
- def subscribers(date, page=1, page_size=1000, order_field="email", order_direction="asc")
39
+ def subscribers(date, page=1, page_size=1000, order_field="email",
40
+ order_direction="asc")
40
41
  options = { :query => {
41
42
  :date => date,
42
43
  :page => page,
@@ -62,7 +63,7 @@ module CreateSend
62
63
  def delete
63
64
  response = CreateSend.delete "/segments/#{segment_id}.json", {}
64
65
  end
65
-
66
+
66
67
  private
67
68
 
68
69
  def get(action, options = {})
@@ -20,31 +20,39 @@ module CreateSend
20
20
  end
21
21
 
22
22
  # Adds a subscriber to a subscriber list.
23
- def self.add(list_id, email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders=false)
23
+ def self.add(list_id, email_address, name, custom_fields, resubscribe,
24
+ restart_subscription_based_autoresponders=false)
24
25
  options = { :body => {
25
26
  :EmailAddress => email_address,
26
27
  :Name => name,
27
28
  :CustomFields => custom_fields,
28
29
  :Resubscribe => resubscribe,
29
- :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json }
30
+ :RestartSubscriptionBasedAutoresponders =>
31
+ restart_subscription_based_autoresponders }.to_json }
30
32
  response = CreateSend.post "/subscribers/#{list_id}.json", options
31
33
  response.parsed_response
32
34
  end
33
35
 
34
36
  # Imports subscribers into a subscriber list.
35
- def self.import(list_id, subscribers, resubscribe, queue_subscription_based_autoresponders=false, restart_subscription_based_autoresponders=false)
37
+ def self.import(list_id, subscribers, resubscribe,
38
+ queue_subscription_based_autoresponders=false,
39
+ restart_subscription_based_autoresponders=false)
36
40
  options = { :body => {
37
41
  :Subscribers => subscribers,
38
42
  :Resubscribe => resubscribe,
39
- :QueueSubscriptionBasedAutoresponders => queue_subscription_based_autoresponders,
40
- :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json }
43
+ :QueueSubscriptionBasedAutoresponders =>
44
+ queue_subscription_based_autoresponders,
45
+ :RestartSubscriptionBasedAutoresponders =>
46
+ restart_subscription_based_autoresponders }.to_json }
41
47
  begin
42
- response = CreateSend.post "/subscribers/#{list_id}/import.json", options
48
+ response = CreateSend.post(
49
+ "/subscribers/#{list_id}/import.json", options)
43
50
  rescue BadRequest => br
44
- # Subscriber import will throw BadRequest if some subscribers are not imported
45
- # successfully. If this occurs, we want to return the ResultData property of
46
- # the BadRequest exception (which is of the same "form" as the response we'd
47
- # receive upon a completely successful import)
51
+ # Subscriber import will throw BadRequest if some subscribers are not
52
+ # imported successfully. If this occurs, we want to return the
53
+ # ResultData property of the BadRequest exception (which is of the
54
+ # same "form" as the response we would receive upon a completely
55
+ # successful import).
48
56
  if br.data.ResultData
49
57
  return br.data.ResultData
50
58
  else
@@ -54,9 +62,10 @@ module CreateSend
54
62
  Hashie::Mash.new(response)
55
63
  end
56
64
 
57
- # Updates any aspect of a subscriber, including email address, name, and
65
+ # Updates any aspect of a subscriber, including email address, name, and
58
66
  # custom field data if supplied.
59
- def update(new_email_address, name, custom_fields, resubscribe, restart_subscription_based_autoresponders=false)
67
+ def update(new_email_address, name, custom_fields, resubscribe,
68
+ restart_subscription_based_autoresponders=false)
60
69
  options = {
61
70
  :query => { :email => @email_address },
62
71
  :body => {
@@ -64,7 +73,8 @@ module CreateSend
64
73
  :Name => name,
65
74
  :CustomFields => custom_fields,
66
75
  :Resubscribe => resubscribe,
67
- :RestartSubscriptionBasedAutoresponders => restart_subscription_based_autoresponders }.to_json }
76
+ :RestartSubscriptionBasedAutoresponders =>
77
+ restart_subscription_based_autoresponders }.to_json }
68
78
  CreateSend.put "/subscribers/#{@list_id}.json", options
69
79
  # Update @email_address, so this object can continue to be used reliably
70
80
  @email_address = new_email_address
@@ -12,7 +12,7 @@ module CreateSend
12
12
 
13
13
  # Creates a new email template.
14
14
  def self.create(client_id, name, html_url, zip_url)
15
- options = { :body => {
15
+ options = { :body => {
16
16
  :Name => name,
17
17
  :HtmlPageURL => html_url,
18
18
  :ZipFileURL => zip_url }.to_json }
@@ -28,7 +28,7 @@ module CreateSend
28
28
 
29
29
  # Updates this email template.
30
30
  def update(name, html_url, zip_url)
31
- options = { :body => {
31
+ options = { :body => {
32
32
  :Name => name,
33
33
  :HtmlPageURL => html_url,
34
34
  :ZipFileURL => zip_url }.to_json }
@@ -1,3 +1,3 @@
1
1
  module CreateSend
2
- VERSION = "1.1.1" unless defined?(CreateSend::VERSION)
2
+ VERSION = "2.0.0" unless defined?(CreateSend::VERSION)
3
3
  end
data/test/client_test.rb CHANGED
@@ -11,7 +11,7 @@ class ClientTest < Test::Unit::TestCase
11
11
 
12
12
  should "create a client" do
13
13
  stub_post(@api_key, "clients.json", "create_client.json")
14
- client_id = CreateSend::Client.create "Client Company Name", "Client Contact Name", "client@example.com", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
14
+ client_id = CreateSend::Client.create "Client Company Name", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
15
15
  client_id.should == "32a381c49a2df99f1d0c6f3c112352b9"
16
16
  end
17
17
 
@@ -68,7 +68,18 @@ class ClientTest < Test::Unit::TestCase
68
68
  lists.first.ListID.should == 'a58ee1d3039b8bec838e6d1482a8a965'
69
69
  lists.first.Name.should == 'List One'
70
70
  end
71
-
71
+
72
+ should "get all lists to which a subscriber with a particular email address belongs" do
73
+ email = "valid@example.com"
74
+ stub_get(@api_key, "clients/#{@client.client_id}/listsforemail.json?email=#{CGI.escape(email)}", "listsforemail.json")
75
+ lists = @client.lists_for_email(email)
76
+ lists.size.should == 2
77
+ lists.first.ListID.should == 'ab4a2b57c7c8f1ba62f898a1af1a575b'
78
+ lists.first.ListName.should == 'List Number One'
79
+ lists.first.SubscriberState.should == 'Active'
80
+ lists.first.DateSubscriberAdded.should == '2012-08-20 22:32:00'
81
+ end
82
+
72
83
  should "get all segments for a client" do
73
84
  stub_get(@api_key, "clients/#{@client.client_id}/segments.json", "segments.json")
74
85
  segments = @client.segments
@@ -94,7 +105,7 @@ class ClientTest < Test::Unit::TestCase
94
105
  res.Results.first.Date.should == "2010-10-26 10:55:31"
95
106
  res.Results.first.State.should == "Suppressed"
96
107
  end
97
-
108
+
98
109
  should "get all people" do
99
110
  stub_get(@api_key, "clients/#{@client.client_id}/people.json", "people.json")
100
111
  people = @client.people
@@ -112,40 +123,35 @@ class ClientTest < Test::Unit::TestCase
112
123
  templates.first.TemplateID.should == '5cac213cf061dd4e008de5a82b7a3621'
113
124
  templates.first.Name.should == 'Template One'
114
125
  end
115
-
126
+
116
127
  should "set primary contact" do
117
128
  email = 'person@blackhole.com'
118
129
  stub_put(@api_key, "clients/#{@client.client_id}/primarycontact.json?email=#{CGI.escape(email)}", 'client_set_primary_contact.json')
119
130
  result = @client.set_primary_contact email
120
131
  result.EmailAddress.should == email
121
132
  end
122
-
133
+
123
134
  should "get primary contact" do
124
135
  stub_get(@api_key, "clients/#{@client.client_id}/primarycontact.json", 'client_get_primary_contact.json')
125
136
  result = @client.get_primary_contact
126
137
  result.EmailAddress.should == 'person@blackhole.com'
127
138
  end
128
-
139
+
129
140
  should "set basics" do
130
141
  stub_put(@api_key, "clients/#{@client.client_id}/setbasics.json", nil)
131
- @client.set_basics "Client Company Name", "Client Contact Name", "client@example.com", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
142
+ @client.set_basics "Client Company Name", "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia"
132
143
  end
133
-
134
- should "set access" do
135
- stub_put(@api_key, "clients/#{@client.client_id}/setaccess.json", nil)
136
- @client.set_access "username", "password", 321
137
- end
138
-
144
+
139
145
  should "set payg billing" do
140
146
  stub_put(@api_key, "clients/#{@client.client_id}/setpaygbilling.json", nil)
141
147
  @client.set_payg_billing "CAD", true, true, 150
142
148
  end
143
-
149
+
144
150
  should "set monthly billing" do
145
151
  stub_put(@api_key, "clients/#{@client.client_id}/setmonthlybilling.json", nil)
146
152
  @client.set_monthly_billing "CAD", true, 150
147
153
  end
148
-
154
+
149
155
  should "delete a client" do
150
156
  stub_delete(@api_key, "clients/#{@client.client_id}.json", nil)
151
157
  @client.delete
@@ -103,7 +103,7 @@ class CreateSendTest < Test::Unit::TestCase
103
103
  context "#{status.first}, a post" do
104
104
  should "raise a #{exception.name} error" do
105
105
  stub_post(@api_key, "clients.json", (status.first == '400' or status.first == '401') ? 'custom_api_error.json' : nil, status)
106
- lambda { CreateSend::Client.create "Client Company Name", "Client Contact Name", "client@example.com",
106
+ lambda { CreateSend::Client.create "Client Company Name",
107
107
  "(GMT+10:00) Canberra, Melbourne, Sydney", "Australia" }.should raise_error(exception)
108
108
  end
109
109
  end
@@ -3,5 +3,6 @@
3
3
  "Title": "a non-basic list :)",
4
4
  "UnsubscribePage": "",
5
5
  "ListID": "2fe4c8f0373ce320e2200596d7ef168f",
6
- "ConfirmationSuccessPage": ""
6
+ "ConfirmationSuccessPage": "",
7
+ "UnsubscribeSetting": "AllClientLists"
7
8
  }
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "ListID": "ab4a2b57c7c8f1ba62f898a1af1a575b",
4
+ "ListName": "List Number One",
5
+ "SubscriberState": "Active",
6
+ "DateSubscriberAdded": "2012-08-20 22:32:00"
7
+ },
8
+ {
9
+ "ListID": "d8e59b07138cf1316a6587007c443e21",
10
+ "ListName": "List Number Two",
11
+ "SubscriberState": "Unsubscribed",
12
+ "DateSubscriberAdded": "2012-08-21 01:35:00"
13
+ }
14
+ ]
data/test/list_test.rb CHANGED
@@ -10,17 +10,33 @@ class ListTest < Test::Unit::TestCase
10
10
  @list = CreateSend::List.new @list_id
11
11
  end
12
12
 
13
- should "create a list" do
13
+ should "create a list without passing in unsubscribe setting" do
14
14
  stub_post(@api_key, "lists/#{@client_id}.json", "create_list.json")
15
15
  list_id = CreateSend::List.create @client_id, "List One", "", false, ""
16
16
  list_id.should == "e3c5f034d68744f7881fdccf13c2daee"
17
17
  end
18
18
 
19
- should "update a list" do
19
+ should "create a list passing in unsubscribe setting" do
20
+ stub_post(@api_key, "lists/#{@client_id}.json", "create_list.json")
21
+ list_id = CreateSend::List.create @client_id, "List One", "", false, "", "OnlyThisList"
22
+ list_id.should == "e3c5f034d68744f7881fdccf13c2daee"
23
+ end
24
+
25
+ should "update a list without passing in unsubscribe setting" do
20
26
  stub_put(@api_key, "lists/#{@list.list_id}.json", nil)
21
27
  @list.update "List One Renamed", "", false, ""
22
28
  end
23
29
 
30
+ should "update a list passing in unsubscribe setting" do
31
+ stub_put(@api_key, "lists/#{@list.list_id}.json", nil)
32
+ @list.update "List One Renamed", "", false, "", "OnlyThisList"
33
+ end
34
+
35
+ should "update a list passing in unsubscribe setting and suppression list options" do
36
+ stub_put(@api_key, "lists/#{@list.list_id}.json", nil)
37
+ @list.update "List One Renamed", "", false, "", "OnlyThisList", true, true
38
+ end
39
+
24
40
  should "delete a list" do
25
41
  stub_delete(@api_key, "lists/#{@list.list_id}.json", nil)
26
42
  @list.delete
@@ -53,6 +69,7 @@ class ListTest < Test::Unit::TestCase
53
69
  details.UnsubscribePage.should == ""
54
70
  details.ListID.should == "2fe4c8f0373ce320e2200596d7ef168f"
55
71
  details.ConfirmationSuccessPage.should == ""
72
+ details.UnsubscribeSetting.should == "AllClientLists"
56
73
  end
57
74
 
58
75
  should "get the custom fields for a list" do
metadata CHANGED
@@ -1,115 +1,111 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: createsend
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
4
5
  prerelease:
5
- version: 1.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - James Dennes
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-08-02 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70279968073360 !ruby/object:Gem::Requirement
18
17
  none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70279968073360
25
+ - !ruby/object:Gem::Dependency
27
26
  name: fakeweb
28
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &70279968072660 !ruby/object:Gem::Requirement
29
28
  none: false
30
- requirements:
29
+ requirements:
31
30
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: "1.3"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *70279968072660
36
+ - !ruby/object:Gem::Dependency
38
37
  name: jnunemaker-matchy
39
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &70279968072160 !ruby/object:Gem::Requirement
40
39
  none: false
41
- requirements:
40
+ requirements:
42
41
  - - ~>
43
- - !ruby/object:Gem::Version
44
- version: "0.4"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.4'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *70279968072160
47
+ - !ruby/object:Gem::Dependency
49
48
  name: mocha
50
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &70279968071620 !ruby/object:Gem::Requirement
51
50
  none: false
52
- requirements:
51
+ requirements:
53
52
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: "0.9"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
57
+ version_requirements: *70279968071620
58
+ - !ruby/object:Gem::Dependency
60
59
  name: shoulda
61
- requirement: &id005 !ruby/object:Gem::Requirement
60
+ requirement: &70279968070900 !ruby/object:Gem::Requirement
62
61
  none: false
63
- requirements:
62
+ requirements:
64
63
  - - ~>
65
- - !ruby/object:Gem::Version
66
- version: 3.0.1
64
+ - !ruby/object:Gem::Version
65
+ version: 3.1.1
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *70279968070900
69
+ - !ruby/object:Gem::Dependency
71
70
  name: json
72
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ requirement: &70279968070360 !ruby/object:Gem::Requirement
73
72
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
78
77
  type: :runtime
79
78
  prerelease: false
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
79
+ version_requirements: *70279968070360
80
+ - !ruby/object:Gem::Dependency
82
81
  name: hashie
83
- requirement: &id007 !ruby/object:Gem::Requirement
82
+ requirement: &70279968069500 !ruby/object:Gem::Requirement
84
83
  none: false
85
- requirements:
84
+ requirements:
86
85
  - - ~>
87
- - !ruby/object:Gem::Version
88
- version: "1.0"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.0'
89
88
  type: :runtime
90
89
  prerelease: false
91
- version_requirements: *id007
92
- - !ruby/object:Gem::Dependency
90
+ version_requirements: *70279968069500
91
+ - !ruby/object:Gem::Dependency
93
92
  name: httparty
94
- requirement: &id008 !ruby/object:Gem::Requirement
93
+ requirement: &70279968068780 !ruby/object:Gem::Requirement
95
94
  none: false
96
- requirements:
95
+ requirements:
97
96
  - - ~>
98
- - !ruby/object:Gem::Version
99
- version: "0.8"
97
+ - !ruby/object:Gem::Version
98
+ version: '0.8'
100
99
  type: :runtime
101
100
  prerelease: false
102
- version_requirements: *id008
101
+ version_requirements: *70279968068780
103
102
  description: Implements the complete functionality of the createsend API.
104
- email:
103
+ email:
105
104
  - jdennes@gmail.com
106
105
  executables: []
107
-
108
106
  extensions: []
109
-
110
107
  extra_rdoc_files: []
111
-
112
- files:
108
+ files:
113
109
  - .gitignore
114
110
  - .travis.yml
115
111
  - Gemfile
@@ -172,6 +168,7 @@ files:
172
168
  - test/fixtures/list_stats.json
173
169
  - test/fixtures/list_webhooks.json
174
170
  - test/fixtures/lists.json
171
+ - test/fixtures/listsforemail.json
175
172
  - test/fixtures/people.json
176
173
  - test/fixtures/person_details.json
177
174
  - test/fixtures/scheduled_campaigns.json
@@ -194,32 +191,30 @@ files:
194
191
  - test/template_test.rb
195
192
  homepage: http://github.com/campaignmonitor/createsend-ruby/
196
193
  licenses: []
197
-
198
194
  post_install_message:
199
195
  rdoc_options: []
200
-
201
- require_paths:
196
+ require_paths:
202
197
  - lib
203
- required_ruby_version: !ruby/object:Gem::Requirement
198
+ required_ruby_version: !ruby/object:Gem::Requirement
204
199
  none: false
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: "0"
209
- required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ! '>='
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
205
  none: false
211
- requirements:
212
- - - ">="
213
- - !ruby/object:Gem::Version
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
214
209
  version: 1.3.6
215
210
  requirements: []
216
-
217
211
  rubyforge_project:
218
- rubygems_version: 1.8.17
212
+ rubygems_version: 1.8.15
219
213
  signing_key:
220
214
  specification_version: 3
221
- summary: A library which implements the complete functionality of v3 of the createsend API.
222
- test_files:
215
+ summary: A library which implements the complete functionality of v3 of the createsend
216
+ API.
217
+ test_files:
223
218
  - test/administrator_test.rb
224
219
  - test/campaign_test.rb
225
220
  - test/client_test.rb
@@ -264,6 +259,7 @@ test_files:
264
259
  - test/fixtures/list_stats.json
265
260
  - test/fixtures/list_webhooks.json
266
261
  - test/fixtures/lists.json
262
+ - test/fixtures/listsforemail.json
267
263
  - test/fixtures/people.json
268
264
  - test/fixtures/person_details.json
269
265
  - test/fixtures/scheduled_campaigns.json