mailchimp3 1.5.1 → 1.5.2
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 +24 -23
- data/lib/mailchimp3/endpoint.rb +14 -14
- data/lib/mailchimp3/version.rb +1 -1
- data/lib/mailchimp3.rb +2 -2
- data/spec/mailchimp3_spec.rb +6 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1cc50c5f6d8d2898fe0bf2a0f862fc88c3cdb07cfde3b7e09f8027cd7be7ef2
|
4
|
+
data.tar.gz: b9544cac7e434bdec8b7c50ec7e6343fefb03dcc2c45b379b6c11d9803d2c3fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53d816a6bb62f88d0f4e6700d6a7952c781ebdd09af0aa439cc0e0f199e4109c54588ba1bde5e4976d2c3f9c7938205715bd016dd5f44405be8f3c006f44272f
|
7
|
+
data.tar.gz: eddcf4862840096d46f5cc49e2cd14ce87eb0a8282e6bcdafdf243a67c372ac7eab94aaf294ac3485e35fcbfc3239b1c5bcb6fc06376212f5bbfb83828a5d9c2
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# MailChimp3
|
2
2
|
|
3
|
-
[](https://circleci.com/gh/planningcenter/mailchimp3/tree/master)
|
4
4
|
|
5
|
-
`mailchimp3` is a Rubygem that provides a very thin, simple wrapper around the MailChimp RESTful JSON API version 3
|
6
|
-
documented at [
|
7
|
-
just use the `post` method. See 2.0 section later in this document.)
|
5
|
+
`mailchimp3` is a Rubygem that provides a very thin, simple wrapper around the MailChimp RESTful JSON "Marketing" API version 3
|
6
|
+
documented at [mailchimp.com/developer/marketing/api](https://mailchimp.com/developer/marketing/api/).
|
8
7
|
|
9
8
|
This wrapper is very low-level -- you'll still be dealing with individual GET, POST, PATCH, and DELETE requests, but the gem
|
10
9
|
handles the OAuth2 flow (getting a token), passing the auth token in every request, and raises descriptive errors you can easily rescue
|
@@ -185,7 +184,18 @@ api.lists.post(
|
|
185
184
|
}
|
186
185
|
```
|
187
186
|
|
188
|
-
##
|
187
|
+
## method_missing(endpoint_name)
|
188
|
+
|
189
|
+
Anything you append to the end gets handled by `method_missing` and returns a new Endpoint object.
|
190
|
+
This is what allows this gem work with any endpoint without the library code needing to be updated.
|
191
|
+
|
192
|
+
## \[](endpoint_name_or_id)
|
193
|
+
|
194
|
+
Similar to the `method_missing` above, `endpoint['whatever']` and `endpoint[123]` are handled dynamically,
|
195
|
+
which allows you to build endpoints containing numbers, hyphens, or other characters not allowed by a
|
196
|
+
Ruby method name.
|
197
|
+
|
198
|
+
## get(params = {})
|
189
199
|
|
190
200
|
`get()` works for a collection (index) and a single resource (show).
|
191
201
|
|
@@ -199,7 +209,9 @@ api.lists['abc123'].members['cde345'].get
|
|
199
209
|
# => resource_hash
|
200
210
|
```
|
201
211
|
|
202
|
-
|
212
|
+
If the endpoint accepts parameters, you can pass them in the `params` hash.
|
213
|
+
|
214
|
+
## post(body = {})
|
203
215
|
|
204
216
|
`post()` sends a POST request to create a new resource.
|
205
217
|
|
@@ -208,7 +220,9 @@ api.lists['abc123'].members.post(...)
|
|
208
220
|
# => resource_hash
|
209
221
|
```
|
210
222
|
|
211
|
-
|
223
|
+
The parameter given is sent as the body of the request. See [Example](#example) above.
|
224
|
+
|
225
|
+
## patch(body = {})
|
212
226
|
|
213
227
|
`patch()` sends a PATCH request to update an existing resource.
|
214
228
|
|
@@ -217,6 +231,8 @@ api.lists['abc123'].members['cde345'].patch(...)
|
|
217
231
|
# => resource_hash
|
218
232
|
```
|
219
233
|
|
234
|
+
The parameter given is sent as the body of the request. See [Example](#example) above.
|
235
|
+
|
220
236
|
## delete()
|
221
237
|
|
222
238
|
`delete()` sends a DELETE request to delete an existing resource. This method returns `true` if the delete was successful.
|
@@ -273,21 +289,6 @@ The `message` should be a simple string given by the API, e.g. "Resource Not Fou
|
|
273
289
|
Alternatively, you may rescue `MailChimp3::Errors::BaseError` and branch your code based on
|
274
290
|
the status code returned by calling `error.status`.
|
275
291
|
|
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
|
-
|
291
292
|
## Copyright & License
|
292
293
|
|
293
|
-
Copyright
|
294
|
+
Copyright 2021, Planning Center. Licensed MIT.
|
data/lib/mailchimp3/endpoint.rb
CHANGED
@@ -16,12 +16,12 @@ module MailChimp3
|
|
16
16
|
@cache = {}
|
17
17
|
end
|
18
18
|
|
19
|
-
def method_missing(
|
20
|
-
_build_endpoint(
|
19
|
+
def method_missing(endpoint_name, *_args)
|
20
|
+
_build_endpoint(endpoint_name.to_s)
|
21
21
|
end
|
22
22
|
|
23
|
-
def [](
|
24
|
-
_build_endpoint(
|
23
|
+
def [](endpoint_name_or_id)
|
24
|
+
_build_endpoint(endpoint_name_or_id.to_s)
|
25
25
|
end
|
26
26
|
|
27
27
|
def get(params = {})
|
@@ -81,23 +81,23 @@ module MailChimp3
|
|
81
81
|
when 200..299
|
82
82
|
body
|
83
83
|
when 400
|
84
|
-
fail Errors::BadRequest
|
84
|
+
fail Errors::BadRequest.new(status: status, body: body)
|
85
85
|
when 401
|
86
|
-
fail Errors::Unauthorized
|
86
|
+
fail Errors::Unauthorized.new(status: status, body: body)
|
87
87
|
when 403
|
88
|
-
fail Errors::Forbidden
|
88
|
+
fail Errors::Forbidden.new(status: status, body: body)
|
89
89
|
when 404
|
90
|
-
fail Errors::NotFound
|
90
|
+
fail Errors::NotFound.new(status: status, body: body)
|
91
91
|
when 405
|
92
|
-
fail Errors::MethodNotAllowed
|
92
|
+
fail Errors::MethodNotAllowed.new(status: status, body: body)
|
93
93
|
when 422
|
94
|
-
fail Errors::UnprocessableEntity
|
94
|
+
fail Errors::UnprocessableEntity.new(status: status, body: body)
|
95
95
|
when 400..499
|
96
|
-
fail Errors::ClientError
|
96
|
+
fail Errors::ClientError.new(status: status, body: body)
|
97
97
|
when 500
|
98
|
-
fail Errors::InternalServerError
|
98
|
+
fail Errors::InternalServerError.new(status: status, body: body)
|
99
99
|
when 500..599
|
100
|
-
fail Errors::ServerError
|
100
|
+
fail Errors::ServerError.new(status: status, body: body)
|
101
101
|
else
|
102
102
|
fail "unknown status #{status}"
|
103
103
|
end
|
@@ -106,7 +106,7 @@ module MailChimp3
|
|
106
106
|
def _parse_body(result)
|
107
107
|
JSON.parse(result.body)
|
108
108
|
rescue JSON::ParserError
|
109
|
-
raise Errors::ServerError
|
109
|
+
raise Errors::ServerError.new(status: result.status, body: result.body)
|
110
110
|
end
|
111
111
|
|
112
112
|
def _build_endpoint(path)
|
data/lib/mailchimp3/version.rb
CHANGED
data/lib/mailchimp3.rb
CHANGED
data/spec/mailchimp3_spec.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
describe MailChimp3 do
|
4
|
+
describe '#new' do
|
5
|
+
it 'smoke test' do
|
6
|
+
expect(subject.new(basic_auth_key: 'key-us2').url).not_to be_nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe '#config' do
|
5
11
|
it 'returns configuration object' do
|
6
12
|
subject.config.client_id = 'foo'
|
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.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -117,7 +117,7 @@ homepage: https://github.com/seven1m/mailchimp3
|
|
117
117
|
licenses:
|
118
118
|
- MIT
|
119
119
|
metadata: {}
|
120
|
-
post_install_message:
|
120
|
+
post_install_message:
|
121
121
|
rdoc_options: []
|
122
122
|
require_paths:
|
123
123
|
- lib
|
@@ -132,12 +132,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
135
|
+
rubygems_version: 3.4.2
|
136
|
+
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: wrapper for MailChimp's 3.0 API
|
139
139
|
test_files:
|
140
|
-
- spec/spec_helper.rb
|
141
|
-
- spec/mailchimp3_spec.rb
|
142
140
|
- spec/mailchimp3/endpoint_spec.rb
|
143
141
|
- spec/mailchimp3/oauth_spec.rb
|
142
|
+
- spec/mailchimp3_spec.rb
|
143
|
+
- spec/spec_helper.rb
|