mailchimp3 1.1.0 → 1.2.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 +1 -1
- data/lib/mailchimp3/endpoint.rb +20 -15
- data/lib/mailchimp3/errors.rb +8 -8
- data/lib/mailchimp3/version.rb +1 -1
- data/spec/mailchimp3/endpoint_spec.rb +44 -25
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10e1e2194f6330bc8836f6449e0d4a34cc94d951
|
4
|
+
data.tar.gz: 9bd5c607f83a710f2a93a70a449407ad4a210daf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03f478d9191b5b0d92534ff773cea17d207de3d14624cc50a2ce2b0d5638bd3e09283a90cd8c87b0d182fa3b779076b7b6cdb4dcffce82326b3c7bcc92016156
|
7
|
+
data.tar.gz: 06caf2489afca52ecdba0ffcb28b5fb2f4e310708b3b3230432b9a1dbdac9907e40f33c023aef22ad04bd25f181cfe3c86130cfbde6382ad9d6a535e048193e9
|
data/README.md
CHANGED
data/lib/mailchimp3/endpoint.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module MailChimp3
|
5
5
|
class Endpoint
|
@@ -65,33 +65,39 @@ module MailChimp3
|
|
65
65
|
private
|
66
66
|
|
67
67
|
def _build_response(result)
|
68
|
-
|
68
|
+
body = _parse_body(result)
|
69
|
+
case (status = result.status)
|
69
70
|
when 200..299
|
70
|
-
|
71
|
+
body
|
71
72
|
when 400
|
72
|
-
fail Errors::BadRequest,
|
73
|
+
fail Errors::BadRequest, status: status, body: body
|
73
74
|
when 401
|
74
|
-
fail Errors::Unauthorized,
|
75
|
+
fail Errors::Unauthorized, status: status, body: body
|
75
76
|
when 403
|
76
|
-
fail Errors::Forbidden,
|
77
|
+
fail Errors::Forbidden, status: status, body: body
|
77
78
|
when 404
|
78
|
-
fail Errors::NotFound,
|
79
|
+
fail Errors::NotFound, status: status, body: body
|
79
80
|
when 405
|
80
|
-
fail Errors::MethodNotAllowed,
|
81
|
+
fail Errors::MethodNotAllowed, status: status, body: body
|
81
82
|
when 422
|
82
|
-
fail Errors::UnprocessableEntity,
|
83
|
+
fail Errors::UnprocessableEntity, status: status, body: body
|
83
84
|
when 400..499
|
84
|
-
fail Errors::ClientError,
|
85
|
+
fail Errors::ClientError, status: status, body: body
|
85
86
|
when 500
|
86
|
-
fail Errors::InternalServerError,
|
87
|
+
fail Errors::InternalServerError, status: status, body: body
|
87
88
|
when 500..599
|
88
|
-
fail Errors::ServerError,
|
89
|
+
fail Errors::ServerError, status: status, body: body
|
89
90
|
else
|
90
|
-
|
91
|
-
fail "unknown status #{result.status}"
|
91
|
+
fail "unknown status #{status}"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
def _parse_body(result)
|
96
|
+
JSON.parse(result.body)
|
97
|
+
rescue JSON::ParserError
|
98
|
+
raise Errors::ServerError, status: result.status, body: result.body
|
99
|
+
end
|
100
|
+
|
95
101
|
def _build_endpoint(path)
|
96
102
|
@cache[path] ||= begin
|
97
103
|
self.class.new(
|
@@ -114,7 +120,6 @@ module MailChimp3
|
|
114
120
|
def _connection
|
115
121
|
@connection ||= Faraday.new(url: url) do |faraday|
|
116
122
|
faraday.adapter :excon
|
117
|
-
faraday.response :json, content_type: /\bjson$/
|
118
123
|
if @basic_auth_key
|
119
124
|
faraday.basic_auth '', @basic_auth_key
|
120
125
|
elsif @oauth_access_token
|
data/lib/mailchimp3/errors.rb
CHANGED
@@ -6,16 +6,16 @@ module MailChimp3
|
|
6
6
|
class BaseError < StandardError
|
7
7
|
attr_reader :status, :details
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@status =
|
11
|
-
@message = if
|
12
|
-
"#{
|
13
|
-
elsif
|
14
|
-
"#{
|
9
|
+
def initialize(body:, status:)
|
10
|
+
@status = status
|
11
|
+
@message = if body.is_a?(Hash) && body['error']
|
12
|
+
"#{body['name']}: #{body['error']}"
|
13
|
+
elsif body.is_a?(Hash)
|
14
|
+
"#{body['title']}: #{body['detail']}"
|
15
15
|
else
|
16
|
-
|
16
|
+
body.to_s
|
17
17
|
end
|
18
|
-
@details =
|
18
|
+
@details = body if body.is_a?(Hash)
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_s
|
data/lib/mailchimp3/version.rb
CHANGED
@@ -68,13 +68,16 @@ describe MailChimp3::Endpoint do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'raises a NotFound error' do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
expect { subject.get }.to raise_error do |error|
|
72
|
+
expect(error).to be_a(MailChimp3::Errors::NotFound)
|
73
|
+
expect(error.status).to eq(404)
|
74
|
+
expect(error.message).to eq('Resource Not Found: The requested resource could not be found.')
|
75
|
+
expect(error.details).to eq(
|
76
|
+
'status' => 404,
|
77
|
+
'title' => 'Resource Not Found',
|
78
|
+
'detail' => 'The requested resource could not be found.'
|
79
|
+
)
|
80
|
+
end
|
78
81
|
end
|
79
82
|
end
|
80
83
|
|
@@ -94,9 +97,7 @@ describe MailChimp3::Endpoint do
|
|
94
97
|
end
|
95
98
|
|
96
99
|
it 'raises a ClientError error' do
|
97
|
-
expect {
|
98
|
-
subject.get
|
99
|
-
}.to raise_error(MailChimp3::Errors::ClientError)
|
100
|
+
expect { subject.get }.to raise_error(MailChimp3::Errors::ClientError)
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
@@ -116,9 +117,7 @@ describe MailChimp3::Endpoint do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it 'raises a ServerError error' do
|
119
|
-
expect {
|
120
|
-
subject.get
|
121
|
-
}.to raise_error(MailChimp3::Errors::ServerError)
|
120
|
+
expect { subject.get }.to raise_error(MailChimp3::Errors::ServerError)
|
122
121
|
end
|
123
122
|
end
|
124
123
|
end
|
@@ -132,21 +131,41 @@ describe MailChimp3::Endpoint do
|
|
132
131
|
}
|
133
132
|
end
|
134
133
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
context do
|
135
|
+
let(:result) do
|
136
|
+
{
|
137
|
+
'id' => 'd3ed40bd7c',
|
138
|
+
'name' => 'Foo'
|
139
|
+
}
|
140
|
+
end
|
141
141
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
142
|
+
before do
|
143
|
+
stub_request(:post, 'https://us2.api.mailchimp.com/3.0/lists')
|
144
|
+
.to_return(status: 201, body: result.to_json, headers: { 'Content-Type' => 'application/json; charset=utf-8' })
|
145
|
+
@result = subject.post(resource)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'returns the result of making a POST request to the endpoint' do
|
149
|
+
expect(@result).to eq(result)
|
150
|
+
end
|
146
151
|
end
|
147
152
|
|
148
|
-
|
149
|
-
|
153
|
+
context 'when the response is not valid JSON' do
|
154
|
+
let(:result) { 'bad' }
|
155
|
+
|
156
|
+
before do
|
157
|
+
stub_request(:post, 'https://us2.api.mailchimp.com/3.0/lists')
|
158
|
+
.to_return(status: 200, body: result, headers: { 'Content-Type' => 'application/json; charset=utf-8' })
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'raises an error' do
|
162
|
+
expect { subject.post(resource) }.to raise_error do |error|
|
163
|
+
expect(error).to be_a(MailChimp3::Errors::ServerError)
|
164
|
+
expect(error.status).to eq(200)
|
165
|
+
expect(error.message).to eq('bad')
|
166
|
+
expect(error.details).to be_nil
|
167
|
+
end
|
168
|
+
end
|
150
169
|
end
|
151
170
|
end
|
152
171
|
|
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.2.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-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.9.1
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: faraday_middleware
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.1
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: excon
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
133
|
version: '0'
|
148
134
|
requirements: []
|
149
135
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.4.
|
136
|
+
rubygems_version: 2.4.5
|
151
137
|
signing_key:
|
152
138
|
specification_version: 4
|
153
139
|
summary: wrapper for MailChimp's 3.0 API
|
@@ -156,3 +142,4 @@ test_files:
|
|
156
142
|
- spec/mailchimp3/oauth_spec.rb
|
157
143
|
- spec/mailchimp3_spec.rb
|
158
144
|
- spec/spec_helper.rb
|
145
|
+
has_rdoc:
|