mailchimp 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CONTRIBUTORS.markdown +1 -2
- data/README-api.markdown +9 -3
- data/lib/mailchimp.rb +1 -0
- data/lib/mailchimp/api.rb +1 -1
- data/lib/mailchimp/api_error.rb +10 -0
- data/lib/mailchimp/base.rb +3 -2
- data/lib/mailchimp/export.rb +1 -4
- data/lib/mailchimp/ext/httparty.rb +1 -1
- data/lib/mailchimp/mandrill.rb +1 -1
- data/lib/mailchimp/version.rb +1 -1
- data/mailchimp.gemspec +4 -4
- data/test/lib/api_test.rb +10 -6
- data/test/lib/export_test.rb +6 -5
- metadata +55 -20
- data/test/integration/export_test.rb +0 -34
data/CONTRIBUTORS.markdown
CHANGED
@@ -14,5 +14,4 @@
|
|
14
14
|
* [Dave Worth](https://github.com/daveworth)
|
15
15
|
* [Mike Skalnik](https://github.com/skalnik)
|
16
16
|
* [Kristopher Murata](https://github.com/krsmurata)
|
17
|
-
* [Michael Klishin](https://github.com/michaelklishin)
|
18
|
-
* [Ben Simpson](https://github.com/bsimpson)
|
17
|
+
* [Michael Klishin](https://github.com/michaelklishin)
|
data/README-api.markdown
CHANGED
@@ -63,9 +63,15 @@ or
|
|
63
63
|
### Export API usage
|
64
64
|
|
65
65
|
In addition to the standard API you can make calls to the
|
66
|
-
[MailChimp Export API](http://apidocs.mailchimp.com/export/1.0/) using a
|
67
|
-
|
68
|
-
|
66
|
+
[MailChimp Export API](http://apidocs.mailchimp.com/export/1.0/) using a APIExport object. Given an existing
|
67
|
+
Mailchimp::API object you can request a new Mailchimp::APIExporter object:
|
68
|
+
|
69
|
+
api = Mailchimp::API.new(@api_key)
|
70
|
+
mailchimp_export = api.get_exporter
|
71
|
+
|
72
|
+
or you can construct a new object directly:
|
73
|
+
|
74
|
+
mailchimp_export = Mailchimp::APIExport.new(@api_key)
|
69
75
|
|
70
76
|
Calling Export API functions is identical to making standard API calls but the
|
71
77
|
return value is an Enumerator which loops over the lines returned from the
|
data/lib/mailchimp.rb
CHANGED
data/lib/mailchimp/api.rb
CHANGED
@@ -40,7 +40,7 @@ module Mailchimp
|
|
40
40
|
end
|
41
41
|
|
42
42
|
if @throws_exceptions && response.is_a?(Hash) && response["error"]
|
43
|
-
raise
|
43
|
+
raise Mailchimp::APIError.new(response['error'],response['code'])
|
44
44
|
end
|
45
45
|
|
46
46
|
response
|
data/lib/mailchimp/base.rb
CHANGED
@@ -6,12 +6,13 @@ module Mailchimp
|
|
6
6
|
include HTTParty
|
7
7
|
default_timeout 30
|
8
8
|
|
9
|
-
attr_accessor :api_key, :timeout, :options
|
9
|
+
attr_accessor :api_key, :timeout, :options, :throws_exceptions
|
10
10
|
|
11
11
|
def initialize(api_key = nil, default_parameters = {})
|
12
12
|
@api_key = api_key || ENV['MAILCHIMP_API_KEY'] || nil
|
13
13
|
@timeout = default_parameters.delete(:timeout)
|
14
14
|
@default_params = default_parameters
|
15
|
+
@throws_exceptions = false
|
15
16
|
end
|
16
17
|
|
17
18
|
def dc_from_api_key
|
@@ -39,7 +40,7 @@ module Mailchimp
|
|
39
40
|
response = self.class.post(url, :body => params, :timeout => timeout)
|
40
41
|
begin; response = JSON.parse(response.body); rescue; response = response.body ;end
|
41
42
|
if @throws_exceptions && response.is_a?(Hash) && response["error"]
|
42
|
-
raise
|
43
|
+
raise Mailchimp::APIError response["error"], response["code"]
|
43
44
|
end
|
44
45
|
response
|
45
46
|
end
|
data/lib/mailchimp/export.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
module Mailchimp
|
2
2
|
class Export < Base
|
3
|
-
|
4
|
-
format :plain
|
5
|
-
|
6
3
|
def initialize(api_key = nil, default_parameters = {})
|
7
4
|
super(api_key, {:apikey => api_key}.merge(default_parameters))
|
8
5
|
end
|
@@ -20,7 +17,7 @@ module Mailchimp
|
|
20
17
|
lines = response.body.lines
|
21
18
|
if @throws_exceptions
|
22
19
|
first_line_object = JSON.parse(lines.first) if lines.first
|
23
|
-
raise
|
20
|
+
raise Mailchimp::APIError.new(first_line_object["error"],first_line_object["code"]) if first_line_object.is_a?(Hash) && first_line_object["error"]
|
24
21
|
end
|
25
22
|
|
26
23
|
lines
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class MailchimpPseudoJSONParser < HTTParty::Parser
|
2
2
|
# Unfornately Mailchimp's API returns invalid JSON for some valid requests,
|
3
3
|
# specifically mandrill's users/ping. We need to just pass that through instead
|
4
4
|
# of blowing up inside of HTTParty so that we can do something with it later.
|
data/lib/mailchimp/mandrill.rb
CHANGED
data/lib/mailchimp/version.rb
CHANGED
data/mailchimp.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "mailchimp/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "mailchimp"
|
7
7
|
s.version = Mailchimp::VERSION
|
8
|
-
s.authors = ["Chris Kelly"]
|
9
|
-
s.email = ["
|
8
|
+
s.authors = ["Chris Kelly", "Dave Worth"]
|
9
|
+
s.email = ["dave@bignerdranch.com"]
|
10
10
|
s.homepage = "https://github.com/mailchimp/mailchimp-gem"
|
11
11
|
s.summary = %q{Mailchimp APIs in Ruby}
|
12
12
|
s.description = %q{This provides Ruby access to (eventually) all of Mailchimp's APIs}
|
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
|
-
|
20
|
+
|
21
21
|
s.add_dependency('httparty')
|
22
|
-
|
22
|
+
|
23
23
|
s.add_development_dependency('ruby-debug19')
|
24
24
|
s.add_development_dependency('rake')
|
25
25
|
s.add_development_dependency('shoulda')
|
data/test/lib/api_test.rb
CHANGED
@@ -115,22 +115,26 @@ class ApiTest < Test::Unit::TestCase
|
|
115
115
|
@returns = Struct.new(:body).new(["array", "entries"].to_json)
|
116
116
|
end
|
117
117
|
|
118
|
-
should "throw exception if
|
119
|
-
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
|
118
|
+
should "not throw exception if the API replies with a JSON hash containing a key called 'error'" do
|
119
|
+
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '254'}.to_json))
|
120
120
|
assert_nothing_raised do
|
121
121
|
result = @api.say_hello
|
122
|
+
assert_equal 'bad things', result['error']
|
123
|
+
assert_equal '254', result['code']
|
122
124
|
end
|
123
|
-
|
124
|
-
ap result
|
125
125
|
end
|
126
126
|
|
127
127
|
should "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
128
128
|
@api.throws_exceptions = true
|
129
|
-
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
|
130
|
-
assert_raise
|
129
|
+
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '254'}.to_json))
|
130
|
+
e = assert_raise Mailchimp::APIError do
|
131
131
|
@api.say_hello
|
132
132
|
end
|
133
|
+
|
134
|
+
assert_equal 'bad things', e.error
|
135
|
+
assert_equal '254', e.code
|
133
136
|
end
|
137
|
+
|
134
138
|
should 'allow one to check api key validity' do
|
135
139
|
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new(%q{"Everything's Chimpy!"}.to_json))
|
136
140
|
assert_equal true, @api.valid_api_key?
|
data/test/lib/export_test.rb
CHANGED
@@ -21,23 +21,24 @@ class ExportTest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
should "not throw exception if the Export API replies with a JSON hash containing a key called 'error'" do
|
24
|
-
Mailchimp::Export.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
|
24
|
+
Mailchimp::Export.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '123'}.to_json))
|
25
25
|
|
26
26
|
assert_nothing_raised do
|
27
27
|
@api.say_hello(@body)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
should "throw exception if configured to and the Export API replies with a JSON hash containing a key called 'error'" do
|
32
32
|
@api.throws_exceptions = true
|
33
33
|
params = {:body => @body, :timeout => nil}
|
34
34
|
Mailchimp::Export.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '123'}.to_json))
|
35
35
|
|
36
|
-
assert_raise
|
36
|
+
e = assert_raise Mailchimp::APIError do
|
37
37
|
@api.say_hello(@body)
|
38
38
|
end
|
39
|
+
assert_equal 'bad things', e.error
|
40
|
+
assert_equal '123', e.code
|
39
41
|
end
|
40
|
-
=end
|
41
42
|
end
|
42
43
|
private
|
43
44
|
|
@@ -49,4 +50,4 @@ class ExportTest < Test::Unit::TestCase
|
|
49
50
|
end.returns(Struct.new(:body).new("") )
|
50
51
|
end
|
51
52
|
|
52
|
-
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailchimp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Kelly
|
9
|
+
- Dave Worth
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: httparty
|
16
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
@@ -21,10 +22,15 @@ dependencies:
|
|
21
22
|
version: '0'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
25
31
|
- !ruby/object:Gem::Dependency
|
26
32
|
name: ruby-debug19
|
27
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
28
34
|
none: false
|
29
35
|
requirements:
|
30
36
|
- - ! '>='
|
@@ -32,10 +38,15 @@ dependencies:
|
|
32
38
|
version: '0'
|
33
39
|
type: :development
|
34
40
|
prerelease: false
|
35
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rake
|
38
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,15 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
47
63
|
- !ruby/object:Gem::Dependency
|
48
64
|
name: shoulda
|
49
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
50
66
|
none: false
|
51
67
|
requirements:
|
52
68
|
- - ! '>='
|
@@ -54,10 +70,15 @@ dependencies:
|
|
54
70
|
version: '0'
|
55
71
|
type: :development
|
56
72
|
prerelease: false
|
57
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
58
79
|
- !ruby/object:Gem::Dependency
|
59
80
|
name: mocha
|
60
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
61
82
|
none: false
|
62
83
|
requirements:
|
63
84
|
- - ! '>='
|
@@ -65,10 +86,15 @@ dependencies:
|
|
65
86
|
version: '0'
|
66
87
|
type: :development
|
67
88
|
prerelease: false
|
68
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
69
95
|
- !ruby/object:Gem::Dependency
|
70
96
|
name: cover_me
|
71
|
-
requirement:
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
72
98
|
none: false
|
73
99
|
requirements:
|
74
100
|
- - ! '>='
|
@@ -76,10 +102,15 @@ dependencies:
|
|
76
102
|
version: '0'
|
77
103
|
type: :development
|
78
104
|
prerelease: false
|
79
|
-
version_requirements:
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
80
111
|
- !ruby/object:Gem::Dependency
|
81
112
|
name: fakeweb
|
82
|
-
requirement:
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
83
114
|
none: false
|
84
115
|
requirements:
|
85
116
|
- - ! '>='
|
@@ -87,10 +118,15 @@ dependencies:
|
|
87
118
|
version: '0'
|
88
119
|
type: :development
|
89
120
|
prerelease: false
|
90
|
-
version_requirements:
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
91
127
|
description: This provides Ruby access to (eventually) all of Mailchimp's APIs
|
92
128
|
email:
|
93
|
-
-
|
129
|
+
- dave@bignerdranch.com
|
94
130
|
executables: []
|
95
131
|
extensions: []
|
96
132
|
extra_rdoc_files: []
|
@@ -109,6 +145,7 @@ files:
|
|
109
145
|
- examples/sts_example.rb
|
110
146
|
- lib/mailchimp.rb
|
111
147
|
- lib/mailchimp/api.rb
|
148
|
+
- lib/mailchimp/api_error.rb
|
112
149
|
- lib/mailchimp/base.rb
|
113
150
|
- lib/mailchimp/export.rb
|
114
151
|
- lib/mailchimp/ext/httparty.rb
|
@@ -120,7 +157,6 @@ files:
|
|
120
157
|
- mailchimp.gemspec
|
121
158
|
- test/integration/api_test.rb
|
122
159
|
- test/integration/base_test.rb
|
123
|
-
- test/integration/export_test.rb
|
124
160
|
- test/integration/mandrill_test.rb
|
125
161
|
- test/integration/sts_test.rb
|
126
162
|
- test/lib/api_test.rb
|
@@ -150,14 +186,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
186
|
version: '0'
|
151
187
|
requirements: []
|
152
188
|
rubyforge_project: mailchimp
|
153
|
-
rubygems_version: 1.8.
|
189
|
+
rubygems_version: 1.8.25
|
154
190
|
signing_key:
|
155
191
|
specification_version: 3
|
156
192
|
summary: Mailchimp APIs in Ruby
|
157
193
|
test_files:
|
158
194
|
- test/integration/api_test.rb
|
159
195
|
- test/integration/base_test.rb
|
160
|
-
- test/integration/export_test.rb
|
161
196
|
- test/integration/mandrill_test.rb
|
162
197
|
- test/integration/sts_test.rb
|
163
198
|
- test/lib/api_test.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ExportIntegrationTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "send request List Data from the Mailchimp Export API" do
|
6
|
-
|
7
|
-
FakeWeb.register_uri(
|
8
|
-
:post,
|
9
|
-
'http://us2.api.mailchimp.com/export/1.0/list/',
|
10
|
-
body: '["Email Address","First Name","Last Name","Salesforce ID","EMAIL_TYPE","MEMBER_RATING","OPTIN_TIME","OPTIN_IP","CONFIRM_TIME","CONFIRM_IP","LATITUDE","LONGITUDE","GMTOFF","DSTOFF","TIMEZONE","CC","REGION","LAST_CHANGED"]
|
11
|
-
["highgroove@example.com","Daniel","Rice","00Qd0000005MKaEEAW","html",2,"2011-10-06 20:06:46","173.160.74.121","2011-10-06 20:07:28","173.160.74.121","33.7490000","-84.3880000","-5","-4","America\/Kentucky\/Monticello","US","GA","2012-03-12 17:45:18"]
|
12
|
-
["chimpy@example.com","Daniel","Rice","00Qd0000006AjjtEAC","html",2,"",null,"2012-03-08 20:52:31","173.160.74.121",null,null,null,null,null,null,null,"2012-03-12 17:45:20"]
|
13
|
-
["wolfbrain@example.com","George P","Burdell","00Qd0000006AjjuEAC","html",2,"",null,"2012-03-08 20:53:10","173.160.74.121",null,null,null,null,null,null,null,"2012-03-12 17:45:22"]'
|
14
|
-
)
|
15
|
-
|
16
|
-
m = Mailchimp::Export.new('abc123-us2')
|
17
|
-
response = m.list(:id => 'xxxxxxxx')
|
18
|
-
|
19
|
-
assert_kind_of Enumerator, response
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
should "get campaign subscriber activity" do
|
24
|
-
|
25
|
-
FakeWeb.register_uri(
|
26
|
-
:post,
|
27
|
-
'http://us2.api.mailchimp.com/export/1.0/campaignSubscriberActivity/',
|
28
|
-
body: '{"highgroove@example.com":[{"action":"open","timestamp":"2012-03-12 20:14:17","url":null,"ip":"184.77.22.196"}]} {"wolfbrain@example.com":[{"action":"open","timestamp":"2012-03-12 20:14:20","url":null,"ip":"184.77.22.196"}]}'.to_json
|
29
|
-
)
|
30
|
-
response = Mailchimp::Export.new('abc123-us2').campaign_subscriber_activity(:id => 'xxxxxxxx')
|
31
|
-
|
32
|
-
assert_kind_of Enumerator, response
|
33
|
-
end
|
34
|
-
end
|