gibbon 1.0.4 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gibbon might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +1 -1
- data/README.markdown +29 -11
- data/gibbon.gemspec +2 -2
- data/lib/gibbon/api.rb +4 -0
- data/lib/gibbon/api_category.rb +3 -2
- data/lib/gibbon/export.rb +5 -1
- data/spec/gibbon/gibbon_spec.rb +24 -10
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34d4b58a97f16a89c75bf58613f549aa65254a06
|
4
|
+
data.tar.gz: e8daf0d12e8f4d180eece626ad64a0740a1a2fb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b627afea51e05ed36a958982ce2e0cdfab1f8abc013e36dc12850da2c8d05fb37218fa44d90dd97864e9e0daa182ee4c3bb68d704e04f2e46f65929348fbdc8
|
7
|
+
data.tar.gz: 4b9c3d6718612ba070dd15d156794fde5324d6b9c2717e02e3f5315f519710be6f65f8d0f85c0fd4c33725396bce2f0d2e94fc73dffdce866f58f1153a60f672
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
Gibbon is an API wrapper for MailChimp's [Primary and Export APIs](http://www.mailchimp.com/api).
|
4
4
|
|
5
5
|
[![Build Status](https://secure.travis-ci.org/amro/gibbon.png)](http://travis-ci.org/amro/gibbon)
|
6
|
-
|
7
|
-
##Important Notes
|
8
|
-
### (It's different!)
|
6
|
+
[![Dependency Status](https://gemnasium.com/amro/gibbon.png)](https://gemnasium.com/amro/gibbon)
|
7
|
+
##Important Notes
|
9
8
|
|
10
9
|
Gibbon now targets MailChimp API 2.0, which is substantially different from API 1.3. Please use Gibbon 0.4.6 if you need to use API 1.3.
|
11
10
|
|
@@ -80,7 +79,7 @@ Or, to fetch a list by name:
|
|
80
79
|
|
81
80
|
Getting batch member information for subscribers looks like this:
|
82
81
|
|
83
|
-
info = gb.lists.member_info({:id => list_id, :emails =>
|
82
|
+
info = gb.lists.member_info({:id => list_id, :emails => [{:email => email_1}, {:email => email_2}]})
|
84
83
|
|
85
84
|
List subscribers for a list:
|
86
85
|
|
@@ -102,16 +101,22 @@ or
|
|
102
101
|
|
103
102
|
Batch subscribe members to a list:
|
104
103
|
|
105
|
-
gb.lists.batch_subscribe(:id => list_id, :batch => [{:
|
104
|
+
gb.lists.batch_subscribe(:id => list_id, :batch => [{:email => {:email => "email1"}, :merge_vars => {:FNAME => "FirstName1", :LNAME => "LastName1"}},{:email => {:email =>"email2"}, :merge_vars => {:FNAME => "FirstName2", :LNAME => "LastName2"}}])
|
106
105
|
|
107
106
|
> Note: This will send welcome emails to the new subscribers
|
108
107
|
|
109
108
|
If you want to update the existing members you need to send the boolean update_existing in true
|
110
109
|
|
111
|
-
gb.lists.batch_subscribe(:id => list_id, :batch => [{:
|
110
|
+
gb.lists.batch_subscribe(:id => list_id, :batch => [{:email => {:email => "email1"}, :merge_vars => {:FNAME => "FirstName1", :LNAME => "LastName1"}}], :update_existing => true)
|
112
111
|
|
113
|
-
>
|
112
|
+
> Note: The `email` hash can also accept either a unique email id or a list email id. Please see the [lists/batch-subscribe](http://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php) documentation for more information.
|
113
|
+
|
114
|
+
You can also unsubscribe a member from a list:
|
114
115
|
|
116
|
+
gb.lists.unsubscribe(:id => list_id, :email => {:email => "user_email"}, :delete_member => true, :send_notify => true)
|
117
|
+
|
118
|
+
> Note: :delete_member defaults to false, meaning the member stays on your mailchimp list as "unsubscribed". See [Api Docs](http://apidocs.mailchimp.com/api/2.0/lists/unsubscribe.php) for details of options.
|
119
|
+
|
115
120
|
Fetch recipients who opened particular campaign:
|
116
121
|
|
117
122
|
email_stats = gb.reports.opened({:cid => campaign_id})
|
@@ -148,7 +153,20 @@ information about the error, and "code", the numeric code of the error.
|
|
148
153
|
|
149
154
|
If you rescue Gibbon::MailChimpError, you are provided with the error message itself as well as
|
150
155
|
a `code` attribute that you can map onto the API's error list. The API docs list possible errors
|
151
|
-
at the bottom of each page.
|
156
|
+
at the bottom of each page. Here's how you might do that:
|
157
|
+
|
158
|
+
begin
|
159
|
+
g.lists.subscribe(...)
|
160
|
+
rescue Gibbon::MailChimpError => e
|
161
|
+
# do something with e.message here
|
162
|
+
# do something wiht e.code here
|
163
|
+
end
|
164
|
+
|
165
|
+
Some API endpoints, like `[lists/batch-subscribe](http://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php)`
|
166
|
+
return errors to let you know that some of your actions failed, but some suceeded. Gibbon will not
|
167
|
+
raise Gibbon::MailChimpError for these endpoints because the key for the success count varies from endpoint to endpoint.
|
168
|
+
This makes it difficult to determine whether all of your actions failed in a generic way. **Because of this, you're responsible
|
169
|
+
for checking the response body for the `errors` array in these cases.**
|
152
170
|
|
153
171
|
> Note: In an effort to make Gibbon easier to use, errors are raised automatically as of version 0.4.0.
|
154
172
|
|
@@ -174,9 +192,9 @@ For example, dumping list members via the "list" method works like this:
|
|
174
192
|
|
175
193
|
##Thanks
|
176
194
|
|
177
|
-
Thanks to everyone who's [contributed](https://github.com/amro/gibbon/contributors) to Gibbon's development. Major props to
|
195
|
+
Thanks to everyone who's [contributed](https://github.com/amro/gibbon/contributors) to Gibbon's development. Major props to The Viking for making MailChimp API 2.0 great.
|
178
196
|
|
179
197
|
##Copyright
|
180
198
|
|
181
|
-
* Copyright (c) 2010-
|
182
|
-
* MailChimp (c) 2001-
|
199
|
+
* Copyright (c) 2010-2014 Amro Mousa. See LICENSE.txt for details.
|
200
|
+
* MailChimp (c) 2001-2014 The Rocket Science Group.
|
data/gibbon.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "gibbon"
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.1.1"
|
7
7
|
s.authors = ["Amro Mousa"]
|
8
8
|
s.email = ["amromousa@gmail.com"]
|
9
9
|
s.homepage = "http://github.com/amro/gibbon"
|
@@ -26,6 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency('multi_json', '>= 1.3.4')
|
27
27
|
|
28
28
|
s.add_development_dependency 'rake'
|
29
|
-
s.add_development_dependency "rspec", "
|
29
|
+
s.add_development_dependency "rspec", ">= 2.14.1"
|
30
30
|
|
31
31
|
end
|
data/lib/gibbon/api.rb
CHANGED
@@ -23,6 +23,10 @@ module Gibbon
|
|
23
23
|
api
|
24
24
|
end
|
25
25
|
|
26
|
+
def respond_to_missing?(method, include_private = false)
|
27
|
+
%w{campaigns ecomm folders gallery lists helper reports templates users vip}.include?(method.to_s) || super
|
28
|
+
end
|
29
|
+
|
26
30
|
class << self
|
27
31
|
attr_accessor :api_key, :timeout, :throws_exceptions, :api_endpoint
|
28
32
|
|
data/lib/gibbon/api_category.rb
CHANGED
@@ -22,7 +22,8 @@ module Gibbon
|
|
22
22
|
def call(method, params = {})
|
23
23
|
api_url = base_api_url + method
|
24
24
|
params = @default_params.merge(params).merge({:apikey => @api_key})
|
25
|
-
|
25
|
+
headers = params.delete(:headers) || {}
|
26
|
+
response = self.class.post(api_url, :body => MultiJson.dump(params), :headers => headers, :timeout => @timeout)
|
26
27
|
|
27
28
|
parsed_response = nil
|
28
29
|
|
@@ -30,7 +31,7 @@ module Gibbon
|
|
30
31
|
parsed_response = MultiJson.load(response.body)
|
31
32
|
|
32
33
|
if should_raise_for_response?(parsed_response)
|
33
|
-
error = MailChimpError.new(
|
34
|
+
error = MailChimpError.new(parsed_response["error"])
|
34
35
|
error.code = parsed_response["code"]
|
35
36
|
raise error
|
36
37
|
end
|
data/lib/gibbon/export.rb
CHANGED
@@ -24,7 +24,7 @@ module Gibbon
|
|
24
24
|
first_line = MultiJson.load(lines.first) if lines.first
|
25
25
|
|
26
26
|
if should_raise_for_response?(first_line)
|
27
|
-
error = MailChimpError.new(
|
27
|
+
error = MailChimpError.new(first_line["error"])
|
28
28
|
error.code = first_line["code"]
|
29
29
|
raise error
|
30
30
|
end
|
@@ -53,6 +53,10 @@ module Gibbon
|
|
53
53
|
call(method, *args)
|
54
54
|
end
|
55
55
|
|
56
|
+
def respond_to_missing?(method, include_private = false)
|
57
|
+
%w{list ecommOrders ecomm_orders campaignSubscriberActivity campaign_subscriber_activity}.include?(method.to_s) || super
|
58
|
+
end
|
59
|
+
|
56
60
|
class << self
|
57
61
|
attr_accessor :api_key, :timeout, :throws_exceptions
|
58
62
|
|
data/spec/gibbon/gibbon_spec.rb
CHANGED
@@ -158,6 +158,19 @@ describe Gibbon do
|
|
158
158
|
expect_post(@url, @body.merge("fee" => 99))
|
159
159
|
@gibbon.say.hello(:fee => 99)
|
160
160
|
end
|
161
|
+
|
162
|
+
it "pass through http header settings" do
|
163
|
+
@gibbon.timeout=30
|
164
|
+
expect_post(@url, @body.merge("messages" => 'Simon says'), @gibbon.timeout, {'Accept-Language' => 'en'})
|
165
|
+
@gibbon.say.hello(:messages => 'Simon says', :headers => {'Accept-Language' => 'en'} )
|
166
|
+
end
|
167
|
+
|
168
|
+
it "with http headers not set" do
|
169
|
+
@gibbon.timeout=30
|
170
|
+
expect_post(@url, @body.merge("messages" => 'Simon says'), @gibbon.timeout, {})
|
171
|
+
@gibbon.say.hello(:messages => 'Simon says' )
|
172
|
+
end
|
173
|
+
|
161
174
|
end
|
162
175
|
|
163
176
|
describe "Gibbon instances" do
|
@@ -176,24 +189,24 @@ describe Gibbon do
|
|
176
189
|
|
177
190
|
it "not throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
178
191
|
@gibbon.throws_exceptions = false
|
179
|
-
Gibbon::APICategory.
|
192
|
+
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
|
180
193
|
|
181
194
|
@gibbon.say.hello
|
182
195
|
end
|
183
196
|
|
184
197
|
it "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
185
198
|
@gibbon.throws_exceptions = true
|
186
|
-
Gibbon::APICategory.
|
199
|
+
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
|
187
200
|
expect {@gibbon.say.hello}.to raise_error(Gibbon::MailChimpError)
|
188
201
|
end
|
189
202
|
|
190
203
|
it "not raise exception if the api returns no response body" do
|
191
|
-
Gibbon::APICategory.
|
204
|
+
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new(nil))
|
192
205
|
expect(@gibbon.say.hello).to be_nil
|
193
206
|
end
|
194
207
|
|
195
208
|
it "can send a campaign" do
|
196
|
-
Gibbon::APICategory.
|
209
|
+
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new(MultiJson.dump({"cid" => "1234567"})))
|
197
210
|
expect(@gibbon.campaigns.send({"cid" => "1234567"})).to eq({"cid" => "1234567"})
|
198
211
|
end
|
199
212
|
end
|
@@ -215,13 +228,13 @@ describe Gibbon do
|
|
215
228
|
params = {:body => MultiJson.dump(@body), :timeout => 30}
|
216
229
|
|
217
230
|
url = @url.gsub('us1', 'us2') + "sayHello/"
|
218
|
-
Gibbon::Export.
|
231
|
+
expect(Gibbon::Export).to receive(:post).with(url, params).and_return(@returns)
|
219
232
|
@gibbon.say_hello(@body)
|
220
233
|
end
|
221
234
|
|
222
235
|
it "not throw exception if the Export API replies with a JSON hash containing a key called 'error'" do
|
223
236
|
@gibbon.throws_exceptions = false
|
224
|
-
Gibbon::Export.
|
237
|
+
allow(Gibbon::Export).to receive(:post).and_return(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
|
225
238
|
|
226
239
|
@gibbon.say_hello(@body)
|
227
240
|
end
|
@@ -230,7 +243,7 @@ describe Gibbon do
|
|
230
243
|
@gibbon.throws_exceptions = true
|
231
244
|
params = {:body => @body, :timeout => 30}
|
232
245
|
reply = Struct.new(:body).new MultiJson.dump({'error' => 'bad things', 'code' => '123'})
|
233
|
-
Gibbon::Export.
|
246
|
+
allow(Gibbon::Export).to receive(:post).and_return reply
|
234
247
|
|
235
248
|
expect {@gibbon.say_hello(@body)}.to raise_error(Gibbon::MailChimpError)
|
236
249
|
end
|
@@ -239,12 +252,13 @@ describe Gibbon do
|
|
239
252
|
|
240
253
|
private
|
241
254
|
|
242
|
-
def expect_post(expected_url, expected_body, expected_timeout=30)
|
243
|
-
Gibbon::APICategory.
|
255
|
+
def expect_post(expected_url, expected_body, expected_timeout=30, expected_headers={})
|
256
|
+
expect(Gibbon::APICategory).to receive(:post).with { |url, opts|
|
244
257
|
expect(url).to eq expected_url
|
245
258
|
expect(expected_body).to eq MultiJson.load(URI::decode(opts[:body]))
|
246
259
|
expect(opts[:timeout]).to eq expected_timeout
|
247
|
-
|
260
|
+
expect(opts[:headers]).to eq expected_headers
|
261
|
+
}.and_return(Struct.new(:body).new("[]"))
|
248
262
|
end
|
249
263
|
|
250
264
|
# def expect_post(expected_url, expected_body, expected_timeout=30)
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gibbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amro Mousa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.3.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.3.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: 2.14.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
68
|
+
version: 2.14.1
|
69
69
|
description: A wrapper for MailChimp API 2.0 and Export API 1.0
|
70
70
|
email:
|
71
71
|
- amromousa@gmail.com
|
@@ -73,9 +73,9 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .document
|
77
|
-
- .gitignore
|
78
|
-
- .travis.yml
|
76
|
+
- ".document"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.markdown
|
@@ -101,17 +101,17 @@ require_paths:
|
|
101
101
|
- lib
|
102
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- -
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project: gibbon
|
114
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.2.0
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: A wrapper for MailChimp API 2.0 and Export API 1.0
|