mailchimp3 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +33 -13
- data/lib/mailchimp3/endpoint.rb +19 -5
- data/lib/mailchimp3/errors.rb +3 -1
- data/lib/mailchimp3/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86cbb578a02bfc1b1f33bf8a3394f5a4d324adb8
|
4
|
+
data.tar.gz: 41a06107a92fce74c0a282972fc9994acd6d7ec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f88cecce1c849cfdcb88a77dd4a8b73a4effbd1b0539e7f979d1d2db4d06871c4914de90e058d261860972246efadde5e667d5ee09f3f05cb51b40eb4577cb4
|
7
|
+
data.tar.gz: 40cbb2dcf74b50a58a6faf091904fa24d37c0eeb25a42a1997bff0738d90f592638bfbbd7fb805723b6f62290290c881f8cb4222ab2799ab0595cf20acbd19f8
|
data/README.md
CHANGED
@@ -3,12 +3,17 @@
|
|
3
3
|
[](https://circleci.com/gh/seven1m/mailchimp3/tree/master)
|
4
4
|
|
5
5
|
`mailchimp3` is a Rubygem that provides a very thin, simple wrapper around the MailChimp RESTful JSON API version 3.0
|
6
|
-
documented at [kb.mailchimp.com/api](http://kb.mailchimp.com/api/).
|
6
|
+
documented at [kb.mailchimp.com/api](http://kb.mailchimp.com/api/). (The wrapper also works with the 2.0 API if you
|
7
|
+
just use the `post` method. See 2.0 section later in this document.)
|
8
|
+
|
9
|
+
This wrapper is very low-level -- you'll still be dealing with individual GET, POST, PATCH, and DELETE requests, but the gem
|
10
|
+
handles the OAuth2 flow (getting a token), passing the auth token in every request, and raises descriptive errors you can easily rescue
|
11
|
+
in your own code.
|
7
12
|
|
8
13
|
## Installation
|
9
14
|
|
10
15
|
```
|
11
|
-
gem install mailchimp3
|
16
|
+
gem install mailchimp3
|
12
17
|
```
|
13
18
|
|
14
19
|
## Usage with HTTP Basic Auth
|
@@ -225,17 +230,17 @@ api.lists['abc123'].members['cde345'].delete
|
|
225
230
|
|
226
231
|
The following errors may be raised by the library, depending on the API response status code.
|
227
232
|
|
228
|
-
| HTTP Status Codes | Error Class
|
229
|
-
| ------------------- |
|
230
|
-
| 400 | `MailChimp3::Errors::BadRequest`
|
231
|
-
| 401 | `MailChimp3::Errors::Unauthorized`
|
232
|
-
| 403 | `MailChimp3::Errors::Forbidden`
|
233
|
-
| 404 | `MailChimp3::Errors::NotFound`
|
234
|
-
| 405 | `MailChimp3::Errors::MethodNotAllowed`
|
235
|
-
| 422 | `MailChimp3::Errors::UnprocessableEntity`
|
236
|
-
| other 4xx errors | `MailChimp3::Errors::ClientError`
|
237
|
-
| 500 | `MailChimp3::Errors::InternalServerError`
|
238
|
-
| other 5xx errors | `MailChimp3::Errors::ServerError`
|
233
|
+
| HTTP Status Codes | Specific Error Class | Generic Error Class |
|
234
|
+
| ------------------- | ----------------------------------------- | --------------------------------- |
|
235
|
+
| 400 | `MailChimp3::Errors::BadRequest` | `MailChimp3::Errors::ClientError` |
|
236
|
+
| 401 | `MailChimp3::Errors::Unauthorized` | `MailChimp3::Errors::ClientError` |
|
237
|
+
| 403 | `MailChimp3::Errors::Forbidden` | `MailChimp3::Errors::ClientError` |
|
238
|
+
| 404 | `MailChimp3::Errors::NotFound` | `MailChimp3::Errors::ClientError` |
|
239
|
+
| 405 | `MailChimp3::Errors::MethodNotAllowed` | `MailChimp3::Errors::ClientError` |
|
240
|
+
| 422 | `MailChimp3::Errors::UnprocessableEntity` | `MailChimp3::Errors::ClientError` |
|
241
|
+
| other 4xx errors | `MailChimp3::Errors::ClientError` | |
|
242
|
+
| 500 | `MailChimp3::Errors::InternalServerError` | `MailChimp3::Errors::ServerError` |
|
243
|
+
| other 5xx errors | `MailChimp3::Errors::ServerError` | |
|
239
244
|
|
240
245
|
The exception object has the following methods:
|
241
246
|
|
@@ -268,6 +273,21 @@ The `message` should be a simple string given by the API, e.g. "Resource Not Fou
|
|
268
273
|
Alternatively, you may rescue `MailChimp3::Errors::BaseError` and branch your code based on
|
269
274
|
the status code returned by calling `error.status`.
|
270
275
|
|
276
|
+
## MailChimp 2.0 API
|
277
|
+
|
278
|
+
This wrapper works with MailChimp's soon-to-be-deprecated 2.0 API. You need only use the `v2` path and the `post` method
|
279
|
+
for all your calls, like so:
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
api.v2.lists['member-activity'].post(id: 'abc123', emails: [{email: 'tim@timmorgan.org'}])
|
283
|
+
```
|
284
|
+
|
285
|
+
Some notes:
|
286
|
+
|
287
|
+
1. Call `v2` to switch to the 2.0 API, then add other path elements after that.
|
288
|
+
2. Any path element with a hyphen will need to use the array access syntax, e.g. `lists['member-activity']` not `lists.member-activity`.
|
289
|
+
3. You must use the `post` method for every call.
|
290
|
+
|
271
291
|
## Copyright & License
|
272
292
|
|
273
293
|
Copyright 2015, Tim Morgan. Licensed MIT.
|
data/lib/mailchimp3/endpoint.rb
CHANGED
@@ -5,12 +5,13 @@ module MailChimp3
|
|
5
5
|
class Endpoint
|
6
6
|
attr_reader :url, :last_result
|
7
7
|
|
8
|
-
def initialize(oauth_access_token: nil, basic_auth_key: nil, dc: nil, url: nil)
|
8
|
+
def initialize(oauth_access_token: nil, basic_auth_key: nil, dc: nil, url: nil, version: 3)
|
9
9
|
@oauth_access_token = oauth_access_token
|
10
10
|
@basic_auth_key = basic_auth_key
|
11
11
|
@dc = dc
|
12
12
|
@dc ||= @basic_auth_key.split('-').last if @basic_auth_key
|
13
13
|
@url = url || _build_url
|
14
|
+
@version = version
|
14
15
|
fail Errors::DataCenterRequiredError, 'You must pass dc.' unless @dc || @url
|
15
16
|
@cache = {}
|
16
17
|
end
|
@@ -30,6 +31,7 @@ module MailChimp3
|
|
30
31
|
|
31
32
|
def post(body = {})
|
32
33
|
@last_result = _connection.post(@url) do |req|
|
34
|
+
body[:apikey] = @oauth_access_token || @basic_auth_key if @version == 2
|
33
35
|
req.body = body.to_json
|
34
36
|
end
|
35
37
|
_build_response(@last_result)
|
@@ -51,6 +53,15 @@ module MailChimp3
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
56
|
+
def v2
|
57
|
+
self.class.new(
|
58
|
+
url: _build_v2_url,
|
59
|
+
basic_auth_key: @basic_auth_key,
|
60
|
+
oauth_access_token: @oauth_access_token,
|
61
|
+
version: 2
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
54
65
|
private
|
55
66
|
|
56
67
|
def _build_response(result)
|
@@ -86,15 +97,18 @@ module MailChimp3
|
|
86
97
|
self.class.new(
|
87
98
|
url: File.join(url, path.to_s),
|
88
99
|
basic_auth_key: @basic_auth_key,
|
89
|
-
oauth_access_token: @oauth_access_token
|
100
|
+
oauth_access_token: @oauth_access_token,
|
101
|
+
version: @version
|
90
102
|
)
|
91
103
|
end
|
92
104
|
end
|
93
105
|
|
94
106
|
def _build_url
|
95
|
-
|
96
|
-
|
97
|
-
|
107
|
+
"https://#{@dc}.api.mailchimp.com/3.0/"
|
108
|
+
end
|
109
|
+
|
110
|
+
def _build_v2_url
|
111
|
+
"https://#{@dc}.api.mailchimp.com/2.0/"
|
98
112
|
end
|
99
113
|
|
100
114
|
def _connection
|
data/lib/mailchimp3/errors.rb
CHANGED
@@ -8,7 +8,9 @@ module MailChimp3
|
|
8
8
|
|
9
9
|
def initialize(response)
|
10
10
|
@status = response.status
|
11
|
-
@message = if response.body.is_a?(Hash)
|
11
|
+
@message = if response.body.is_a?(Hash) && response.body['error']
|
12
|
+
"#{response.body['name']}: #{response.body['error']}"
|
13
|
+
elsif response.body.is_a?(Hash)
|
12
14
|
"#{response.body['title']}: #{response.body['detail']}"
|
13
15
|
else
|
14
16
|
response.body.to_s
|
data/lib/mailchimp3/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailchimp3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|