createsend 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- createsend (0.2.0)
5
- hashie (~> 0.4.0)
6
- httparty (~> 0.6.1)
4
+ createsend (0.2.1)
5
+ hashie (~> 1.0)
6
+ httparty (~> 0.7)
7
7
  json
8
8
 
9
9
  GEM
@@ -11,14 +11,12 @@ GEM
11
11
  specs:
12
12
  crack (0.1.8)
13
13
  fakeweb (1.3.0)
14
- hashie (0.4.0)
15
- httparty (0.6.1)
14
+ hashie (1.0.0)
15
+ httparty (0.7.4)
16
16
  crack (= 0.1.8)
17
17
  jnunemaker-matchy (0.4.0)
18
- json (1.4.6)
19
- mocha (0.9.10)
20
- rake
21
- rake (0.8.7)
18
+ json (1.5.1)
19
+ mocha (0.9.12)
22
20
  shoulda (2.11.3)
23
21
 
24
22
  PLATFORMS
@@ -27,9 +25,9 @@ PLATFORMS
27
25
  DEPENDENCIES
28
26
  createsend!
29
27
  fakeweb (~> 1.3)
30
- hashie (~> 0.4.0)
31
- httparty (~> 0.6.1)
32
- jnunemaker-matchy (~> 0.4.0)
28
+ hashie (~> 1.0)
29
+ httparty (~> 0.7)
30
+ jnunemaker-matchy (~> 0.4)
33
31
  json
34
32
  mocha (~> 0.9)
35
33
  shoulda (~> 2.11)
data/createsend.gemspec CHANGED
@@ -5,12 +5,12 @@ require File.expand_path('lib/createsend/version')
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.add_development_dependency('fakeweb', '~> 1.3')
8
- s.add_development_dependency('jnunemaker-matchy', '~> 0.4.0')
8
+ s.add_development_dependency('jnunemaker-matchy', '~> 0.4')
9
9
  s.add_development_dependency('mocha', '~> 0.9')
10
10
  s.add_development_dependency('shoulda', '~> 2.11')
11
11
  s.add_runtime_dependency('json')
12
- s.add_runtime_dependency('hashie', '~> 0.4.0')
13
- s.add_runtime_dependency('httparty', '~> 0.6.1')
12
+ s.add_runtime_dependency('hashie', '~> 1.0')
13
+ s.add_runtime_dependency('httparty', '~> 0.7')
14
14
  s.name = "createsend"
15
15
  s.author = "James Dennes"
16
16
  s.description = %q{A library which implements the complete functionality of v3 of the createsend API.}
data/lib/createsend.rb CHANGED
@@ -57,7 +57,10 @@ module CreateSend
57
57
  class CreateSend
58
58
  include HTTParty
59
59
 
60
- headers({ 'User-Agent' => "createsend-ruby-#{CreateSend::VERSION}", 'Content-Type' => 'application/json' })
60
+ headers({
61
+ 'User-Agent' => "createsend-ruby-#{CreateSend::VERSION}",
62
+ 'Content-Type' => 'application/json; charset=utf-8',
63
+ 'Accept-Encoding' => 'gzip, deflate' })
61
64
  base_uri CreateSendOptions['base_uri']
62
65
  basic_auth CreateSendOptions['api_key'], 'x'
63
66
 
@@ -51,6 +51,21 @@ module CreateSend
51
51
  Hashie::Mash.new(response)
52
52
  end
53
53
 
54
+ # Updates any aspect of a subscriber, including email address, name, and
55
+ # custom field data if supplied.
56
+ def update(new_email_address, name, custom_fields, resubscribe)
57
+ options = {
58
+ :query => { :email => @email_address },
59
+ :body => {
60
+ :EmailAddress => new_email_address,
61
+ :Name => name,
62
+ :CustomFields => custom_fields,
63
+ :Resubscribe => resubscribe }.to_json }
64
+ CreateSend.put "/subscribers/#{@list_id}.json", options
65
+ # Update @email_address, so this object can continue to be used reliably
66
+ @email_address = new_email_address
67
+ end
68
+
54
69
  # Unsubscribes this subscriber from the associated list.
55
70
  def unsubscribe
56
71
  options = { :body => {
@@ -1,3 +1,3 @@
1
1
  module CreateSend
2
- VERSION = "0.2.1" unless defined?(CreateSend::VERSION)
2
+ VERSION = "0.3.0" unless defined?(CreateSend::VERSION)
3
3
  end
data/test/client_test.rb CHANGED
@@ -76,6 +76,7 @@ class ClientTest < Test::Unit::TestCase
76
76
  res.TotalNumberOfRecords.should == 5
77
77
  res.NumberOfPages.should == 1
78
78
  res.Results.size.should == 5
79
+ res.Results.first.SuppressionReason.should == "Unsubscribed"
79
80
  res.Results.first.EmailAddress.should == "example+1@example.com"
80
81
  res.Results.first.Date.should == "2010-10-26 10:55:31"
81
82
  res.Results.first.State.should == "Suppressed"
@@ -1,26 +1,31 @@
1
1
  {
2
2
  "Results": [
3
3
  {
4
+ "SuppressionReason": "Unsubscribed",
4
5
  "EmailAddress": "example+1@example.com",
5
6
  "Date": "2010-10-26 10:55:31",
6
7
  "State": "Suppressed"
7
8
  },
8
9
  {
10
+ "SuppressionReason": "Unsubscribed",
9
11
  "EmailAddress": "example+2@example.com",
10
12
  "Date": "2010-10-26 10:55:31",
11
13
  "State": "Suppressed"
12
14
  },
13
15
  {
16
+ "SuppressionReason": "Unsubscribed",
14
17
  "EmailAddress": "example+3@example.com",
15
18
  "Date": "2010-10-26 10:55:31",
16
19
  "State": "Suppressed"
17
20
  },
18
21
  {
22
+ "SuppressionReason": "Unsubscribed",
19
23
  "EmailAddress": "subscriber@example.com",
20
24
  "Date": "2010-10-25 13:11:04",
21
25
  "State": "Suppressed"
22
26
  },
23
27
  {
28
+ "SuppressionReason": "Unsubscribed",
24
29
  "EmailAddress": "subscriberone@example.com",
25
30
  "Date": "2010-10-25 13:04:15",
26
31
  "State": "Suppressed"
data/test/helper.rb CHANGED
@@ -26,7 +26,7 @@ def stub_request(method, api_key, url, filename, status=nil)
26
26
  options = {:body => ""}
27
27
  options.merge!({:body => fixture_file(filename)}) if filename
28
28
  options.merge!({:status => status}) if status
29
- options.merge!(:content_type => "application/json")
29
+ options.merge!(:content_type => "application/json; charset=utf-8")
30
30
  FakeWeb.register_uri(method, createsend_url(api_key, url), options)
31
31
  end
32
32
 
data/test/list_test.rb CHANGED
@@ -15,12 +15,12 @@ class ListTest < Test::Unit::TestCase
15
15
  list_id = CreateSend::List.create @client_id, "List One", "", false, ""
16
16
  list_id.should == "e3c5f034d68744f7881fdccf13c2daee"
17
17
  end
18
-
18
+
19
19
  should "update a list" do
20
20
  stub_put(@api_key, "lists/#{@list.list_id}.json", nil)
21
21
  @list.update "List One Renamed", "", false, ""
22
22
  end
23
-
23
+
24
24
  should "delete a list" do
25
25
  stub_delete(@api_key, "lists/#{@list.list_id}.json", nil)
26
26
  @list.delete
@@ -34,6 +34,24 @@ class SubscriberTest < Test::Unit::TestCase
34
34
  email_address = CreateSend::Subscriber.add @list_id, "subscriber@example.com", "Subscriber", custom_fields, true
35
35
  email_address.should == "subscriber@example.com"
36
36
  end
37
+
38
+ should "add a subscriber with custom fields including multi-option fields" do
39
+ stub_post(@api_key, "subscribers/#{@list_id}.json", "add_subscriber.json")
40
+ custom_fields = [ { :Key => 'multioptionselectone', :Value => 'myoption' },
41
+ { :Key => 'multioptionselectmany', :Value => 'firstoption' },
42
+ { :Key => 'multioptionselectmany', :Value => 'secondoption' } ]
43
+ email_address = CreateSend::Subscriber.add @list_id, "subscriber@example.com", "Subscriber", custom_fields, true
44
+ email_address.should == "subscriber@example.com"
45
+ end
46
+
47
+ should "update a subscriber with custom fields" do
48
+ email = "subscriber@example.com"
49
+ new_email = "new_email_address@example.com"
50
+ stub_put(@api_key, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil)
51
+ custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ]
52
+ @subscriber.update new_email, "Subscriber", custom_fields, true
53
+ @subscriber.email_address.should == new_email
54
+ end
37
55
 
38
56
  should "import many subscribers at once" do
39
57
  stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json")
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: 21
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Dennes
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 +11:00
18
+ date: 2011-04-18 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ type: :development
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -29,27 +30,26 @@ dependencies:
29
30
  - 1
30
31
  - 3
31
32
  version: "1.3"
32
- type: :development
33
- prerelease: false
34
- name: fakeweb
35
33
  version_requirements: *id001
34
+ name: fakeweb
35
+ prerelease: false
36
36
  - !ruby/object:Gem::Dependency
37
+ type: :development
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
40
41
  - - ~>
41
42
  - !ruby/object:Gem::Version
42
- hash: 15
43
+ hash: 3
43
44
  segments:
44
45
  - 0
45
46
  - 4
46
- - 0
47
- version: 0.4.0
48
- type: :development
49
- prerelease: false
50
- name: jnunemaker-matchy
47
+ version: "0.4"
51
48
  version_requirements: *id002
49
+ name: jnunemaker-matchy
50
+ prerelease: false
52
51
  - !ruby/object:Gem::Dependency
52
+ type: :development
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
@@ -60,11 +60,11 @@ dependencies:
60
60
  - 0
61
61
  - 9
62
62
  version: "0.9"
63
- type: :development
64
- prerelease: false
65
- name: mocha
66
63
  version_requirements: *id003
64
+ name: mocha
65
+ prerelease: false
67
66
  - !ruby/object:Gem::Dependency
67
+ type: :development
68
68
  requirement: &id004 !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
@@ -75,11 +75,11 @@ dependencies:
75
75
  - 2
76
76
  - 11
77
77
  version: "2.11"
78
- type: :development
79
- prerelease: false
80
- name: shoulda
81
78
  version_requirements: *id004
79
+ name: shoulda
80
+ prerelease: false
82
81
  - !ruby/object:Gem::Dependency
82
+ type: :runtime
83
83
  requirement: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -89,11 +89,11 @@ dependencies:
89
89
  segments:
90
90
  - 0
91
91
  version: "0"
92
- type: :runtime
93
- prerelease: false
94
- name: json
95
92
  version_requirements: *id005
93
+ name: json
94
+ prerelease: false
96
95
  - !ruby/object:Gem::Dependency
96
+ type: :runtime
97
97
  requirement: &id006 !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -101,15 +101,14 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  hash: 15
103
103
  segments:
104
+ - 1
104
105
  - 0
105
- - 4
106
- - 0
107
- version: 0.4.0
108
- type: :runtime
109
- prerelease: false
110
- name: hashie
106
+ version: "1.0"
111
107
  version_requirements: *id006
108
+ name: hashie
109
+ prerelease: false
112
110
  - !ruby/object:Gem::Dependency
111
+ type: :runtime
113
112
  requirement: &id007 !ruby/object:Gem::Requirement
114
113
  none: false
115
114
  requirements:
@@ -118,13 +117,11 @@ dependencies:
118
117
  hash: 5
119
118
  segments:
120
119
  - 0
121
- - 6
122
- - 1
123
- version: 0.6.1
124
- type: :runtime
125
- prerelease: false
126
- name: httparty
120
+ - 7
121
+ version: "0.7"
127
122
  version_requirements: *id007
123
+ name: httparty
124
+ prerelease: false
128
125
  description: A library which implements the complete functionality of v3 of the createsend API.
129
126
  email:
130
127
  - jdennes@gmail.com
@@ -233,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
230
  requirements: []
234
231
 
235
232
  rubyforge_project:
236
- rubygems_version: 1.3.7
233
+ rubygems_version: 1.4.2
237
234
  signing_key:
238
235
  specification_version: 3
239
236
  summary: A library which implements the complete functionality of v3 of the createsend API.