gibbon 2.1.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f67c204c24ccb1e88465da9491083990cda98d84
4
- data.tar.gz: d7ee83c9782fdd6a9664a0e0e1095f82fa7d14cd
3
+ metadata.gz: b0639262cf049f3539150517ac94debb49d959f5
4
+ data.tar.gz: cce871c66805b8746dfd37df80164f6c2e77813f
5
5
  SHA512:
6
- metadata.gz: 4f298cdbe7fc035c0be9078e9ce9c0baa37f95d97ddaba121c55be7e3b9d5e95227f0fc228448aeb9e31417d7222a0ed4f91c1b4b1a0bfb06c2c33879c154ac1
7
- data.tar.gz: b0c0012892ca2d80bb1f6ea012f03d7586510fa9ed6c965d1179a04f79cb17003469be6c5af71197ecb236659de7df57bce228b50e52753aeae20751c1f5a1cf
6
+ metadata.gz: 25e68e96de157c2a5b34bff6e0222c02ef2752114533bba3f98c9248b20fea9516f82dd2dabcee4601b74154781c69b180808899cfb47923baf2215c865422c2
7
+ data.tar.gz: ab56e1adbd864afb3ea3f84d6244cfb338e84330ddb705b9c6dd40cf5d7a85b11ace78b94ca5edd8df52ac46d37ad01dc734e2b8b494f48bfb97853156a3fb17
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased][unreleased]
2
2
 
3
+ ## [2.1.1] - 2015-11-05
4
+ - Fix surfacing unparseable Faraday request exception.
5
+
3
6
  ## [2.1.0] - 2015-10-12
4
7
  - Upsert support
5
8
 
data/README.markdown CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gibbon is an API wrapper for MailChimp's [API](http://kb.mailchimp.com/api/).
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/amro/gibbon.png)](http://travis-ci.org/amro/gibbon)
6
- [![Dependency Status](https://gemnasium.com/amro/gibbon.png)](https://gemnasium.com/amro/gibbon)
5
+ [![Build Status](https://secure.travis-ci.org/amro/gibbon.svg)](http://travis-ci.org/amro/gibbon)
6
+ [![Dependency Status](https://gemnasium.com/amro/gibbon.svg)](https://gemnasium.com/amro/gibbon)
7
7
  ##Important Notes
8
8
 
9
9
  Gibbon now targets MailChimp API 3.0, which is substantially different from the previous API. Please use Gibbon 1.1.x if you need to use API 2.0.
@@ -22,83 +22,121 @@ A MailChimp account and API key. You can see your API keys [here](http://admin.m
22
22
 
23
23
  First, create an instance Gibbon::Request:
24
24
 
25
- gibbon = Gibbon::Request.new(api_key: "your_api_key")
25
+ ```ruby
26
+ gibbon = Gibbon::Request.new(api_key: "your_api_key")
27
+ ```
26
28
 
27
29
  You can set an individual request's timeout like this:
28
30
 
29
- gibbon.timeout = 10
31
+ ```ruby
32
+ gibbon.timeout = 10
33
+ ```
30
34
 
31
35
  Now you can make requests using the resources defined in [MailChimp's docs](http://kb.mailchimp.com/api/resources). Resource IDs
32
36
  are specified inline and a `CRUD` (`create`, `retrieve`, `update`, `upsert`, or `delete`) verb initiates the request. `upsert` lets you update a record, if it exists, or insert it otherwise where supported by MailChimp's API.
33
37
 
34
- gibbon.lists.retrieve
38
+ *Please note that `upsert` requires Gibbon version 2.1.0 or newer!*
39
+
40
+ ```ruby
41
+ gibbon.lists.retrieve
42
+ ```
35
43
 
36
44
  Retrieving a specific list looks like:
37
45
 
38
- gibbon.lists(list_id).retrieve
46
+ ```ruby
47
+ gibbon.lists(list_id).retrieve
48
+ ```
39
49
 
40
50
  Retrieving a specific list's members looks like:
41
51
 
42
- gibbon.lists(list_id).members.retrieve
52
+ ```ruby
53
+ gibbon.lists(list_id).members.retrieve
54
+ ```
43
55
 
44
56
  You can also specify `headers`, `params`, and `body` when calling a `CRUD` method. For example:
45
57
 
46
- gibbon.lists.retrieve(headers: {"SomeHeader": "SomeHeaderValue"}, params: {"query_param": "query_param_value"})
58
+ ```ruby
59
+ gibbon.lists.retrieve(headers: {"SomeHeader": "SomeHeaderValue"}, params: {"query_param": "query_param_value"})
60
+ ```
47
61
 
48
- Of course, `body` is only supported on `create` and `update` calls. Those map to HTTP `POST` and `PATCH` verbs.
62
+ Of course, `body` is only supported on `create`, `update`, and `upsert` calls. Those map to HTTP `POST`, `PATCH`, and `PUT` verbs respectively.
49
63
 
50
64
  You can set `api_key` and `timeout` globally:
51
65
 
52
- Gibbon::Request.api_key = "your_api_key"
53
- Gibbon::Request.timeout = 15
66
+ ```ruby
67
+ Gibbon::Request.api_key = "your_api_key"
68
+ Gibbon::Request.timeout = 15
69
+ ```
54
70
 
55
71
  For example, you could set the values above in an `initializer` file in your `Rails` app (e.g. your\_app/config/initializers/gibbon.rb).
56
72
 
57
73
  Assuming you've set an `api_key` on Gibbon, you can conveniently make API calls on the class itself:
58
74
 
59
- Gibbon::Request.lists.retrieve
75
+ ```ruby
76
+ Gibbon::Request.lists.retrieve
77
+ ```
60
78
 
61
79
  You can also set the environment variable `MAILCHIMP_API_KEY` and Gibbon will use it when you create an instance:
62
80
 
63
- gibbon = Gibbon::Request.new
81
+ ```ruby
82
+ gibbon = Gibbon::Request.new
83
+ ```
64
84
 
65
85
  MailChimp's [resource documentation](http://kb.mailchimp.com/api/resources) is a list of available resources. Substitute an underscore if
66
86
  a resource name contains a hyphen.
67
87
 
68
88
  ### Fetching Campaigns
69
89
 
70
- campaigns = gb.campaigns.retrieve
90
+ ```ruby
91
+ campaigns = gb.campaigns.retrieve
92
+ ```
71
93
 
72
94
  ### Fetching Lists
73
95
 
74
96
  Similarly, to fetch your lists
75
97
 
76
- lists = gibbon.lists.retrieve
98
+ ```ruby
99
+ lists = gibbon.lists.retrieve
100
+ ```
77
101
 
78
102
  ### More Advanced Examples
79
103
 
80
104
  List subscribers for a list:
81
105
 
82
- gibbon.lists(list_id).members.retrieve
106
+ ```ruby
107
+ gibbon.lists(list_id).members.retrieve
108
+ ```
83
109
 
84
110
  Subscribe a member to a list:
85
111
 
86
- gibbon.lists(list_id).members.create(body: {email_address: "email_address", status: "subscribed", merge_fields: {FNAME: "First Name", LNAME: "Last Name"}})
112
+ ```ruby
113
+ gibbon.lists(list_id).members.create(body: {email_address: "foo@bar.com", status: "subscribed", merge_fields: {FNAME: "First Name", LNAME: "Last Name"}})
114
+ ```
115
+
116
+ If you want to `upsert` instead, you would do the following:
87
117
 
88
- Note: You could call `upsert` instead of `create` in the example above to update the member if they already exist or subscribe them if they do not.
118
+ ```ruby
119
+ gibbon.lists(list_id).members(lower_case_md5_hashed_email_address).upsert(body: {email_address: "foo@bar.com", status: "subscribed", merge_fields: {FNAME: "First Name", LNAME: "Last Name"}})
120
+ ```
89
121
 
90
122
  You can also unsubscribe a member from a list:
91
123
 
92
- gibbon.lists(list_id).members(member_id).update(body: { status: "unsubscribed" })
124
+ ```ruby
125
+ gibbon.lists(list_id).members(member_id).update(body: { status: "unsubscribed" })
126
+ ```
93
127
 
94
128
  Fetch the number of opens for a campaign
95
129
 
96
- email_stats = gibbon.reports(campaign_id).retrieve["opens"]
130
+ ```ruby
131
+ email_stats = gibbon.reports(campaign_id).retrieve["opens"]
132
+ ```
97
133
 
98
134
  Overriding Gibbon's API endpoint (i.e. if using an access token from OAuth and have the `api_endpoint` from the [metadata](http://apidocs.mailchimp.com/oauth2/)):
99
135
 
100
- Gibbon::Request.api_endpoint = "https://us1.api.mailchimp.com"
101
- Gibbon::Request.api_key = your_access_token_or_api_key
136
+ ```ruby
137
+ Gibbon::Request.api_endpoint = "https://us1.api.mailchimp.com"
138
+ Gibbon::Request.api_key = your_access_token_or_api_key
139
+ ```
102
140
 
103
141
  ### Interests
104
142
 
@@ -106,31 +144,45 @@ Interests are a little more complicated than other parts of the API, so here's a
106
144
 
107
145
  Subscribing a member to a list with specific interests up front:
108
146
 
109
- g.lists(list_id).members.create(body: {email_address: user_email_address, status: "subscribed", interests: {some_interest_id: true, another_interest_id: true}})
147
+ ```ruby
148
+ g.lists(list_id).members.create(body: {email_address: user_email_address, status: "subscribed", interests: {some_interest_id: true, another_interest_id: true}})
149
+ ```
110
150
 
111
151
  Updating a list member's interests:
112
152
 
113
- gibbon.lists(list_id).members(member_id).update(body: {interests: {some_interest_id: true, another_interest_id: false}})
153
+ ```ruby
154
+ gibbon.lists(list_id).members(member_id).update(body: {interests: {some_interest_id: true, another_interest_id: false}})
155
+ ```
114
156
 
115
157
  So how do we get the interest IDs? When you query the API for a specific list member's information:
116
158
 
117
- g.lists(list_id).members(member_id).retrieve
159
+ ```ruby
160
+ g.lists(list_id).members(member_id).retrieve
161
+ ```
118
162
 
119
163
  The response looks someting like this (unrelated things removed):
120
164
 
121
- {"id"=>"...", "email_address"=>"...", ..., "interests"=>{"3def637141"=>true, "f7cc4ee841"=>false, "fcdc951b9f"=>false, "3daf3cf27d"=>true, "293a3703ed"=>false, "72370e0d1f"=>false, "d434d21a1c"=>false, "bdb1ff199f"=>false, "a54e78f203"=>false, "c4527fd018"=>false} ...}
165
+ ```ruby
166
+ {"id"=>"...", "email_address"=>"...", ..., "interests"=>{"3def637141"=>true, "f7cc4ee841"=>false, "fcdc951b9f"=>false, "3daf3cf27d"=>true, "293a3703ed"=>false, "72370e0d1f"=>false, "d434d21a1c"=>false, "bdb1ff199f"=>false, "a54e78f203"=>false, "c4527fd018"=>false} ...}
167
+ ```
122
168
 
123
169
  The API returns a map of interest ID to boolean value. Now we to get interest details so we know what these interest IDs map to. Looking at [this doc page](http://kb.mailchimp.com/api/resources/lists/interest-categories/interests/lists-interests-collection), we need to do this:
124
170
 
125
- g.lists(list_id).interest_categories.retrieve
171
+ ```ruby
172
+ g.lists(list_id).interest_categories.retrieve
173
+ ```
126
174
 
127
175
  To get a list of interest categories. That gives us something like:
128
176
 
129
- {"list_id"=>"...", "categories"=>[{"list_id"=>"...", "id"=>"0ace7aa498", "title"=>"Food Preferences", ...}] ...}
177
+ ```ruby
178
+ {"list_id"=>"...", "categories"=>[{"list_id"=>"...", "id"=>"0ace7aa498", "title"=>"Food Preferences", ...}] ...}
179
+ ```
130
180
 
131
181
  In this case, we're interested in the ID of the "Food Preferences" interest, which is `0ace7aa498`. Now we can fetch the details for this interest group:
132
182
 
133
- g.lists(list_id).interest_categories("0ace7aa498").interests.retrieve
183
+ ```ruby
184
+ g.lists(list_id).interest_categories("0ace7aa498").interests.retrieve
185
+ ```
134
186
 
135
187
  That response gives the interest data, including the ID for the interests themselves, which we can use to update a list member's interests or set them when we call the API to subscribe her or him to a list.
136
188
 
@@ -149,11 +201,15 @@ Gibbon 2.x has different syntax from version 1.x. This is because Gibbon maps to
149
201
 
150
202
  Gibbon 1.x:
151
203
 
152
- gibbon = Gibbon::API.new("your_api_key")
204
+ ```ruby
205
+ gibbon = Gibbon::API.new("your_api_key")
206
+ ```
153
207
 
154
208
  Gibbon 2.x:
155
209
 
156
- gibbon = Gibbon::Request.new(api_key: "your_api_key")
210
+ ```ruby
211
+ gibbon = Gibbon::Request.new(api_key: "your_api_key")
212
+ ```
157
213
 
158
214
  MailChimp API 3 is a RESTful API, so Gibbon's syntax now requires a trailing call to a verb, as described above.
159
215
 
@@ -161,37 +217,49 @@ MailChimp API 3 is a RESTful API, so Gibbon's syntax now requires a trailing cal
161
217
 
162
218
  Gibbon 1.x:
163
219
 
164
- gibbon.lists.list
220
+ ```ruby
221
+ gibbon.lists.list
222
+ ```
165
223
 
166
224
  Gibbon 2.x:
167
225
 
168
- gibbon.lists.retrieve
226
+ ```ruby
227
+ gibbon.lists.retrieve
228
+ ```
169
229
 
170
230
  #### Fetching List Members
171
231
 
172
232
  Gibbon 1.x:
173
233
 
174
- gibbon.lists.members({:id => list_id})
234
+ ```ruby
235
+ gibbon.lists.members({:id => list_id})
236
+ ```
175
237
 
176
238
  Gibbon 2.x:
177
239
 
178
- gibbon.lists(list_id).members.retrieve
240
+ ```ruby
241
+ gibbon.lists(list_id).members.retrieve
242
+ ```
179
243
 
180
244
  #### Subscribing a Member to a List
181
245
 
182
246
  Gibbon 1.x:
183
247
 
184
- gibbon.lists.subscribe({:id => list_id, :email => {:email => "email_address"}, :merge_vars => {:FNAME => "Bob", :LNAME => "Smith"}})
248
+ ```ruby
249
+ gibbon.lists.subscribe({:id => list_id, :email => {:email => "foo@bar.com"}, :merge_vars => {:FNAME => "Bob", :LNAME => "Smith"}})
250
+ ```
185
251
 
186
252
  Gibbon 2.x:
187
253
 
188
- gibbon.lists(list_id).members.create(body: {email_address: "email_address", status: "subscribed", merge_fields: {FNAME: "Bob", LNAME: "Smith"}})
254
+ ```ruby
255
+ gibbon.lists(list_id).members.create(body: {email_address: "foo@bar.com", status: "subscribed", merge_fields: {FNAME: "Bob", LNAME: "Smith"}})
256
+ ```
189
257
 
190
- ##Thanks
258
+ ## Thanks
191
259
 
192
260
  Thanks to everyone who has [contributed](https://github.com/amro/gibbon/contributors) to Gibbon's development.
193
261
 
194
- ##Copyright
262
+ ## Copyright
195
263
 
196
264
  * Copyright (c) 2010-2015 Amro Mousa. See LICENSE.txt for details.
197
265
  * MailChimp (c) 2001-2015 The Rocket Science Group.
@@ -1,5 +1,5 @@
1
1
  module Gibbon
2
2
  class MailChimpError < StandardError
3
- attr_accessor :title, :detail, :body, :raw_body, :status_code
3
+ attr_accessor :title, :detail, :body, :raw_body, :status_code, :message
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module Gibbon
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'webmock/rspec'
3
+
4
+ describe Gibbon::APIRequest do
5
+ let(:api_key) { "1234-us1" }
6
+
7
+ before do
8
+ @gibbon = Gibbon::Request.new(api_key: api_key)
9
+ @api_root = "https://apikey:#{api_key}@us1.api.mailchimp.com/3.0"
10
+ end
11
+
12
+ it "surfaces client request exceptions as a Gibbon::MailChimpError" do
13
+ exception = Faraday::Error::ClientError.new("the server responded with status 503")
14
+ stub_request(:get, "#{@api_root}/lists").to_raise(exception)
15
+ expect { @gibbon.lists.retrieve }.to raise_error(Gibbon::MailChimpError)
16
+ end
17
+
18
+ it "surfaces an unparseable client request exception as a Gibbon::MailChimpError" do
19
+ exception = Faraday::Error::ClientError.new(
20
+ "the server responded with status 503")
21
+ stub_request(:get, "#{@api_root}/lists").to_raise(exception)
22
+ expect { @gibbon.lists.retrieve }.to raise_error(Gibbon::MailChimpError)
23
+ end
24
+
25
+ it "surfaces an unparseable response body as a Gibbon::MailChimpError" do
26
+ response_values = {:status => 503, :headers => {}, :body => '[foo]'}
27
+ exception = Faraday::Error::ClientError.new("the server responded with status 503", response_values)
28
+
29
+ stub_request(:get, "#{@api_root}/lists").to_raise(exception)
30
+ expect { @gibbon.lists.retrieve }.to raise_error(Gibbon::MailChimpError)
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.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: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -102,6 +102,7 @@ files:
102
102
  - lib/gibbon/mailchimp_error.rb
103
103
  - lib/gibbon/request.rb
104
104
  - lib/gibbon/version.rb
105
+ - spec/gibbon/api_request_spec.rb
105
106
  - spec/gibbon/gibbon_spec.rb
106
107
  - spec/gibbon/upsert_spec.rb
107
108
  - spec/spec_helper.rb
@@ -133,6 +134,7 @@ signing_key:
133
134
  specification_version: 4
134
135
  summary: A wrapper for MailChimp API 3.0
135
136
  test_files:
137
+ - spec/gibbon/api_request_spec.rb
136
138
  - spec/gibbon/gibbon_spec.rb
137
139
  - spec/gibbon/upsert_spec.rb
138
140
  - spec/spec_helper.rb