mailchimp 0.0.5.alpha → 0.0.6.alpha
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 -0
- data/README-api.markdown +0 -5
- data/README-mandrill.markdown +0 -5
- data/README-sts.markdown +0 -5
- data/README.markdown +9 -0
- data/lib/mailchimp.rb +2 -0
- data/lib/mailchimp/api.rb +6 -31
- data/lib/mailchimp/base.rb +63 -0
- data/lib/mailchimp/export.rb +34 -0
- data/lib/mailchimp/mandrill.rb +18 -36
- data/lib/mailchimp/sts.rb +12 -31
- data/lib/mailchimp/version.rb +1 -1
- data/test/integration/api_test.rb +1 -1
- data/test/integration/base_test.rb +26 -0
- data/test/integration/mandrill_test.rb +1 -25
- data/test/integration/sts_test.rb +9 -0
- data/test/lib/api_test.rb +4 -44
- data/test/lib/base_test.rb +18 -0
- data/test/lib/export_test.rb +52 -0
- data/test/lib/mandrill_test.rb +0 -7
- metadata +24 -16
data/CONTRIBUTORS.markdown
CHANGED
data/README-api.markdown
CHANGED
@@ -59,11 +59,6 @@ or
|
|
59
59
|
|
60
60
|
email_stats = api.campaignEmailStatsAIM({:cid => campaign_id, :email_address => email_array})
|
61
61
|
|
62
|
-
### Other Stuff
|
63
|
-
|
64
|
-
API defaults to a 30 second timeout. You can optionally set your own timeout (in seconds) like so:
|
65
|
-
|
66
|
-
api.timeout = 5
|
67
62
|
|
68
63
|
### Export API usage
|
69
64
|
|
data/README-mandrill.markdown
CHANGED
@@ -62,8 +62,3 @@ You can tell ActionMailer to send mail using Mandrill by adding the follow to to
|
|
62
62
|
|
63
63
|
These setting will allow you to use ActionMailer as you normally would, any calls to mail() will be sent using Mandrill
|
64
64
|
|
65
|
-
### Other Stuff
|
66
|
-
|
67
|
-
Mandrill defaults to a 30 second timeout. You can optionally set your own timeout (in seconds) like so:
|
68
|
-
|
69
|
-
sts.timeout = 5
|
data/README-sts.markdown
CHANGED
@@ -63,8 +63,3 @@ If, for some reason, you want to use ActionMailer and change your tags dynamical
|
|
63
63
|
|
64
64
|
ActionMailer::Base.mailchimp_sts_settings[:tags] = ["dynamically", "set", "tags"]
|
65
65
|
|
66
|
-
### Other Stuff
|
67
|
-
|
68
|
-
STS defaults to a 30 second timeout. You can optionally set your own timeout (in seconds) like so:
|
69
|
-
|
70
|
-
sts.timeout = 5
|
data/README.markdown
CHANGED
@@ -45,6 +45,15 @@ Mailchimp API keys for them. run them like:
|
|
45
45
|
ruby examples/sts_example.rb
|
46
46
|
ruby examples/mandrill_example.rb
|
47
47
|
|
48
|
+
### Other Stuff
|
49
|
+
|
50
|
+
API calls default to a 30 second timeout. You can optionally set your own timeout (in seconds) like so:
|
51
|
+
|
52
|
+
api = Mailchimp::API.new("apikey", timeout: 60)
|
53
|
+
api.timeout = 5
|
54
|
+
api.listBatchSubscribe(list_id: "123", batch: [1..7000], timeout: 300) #per-request will override default
|
55
|
+
|
56
|
+
|
48
57
|
##Development
|
49
58
|
|
50
59
|
Write tests before you change anything, run tests before you commit anything:
|
data/lib/mailchimp.rb
CHANGED
@@ -4,10 +4,12 @@ require 'cgi'
|
|
4
4
|
|
5
5
|
require "mailchimp/ext/httparty"
|
6
6
|
|
7
|
+
require 'mailchimp/base'
|
7
8
|
require "mailchimp/version"
|
8
9
|
require "mailchimp/api"
|
9
10
|
require "mailchimp/sts"
|
10
11
|
require "mailchimp/mandrill"
|
12
|
+
require 'mailchimp/export'
|
11
13
|
|
12
14
|
module Mailchimp
|
13
15
|
end
|
data/lib/mailchimp/api.rb
CHANGED
@@ -17,20 +17,21 @@ module Mailchimp
|
|
17
17
|
@default_params = @default_params.merge({:apikey => @api_key})
|
18
18
|
end
|
19
19
|
|
20
|
-
def get_exporter
|
21
|
-
APIExport.new(@api_key, @default_params)
|
22
|
-
end
|
23
|
-
|
24
20
|
def base_api_url
|
25
21
|
"https://#{dc_from_api_key}api.mailchimp.com/1.3/?method="
|
26
22
|
end
|
23
|
+
|
24
|
+
def valid_api_key?(*args)
|
25
|
+
%q{"Everything's Chimpy!"} == call("#{base_api_url}ping")
|
26
|
+
end
|
27
27
|
|
28
28
|
protected
|
29
29
|
|
30
30
|
def call(method, params = {})
|
31
31
|
api_url = base_api_url + method
|
32
32
|
params = @default_params.merge(params)
|
33
|
-
|
33
|
+
timeout = params.delete(:timeout) || @timeout
|
34
|
+
response = self.class.post(api_url, :body => CGI::escape(params.to_json), :timeout => timeout)
|
34
35
|
|
35
36
|
begin
|
36
37
|
response = JSON.parse(response.body)
|
@@ -65,30 +66,4 @@ module Mailchimp
|
|
65
66
|
(@api_key.nil? || @api_key.length == 0 || @api_key !~ /-/) ? '' : "#{@api_key.split("-").last}."
|
66
67
|
end
|
67
68
|
end
|
68
|
-
|
69
|
-
class APIExport < API
|
70
|
-
def initialize(api_key = nil, extra_params = {})
|
71
|
-
super(api_key, extra_params)
|
72
|
-
end
|
73
|
-
|
74
|
-
protected
|
75
|
-
|
76
|
-
def export_api_url
|
77
|
-
"http://#{dc_from_api_key}api.mailchimp.com/export/1.0/"
|
78
|
-
end
|
79
|
-
|
80
|
-
def call(method, params = {})
|
81
|
-
api_url = export_api_url + method + "/"
|
82
|
-
params = @default_params.merge(params)
|
83
|
-
response = self.class.post(api_url, :body => params, :timeout => @timeout)
|
84
|
-
|
85
|
-
lines = response.body.lines
|
86
|
-
if @throws_exceptions
|
87
|
-
first_line_object = JSON.parse(lines.first) if lines.first
|
88
|
-
raise "Error from MailChimp Export API: #{first_line_object["error"]} (code #{first_line_object["code"]})" if first_line_object.is_a?(Hash) && first_line_object["error"]
|
89
|
-
end
|
90
|
-
|
91
|
-
lines
|
92
|
-
end
|
93
|
-
end
|
94
69
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Mailchimp
|
2
|
+
def self.valid_api_key?(api_key)
|
3
|
+
Base.new(api_key).valid_api_key?
|
4
|
+
end
|
5
|
+
class Base
|
6
|
+
include HTTParty
|
7
|
+
default_timeout 30
|
8
|
+
|
9
|
+
attr_accessor :api_key, :timeout, :options
|
10
|
+
|
11
|
+
def initialize(api_key = nil, default_parameters = {})
|
12
|
+
@api_key = api_key || ENV['MAILCHIMP_API_KEY'] || nil
|
13
|
+
@timeout = default_parameters.delete(:timeout)
|
14
|
+
@default_params = default_parameters
|
15
|
+
end
|
16
|
+
|
17
|
+
def dc_from_api_key
|
18
|
+
(@api_key.nil? || @api_key.length == 0 || @api_key !~ /-/) ? '' : "#{@api_key.split("-").last}."
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_api_key?
|
22
|
+
%q{"Everything's Chimpy!"} == self.class.post(_base_api_url+"ping", :body => {apikey: @api_key}, :timeout => 30).body
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_accessor :api_key
|
27
|
+
|
28
|
+
def method_missing(sym, *args, &block)
|
29
|
+
self.api_key = args[0] if sym == :valid_api_key?
|
30
|
+
new(self.api_key).send(sym, *args, &block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def call(url, params = {})
|
37
|
+
params = @default_params.merge(params)
|
38
|
+
timeout = params.delete(:timeout) || @timeout
|
39
|
+
response = self.class.post(url, :body => params, :timeout => timeout)
|
40
|
+
begin; response = JSON.parse(response.body); rescue; response = response.body ;end
|
41
|
+
if @throws_exceptions && response.is_a?(Hash) && response["error"]
|
42
|
+
raise "Error from MailChimp API: #{response["error"]} (code #{response["code"]})"
|
43
|
+
end
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
def method_missing(method, *args)
|
48
|
+
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails
|
49
|
+
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM')
|
50
|
+
args = {} unless args.length > 0
|
51
|
+
args = args[0] if args.is_a?(Array)
|
52
|
+
call(method, args)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def _base_api_url
|
58
|
+
"https://#{dc_from_api_key}api.mailchimp.com/1.3/?method="
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mailchimp
|
2
|
+
class Export < Base
|
3
|
+
def initialize(api_key = nil, default_parameters = {})
|
4
|
+
super(api_key, {:apikey => api_key}.merge(default_parameters))
|
5
|
+
end
|
6
|
+
|
7
|
+
def export_api_url
|
8
|
+
"http://#{dc_from_api_key}api.mailchimp.com/export/1.0/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(method, params = {})
|
12
|
+
api_url = export_api_url + method + "/"
|
13
|
+
params = @default_params.merge(params)
|
14
|
+
timeout = params.delete(:timeout) || @timeout
|
15
|
+
response = self.class.post(api_url, :body => params, :timeout => timeout)
|
16
|
+
|
17
|
+
lines = response.body.lines
|
18
|
+
if @throws_exceptions
|
19
|
+
first_line_object = JSON.parse(lines.first) if lines.first
|
20
|
+
raise "Error from MailChimp Export API: #{first_line_object["error"]} (code #{first_line_object["code"]})" if first_line_object.is_a?(Hash) && first_line_object["error"]
|
21
|
+
end
|
22
|
+
|
23
|
+
lines
|
24
|
+
end
|
25
|
+
class << self
|
26
|
+
attr_accessor :api_key
|
27
|
+
|
28
|
+
def method_missing(sym, *args, &block)
|
29
|
+
new(self.api_key).send(sym, *args, &block)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/mailchimp/mandrill.rb
CHANGED
@@ -3,46 +3,27 @@ if defined?(ActionMailer)
|
|
3
3
|
end
|
4
4
|
|
5
5
|
module Mailchimp
|
6
|
-
class Mandrill
|
7
|
-
include HTTParty
|
6
|
+
class Mandrill < Base
|
8
7
|
parser MailchimpPsuedoJSONParser
|
9
|
-
default_timeout 30
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@api_key = api_key || ENV['MAILCHIMP_API_KEY'] || self.class.api_key
|
15
|
-
@default_params = {
|
16
|
-
:key => @api_key,
|
9
|
+
def initialize(api_key = nil, default_parameters = {})
|
10
|
+
super(api_key, {
|
11
|
+
:key => api_key,
|
17
12
|
:options => {
|
18
13
|
:track_opens => true,
|
19
14
|
:track_clicks => true
|
20
15
|
}
|
21
|
-
}.merge(
|
22
|
-
end
|
23
|
-
|
24
|
-
def api_key=(value)
|
25
|
-
@api_key = value
|
26
|
-
@default_params = @default_params.merge({:key => @api_key})
|
16
|
+
}.merge(default_parameters))
|
27
17
|
end
|
28
|
-
|
29
|
-
def
|
30
|
-
"
|
18
|
+
|
19
|
+
def valid_api_key?(*args)
|
20
|
+
'"PONG!"' == self.users_ping
|
31
21
|
end
|
32
|
-
|
22
|
+
|
33
23
|
def call(method, params = {})
|
34
|
-
|
35
|
-
params = @default_params.merge(params)
|
36
|
-
response = self.class.post(url, :body => params, :timeout => @timeout)
|
37
|
-
|
38
|
-
begin
|
39
|
-
response = JSON.parse(response.body)
|
40
|
-
rescue
|
41
|
-
response = response.body
|
42
|
-
end
|
43
|
-
response
|
24
|
+
super("#{base_api_url}#{method}",@default_params.merge(params))
|
44
25
|
end
|
45
|
-
|
26
|
+
|
46
27
|
def method_missing(method, *args)
|
47
28
|
match = method.to_s.match(/([a-z]*)_([a-z]*)_?([a-z]*)/)
|
48
29
|
method = "#{match[1]}/#{match[2]}#{match[3] == '' ? "" : "-"+match[3]}"
|
@@ -50,19 +31,20 @@ module Mailchimp
|
|
50
31
|
args = args[0] if (args.class.to_s == "Array")
|
51
32
|
call(method, args)
|
52
33
|
end
|
53
|
-
|
54
|
-
def valid_api_key?(*args)
|
55
|
-
puts args.inspect
|
56
|
-
'"PONG!"' == self.users_ping
|
57
|
-
end
|
34
|
+
|
58
35
|
|
59
36
|
class << self
|
60
37
|
attr_accessor :api_key
|
61
38
|
|
62
39
|
def method_missing(sym, *args, &block)
|
63
|
-
self.api_key = args[0] if sym == :valid_api_key?
|
64
40
|
new(self.api_key).send(sym, *args, &block)
|
65
41
|
end
|
66
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def base_api_url
|
47
|
+
"http://mandrillapp.com/api/1.0/"
|
48
|
+
end
|
67
49
|
end
|
68
50
|
end
|
data/lib/mailchimp/sts.rb
CHANGED
@@ -3,44 +3,19 @@ if defined?(ActionMailer)
|
|
3
3
|
end
|
4
4
|
|
5
5
|
module Mailchimp
|
6
|
-
class STS
|
7
|
-
include HTTParty
|
8
|
-
default_timeout 30
|
9
|
-
|
10
|
-
attr_accessor :api_key, :timeout, :options
|
11
|
-
|
6
|
+
class STS < Base
|
12
7
|
def initialize(api_key = nil, extra_params = {})
|
13
|
-
|
14
|
-
|
15
|
-
:apikey => @api_key,
|
8
|
+
super(api_key,{
|
9
|
+
:apikey => api_key,
|
16
10
|
:options => {
|
17
11
|
:track_opens => true,
|
18
12
|
:track_clicks => true
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def api_key=(value)
|
24
|
-
@api_key = value
|
25
|
-
@default_params = @default_params.merge({:apikey => @api_key})
|
26
|
-
end
|
27
|
-
|
28
|
-
def base_api_url
|
29
|
-
dc = (@api_key == '' || @api_key == nil) ? '' : "#{@api_key.split("-").last}."
|
30
|
-
"https://#{dc}sts.mailchimp.com/1.0/"
|
13
|
+
}
|
14
|
+
}.merge(extra_params))
|
31
15
|
end
|
32
16
|
|
33
17
|
def call(method, params = {})
|
34
|
-
|
35
|
-
params = @default_params.merge(params)
|
36
|
-
response = self.class.post(url, :body => params, :timeout => @timeout)
|
37
|
-
|
38
|
-
begin
|
39
|
-
response = JSON.parse(response.body)
|
40
|
-
rescue
|
41
|
-
response = response.body
|
42
|
-
end
|
43
|
-
response
|
18
|
+
super("#{base_api_url}#{method}",params.merge({:apikey => @api_key}))
|
44
19
|
end
|
45
20
|
|
46
21
|
def method_missing(method, *args)
|
@@ -57,5 +32,11 @@ module Mailchimp
|
|
57
32
|
new(self.api_key).send(sym, *args, &block)
|
58
33
|
end
|
59
34
|
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def base_api_url
|
39
|
+
"https://#{dc_from_api_key}sts.mailchimp.com/1.0/"
|
40
|
+
end
|
60
41
|
end
|
61
42
|
end
|
data/lib/mailchimp/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BaseIntegrationTest < Test::Unit::TestCase
|
4
|
+
context 'utility methods' do
|
5
|
+
setup do
|
6
|
+
FakeWeb.register_uri(
|
7
|
+
:post,
|
8
|
+
'http://us1.api.mailchimip.com/api/1.3?method=ping',
|
9
|
+
body: %q{"Everything's Chimpy!"}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "know valid api key" do
|
14
|
+
m = Mailchimp::Base.new('abc123-us1')
|
15
|
+
assert_equal true, m.valid_api_key?
|
16
|
+
assert_equal true, Mailchimp.valid_api_key?('abc123-us1')
|
17
|
+
end
|
18
|
+
|
19
|
+
should "know invalid api key" do
|
20
|
+
m = Mailchimp::Base.new('abc123-us1')
|
21
|
+
assert_equal false, !m.valid_api_key?
|
22
|
+
assert_equal false, !Mailchimp.valid_api_key?('abc123-us1')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class MandrillIntegrationTest < Test::Unit::TestCase
|
4
|
-
|
5
4
|
should "send request to Mandrill API" do
|
6
5
|
FakeWeb.register_uri(
|
7
6
|
:post,
|
@@ -12,31 +11,8 @@ class MandrillIntegrationTest < Test::Unit::TestCase
|
|
12
11
|
|
13
12
|
m = Mailchimp::Mandrill.new('abc123-us1')
|
14
13
|
assert_equal '"PONG!"', m.users_ping
|
14
|
+
assert_equal true, m.valid_api_key?
|
15
15
|
assert_equal expected_request, URI::decode(FakeWeb.last_request.body)
|
16
16
|
end
|
17
|
-
|
18
|
-
should "know valid api key" do
|
19
|
-
FakeWeb.register_uri(
|
20
|
-
:post,
|
21
|
-
'http://mandrillapp.com/api/1.0/users/ping',
|
22
|
-
body: '"PONG!"'
|
23
|
-
)
|
24
|
-
|
25
|
-
m = Mailchimp::Mandrill.new('abc123-us1')
|
26
|
-
assert m.valid_api_key?
|
27
|
-
assert Mailchimp::Mandrill.valid_api_key?('abc123-us1')
|
28
|
-
end
|
29
|
-
|
30
|
-
should "know invalid api key" do
|
31
|
-
FakeWeb.register_uri(
|
32
|
-
:post,
|
33
|
-
'http://mandrillapp.com/api/1.0/users/ping',
|
34
|
-
body: '{"status":"error","code":0,"name":"Exception","message":"Invalid API Key"}'
|
35
|
-
)
|
36
|
-
|
37
|
-
m = Mailchimp::Mandrill.new('abc123-us1')
|
38
|
-
assert !m.valid_api_key?
|
39
|
-
assert !Mailchimp::Mandrill.valid_api_key?('abc123-us1')
|
40
|
-
end
|
41
17
|
|
42
18
|
end
|
@@ -14,5 +14,14 @@ class STSIntegrationTest < Test::Unit::TestCase
|
|
14
14
|
assert_equal "Everything's Chimpy!", m.ping
|
15
15
|
assert_equal expected_request, URI::decode(FakeWeb.last_request.body)
|
16
16
|
end
|
17
|
+
should 'use the regular API for checking key validity' do
|
18
|
+
FakeWeb.register_uri(
|
19
|
+
:post,
|
20
|
+
'https://us1.api.mailchimp.com/1.3/?method=ping',
|
21
|
+
body: %q{"Everything's Chimpy!"}
|
22
|
+
)
|
23
|
+
assert_equal true, Mailchimp::STS.new('abc123-us1').valid_api_key?
|
24
|
+
|
25
|
+
end
|
17
26
|
|
18
27
|
end
|
data/test/lib/api_test.rb
CHANGED
@@ -115,11 +115,6 @@ class ApiTest < Test::Unit::TestCase
|
|
115
115
|
@returns = Struct.new(:body).new(["array", "entries"].to_json)
|
116
116
|
end
|
117
117
|
|
118
|
-
should "produce a good exporter" do
|
119
|
-
@exporter = @api.get_exporter
|
120
|
-
assert_equal(@exporter.api_key, @api.api_key)
|
121
|
-
end
|
122
|
-
|
123
118
|
should "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
124
119
|
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
|
125
120
|
assert_nothing_raised do
|
@@ -136,48 +131,13 @@ class ApiTest < Test::Unit::TestCase
|
|
136
131
|
@api.say_hello
|
137
132
|
end
|
138
133
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
setup do
|
143
|
-
@key = "TESTKEY-us1"
|
144
|
-
@api = Mailchimp::APIExport.new(@key)
|
145
|
-
@url = "http://us1.api.mailchimp.com/export/1.0/"
|
146
|
-
@body = {:apikey => @key, :id => "listid"}
|
147
|
-
@returns = Struct.new(:body).new(["array", "entries"].to_json)
|
148
|
-
end
|
149
|
-
|
150
|
-
should "handle api key with dc" do
|
151
|
-
@api_key = "TESTKEY-us2"
|
152
|
-
@api = Mailchimp::APIExport.new(@api_key)
|
153
|
-
|
154
|
-
params = {:body => @body, :timeout => nil}
|
155
|
-
|
156
|
-
url = @url.gsub('us1', 'us2') + "sayHello/"
|
157
|
-
Mailchimp::APIExport.expects(:post).with(url, params).returns(@returns)
|
158
|
-
@api.say_hello(@body)
|
159
|
-
end
|
160
|
-
|
161
|
-
should "not throw exception if the Export API replies with a JSON hash containing a key called 'error'" do
|
162
|
-
Mailchimp::APIExport.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
|
163
|
-
|
164
|
-
assert_nothing_raised do
|
165
|
-
@api.say_hello(@body)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
should "throw exception if configured to and the Export API replies with a JSON hash containing a key called 'error'" do
|
170
|
-
@api.throws_exceptions = true
|
171
|
-
params = {:body => @body, :timeout => nil}
|
172
|
-
Mailchimp::APIExport.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '123'}.to_json))
|
173
|
-
|
174
|
-
assert_raise RuntimeError do
|
175
|
-
@api.say_hello(@body)
|
176
|
-
end
|
134
|
+
should 'allow one to check api key validity' do
|
135
|
+
Mailchimp::API.stubs(:post).returns(Struct.new(:body).new(%q{"Everything's Chimpy!"}.to_json))
|
136
|
+
assert_equal true, @api.valid_api_key?
|
177
137
|
end
|
178
|
-
|
179
138
|
end
|
180
139
|
|
140
|
+
|
181
141
|
private
|
182
142
|
|
183
143
|
def expect_post(expected_url, expected_body, expected_timeout=nil)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class BaseTest < Test::Unit::TestCase
|
5
|
+
context 'instance vars/methods' do
|
6
|
+
should 'set timeout in constructor' do
|
7
|
+
@api = Mailchimp::Base.new(@api_key, :timeout => 65)
|
8
|
+
assert_equal(65,@api.timeout)
|
9
|
+
end
|
10
|
+
=begin #pending throws_exceptions decision
|
11
|
+
should 'set throws_exceptions in constructor' do
|
12
|
+
@api = Mailchimp::API.new(@api_key, :throws_exceptions => true)
|
13
|
+
assert_equal(true,@api.throws_exceptions)
|
14
|
+
end
|
15
|
+
=end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ExportTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "export API" do
|
6
|
+
setup do
|
7
|
+
@key = "TESTKEY-us1"
|
8
|
+
@api = Mailchimp::Export.new(@key)
|
9
|
+
@url = "http://us1.api.mailchimp.com/export/1.0/list/"
|
10
|
+
@body = {:apikey => @key, :id => "listid"}
|
11
|
+
@returns = Struct.new(:body).new(["array", "entries"].to_json)
|
12
|
+
end
|
13
|
+
should 'allow timeout option through constructor' do
|
14
|
+
@api = Mailchimp::Export.new(@key, :timeout => 200)
|
15
|
+
expect_post(@url, @body, 200)
|
16
|
+
@api.list(:id => "listid")
|
17
|
+
end
|
18
|
+
should 'allow timeout option through params' do
|
19
|
+
expect_post(@url, @body, 180)
|
20
|
+
@api.list(:id => "listid", :timeout => 180)
|
21
|
+
end
|
22
|
+
|
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))
|
25
|
+
|
26
|
+
assert_nothing_raised do
|
27
|
+
@api.say_hello(@body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
=begin #pending throw exception decision
|
31
|
+
should "throw exception if configured to and the Export API replies with a JSON hash containing a key called 'error'" do
|
32
|
+
@api.throws_exceptions = true
|
33
|
+
params = {:body => @body, :timeout => nil}
|
34
|
+
Mailchimp::Export.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '123'}.to_json))
|
35
|
+
|
36
|
+
assert_raise RuntimeError do
|
37
|
+
@api.say_hello(@body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
=end
|
41
|
+
end
|
42
|
+
private
|
43
|
+
|
44
|
+
def expect_post(expected_url, expected_body, expected_timeout=nil)
|
45
|
+
Mailchimp::Export.expects(:post).with do |url, opts|
|
46
|
+
url == expected_url &&
|
47
|
+
opts[:body] == expected_body &&
|
48
|
+
opts[:timeout] == expected_timeout
|
49
|
+
end.returns(Struct.new(:body).new("") )
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/test/lib/mandrill_test.rb
CHANGED
@@ -50,13 +50,6 @@ class MandrillTest < Test::Unit::TestCase
|
|
50
50
|
expect_post(@url, DEFAULT_OPTIONS.merge(:key => nil))
|
51
51
|
@api.users_ping
|
52
52
|
end
|
53
|
-
|
54
|
-
should "handle malformed api key" do
|
55
|
-
@api_key = "123"
|
56
|
-
@api.api_key = @api_key
|
57
|
-
expect_post(@url, DEFAULT_OPTIONS.merge(:key => @api_key))
|
58
|
-
@api.users_ping
|
59
|
-
end
|
60
53
|
|
61
54
|
should "handle timeout" do
|
62
55
|
expect_post(@url, DEFAULT_OPTIONS.merge(:key => nil), 120)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6.alpha
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70206693975680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70206693975680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-debug19
|
27
|
-
requirement: &
|
27
|
+
requirement: &70206693975260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70206693975260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70206693974820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70206693974820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shoulda
|
49
|
-
requirement: &
|
49
|
+
requirement: &70206693974400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70206693974400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70206693973940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70206693973940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: cover_me
|
71
|
-
requirement: &
|
71
|
+
requirement: &70206693973480 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70206693973480
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: fakeweb
|
82
|
-
requirement: &
|
82
|
+
requirement: &70206693973020 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70206693973020
|
91
91
|
description: This provides Ruby access to (eventually) all of Mailchimp's APIs
|
92
92
|
email:
|
93
93
|
- chris@highgroove.com
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- examples/sts_example.rb
|
110
110
|
- lib/mailchimp.rb
|
111
111
|
- lib/mailchimp/api.rb
|
112
|
+
- lib/mailchimp/base.rb
|
113
|
+
- lib/mailchimp/export.rb
|
112
114
|
- lib/mailchimp/ext/httparty.rb
|
113
115
|
- lib/mailchimp/handlers/mandrill_delivery_handler.rb
|
114
116
|
- lib/mailchimp/handlers/sts_delivery_handler.rb
|
@@ -117,9 +119,12 @@ files:
|
|
117
119
|
- lib/mailchimp/version.rb
|
118
120
|
- mailchimp.gemspec
|
119
121
|
- test/integration/api_test.rb
|
122
|
+
- test/integration/base_test.rb
|
120
123
|
- test/integration/mandrill_test.rb
|
121
124
|
- test/integration/sts_test.rb
|
122
125
|
- test/lib/api_test.rb
|
126
|
+
- test/lib/base_test.rb
|
127
|
+
- test/lib/export_test.rb
|
123
128
|
- test/lib/mandrill_test.rb
|
124
129
|
- test/lib/sts_test.rb
|
125
130
|
- test/test_helper.rb
|
@@ -149,9 +154,12 @@ specification_version: 3
|
|
149
154
|
summary: Mailchimp APIs in Ruby
|
150
155
|
test_files:
|
151
156
|
- test/integration/api_test.rb
|
157
|
+
- test/integration/base_test.rb
|
152
158
|
- test/integration/mandrill_test.rb
|
153
159
|
- test/integration/sts_test.rb
|
154
160
|
- test/lib/api_test.rb
|
161
|
+
- test/lib/base_test.rb
|
162
|
+
- test/lib/export_test.rb
|
155
163
|
- test/lib/mandrill_test.rb
|
156
164
|
- test/lib/sts_test.rb
|
157
165
|
- test/test_helper.rb
|