gibbon 2.2.3 → 2.2.4
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/CHANGELOG.md +3 -0
- data/Gemfile +1 -1
- data/README.markdown +59 -2
- data/lib/gibbon/api_request.rb +3 -0
- data/lib/gibbon/request.rb +3 -2
- data/lib/gibbon/version.rb +1 -1
- data/spec/gibbon/api_request_spec.rb +14 -0
- data/spec/gibbon/gibbon_spec.rb +10 -0
- 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: 50f6e393e4d3bca4e56673db5f615de6f45008d4
|
4
|
+
data.tar.gz: 36eb3eee9d7a618fd29a4d5de4d0f8facd3a7563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97c4755405474f78cb0674f4caf23389786d22aafa351b7ba2fc08e4666ada7f33c6fa8709d071ee2d83b451a5b6426748993593f40a7705c2a63abb8fc7c1f9
|
7
|
+
data.tar.gz: e426ee592429a2fe4c919ed11f2ecbdef11fcb5017fd721712a4c5beff67cd3e7a59fac98de95c085be1a700a994cb8973222c8b03b5bade6b4cbaccb9f29fbe
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -66,8 +66,17 @@ You can also set the environment variable `MAILCHIMP_API_KEY` and Gibbon will us
|
|
66
66
|
gibbon = Gibbon::Request.new
|
67
67
|
```
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
***Note*** Substitute an underscore if a resource name contains a hyphen.
|
70
|
+
|
71
|
+
MailChimp's [resource documentation](http://kb.mailchimp.com/api/resources) is a list of available resources.
|
72
|
+
|
73
|
+
##Debug Logging
|
74
|
+
|
75
|
+
Pass `debug: true` to enable debug logging to STDOUT.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
gibbon = Gibbon::Request.new(api_key: "your_api_key", debug: true)
|
79
|
+
```
|
71
80
|
|
72
81
|
## Examples
|
73
82
|
|
@@ -111,6 +120,12 @@ And to retrieve the next 50 members:
|
|
111
120
|
gibbon.lists(list_id).members.retrieve(params: {"count": "50", "offset: "50"})
|
112
121
|
```
|
113
122
|
|
123
|
+
And to retrieve only subscribed members
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
gibbon.lists(list_id).members.retrieve(params: {"count": "50", "offset: "50", "status": "subscribed"})
|
127
|
+
```
|
128
|
+
|
114
129
|
Subscribe a member to a list:
|
115
130
|
|
116
131
|
```ruby
|
@@ -129,6 +144,48 @@ You can also unsubscribe a member from a list:
|
|
129
144
|
gibbon.lists(list_id).members(lower_case_md5_hashed_email_address).update(body: { status: "unsubscribed" })
|
130
145
|
```
|
131
146
|
|
147
|
+
### Batch Operations
|
148
|
+
|
149
|
+
Any API call that can be made directly can also be organized into batch operations. Performing batch operations requires you to generate a hash for each individual API call and pass them as an `Array` to the Batch endpoint.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
# Create a new batch job that will create new list members
|
153
|
+
gibbon.batches.create(body: {
|
154
|
+
operations: [
|
155
|
+
{
|
156
|
+
method: "POST",
|
157
|
+
path: "lists/#{ list_id }/members",
|
158
|
+
body: "{...}" # The JSON payload for PUT, POST, or PATCH
|
159
|
+
},
|
160
|
+
...
|
161
|
+
]
|
162
|
+
})
|
163
|
+
```
|
164
|
+
|
165
|
+
This will create a new batch job and return a Batch response. The response will include an `id` attribute which can be used to check the status of a particular batch job.
|
166
|
+
|
167
|
+
##### Checking on a Batch Job
|
168
|
+
```ruby
|
169
|
+
gibbon.batches(batch_id).retrieve
|
170
|
+
```
|
171
|
+
|
172
|
+
###### Response
|
173
|
+
```ruby
|
174
|
+
{
|
175
|
+
"id"=>"0ca62e43cc",
|
176
|
+
"status"=>"started",
|
177
|
+
"total_operations"=>1,
|
178
|
+
"finished_operations"=>1,
|
179
|
+
"errored_operations"=>0,
|
180
|
+
"submitted_at"=>"2016-04-19T01:16:58+00:00",
|
181
|
+
"completed_at"=>"",
|
182
|
+
"response_body_url"=>""
|
183
|
+
}
|
184
|
+
```
|
185
|
+
|
186
|
+
**NOTE** This response truncated for brevity. Reference the MailChimp
|
187
|
+
[API documentation for Batch Operations](http://developer.mailchimp.com/documentation/mailchimp/reference/batches/) for more details.
|
188
|
+
|
132
189
|
### Fields
|
133
190
|
|
134
191
|
Only retrieve ids and names for fetched lists:
|
data/lib/gibbon/api_request.rb
CHANGED
@@ -134,6 +134,9 @@ module Gibbon
|
|
134
134
|
client = Faraday.new(self.api_url, proxy: self.proxy) do |faraday|
|
135
135
|
faraday.response :raise_error
|
136
136
|
faraday.adapter adapter
|
137
|
+
if @request_builder.debug
|
138
|
+
faraday.response :logger, ::Logger.new(STDOUT), bodies: true
|
139
|
+
end
|
137
140
|
end
|
138
141
|
client.basic_auth('apikey', self.api_key)
|
139
142
|
client
|
data/lib/gibbon/request.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Gibbon
|
2
2
|
class Request
|
3
|
-
attr_accessor :api_key, :api_endpoint, :timeout, :proxy, :faraday_adapter
|
3
|
+
attr_accessor :api_key, :api_endpoint, :timeout, :proxy, :faraday_adapter, :debug
|
4
4
|
|
5
5
|
DEFAULT_TIMEOUT = 30
|
6
6
|
|
7
|
-
def initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil)
|
7
|
+
def initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil, debug: false)
|
8
8
|
@path_parts = []
|
9
9
|
@api_key = api_key || self.class.api_key || ENV['MAILCHIMP_API_KEY']
|
10
10
|
@api_key = @api_key.strip if @api_key
|
@@ -12,6 +12,7 @@ module Gibbon
|
|
12
12
|
@timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT
|
13
13
|
@proxy = proxy || self.class.proxy || ENV['MAILCHIMP_PROXY']
|
14
14
|
@faraday_adapter = faraday_adapter || Faraday.default_adapter
|
15
|
+
@debug = debug
|
15
16
|
end
|
16
17
|
|
17
18
|
def method_missing(method, *args)
|
data/lib/gibbon/version.rb
CHANGED
@@ -29,4 +29,18 @@ describe Gibbon::APIRequest do
|
|
29
29
|
stub_request(:get, "#{@api_root}/lists").to_raise(exception)
|
30
30
|
expect { @gibbon.lists.retrieve }.to raise_error(Gibbon::MailChimpError)
|
31
31
|
end
|
32
|
+
|
33
|
+
context "handle_error" do
|
34
|
+
it "includes status and raw body even when json can't be parsed" do
|
35
|
+
response_values = {:status => 503, :headers => {}, :body => 'A non JSON response'}
|
36
|
+
exception = Faraday::Error::ClientError.new("the server responded with status 503", response_values)
|
37
|
+
api_request = Gibbon::APIRequest.new
|
38
|
+
begin
|
39
|
+
api_request.send :handle_error, exception
|
40
|
+
rescue => boom
|
41
|
+
expect(boom.status_code).to eq 503
|
42
|
+
expect(boom.raw_body).to eq "A non JSON response"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
32
46
|
end
|
data/spec/gibbon/gibbon_spec.rb
CHANGED
@@ -76,6 +76,16 @@ describe Gibbon do
|
|
76
76
|
@gibbon = Gibbon::Request.new(faraday_adapter: adapter)
|
77
77
|
expect(@gibbon.faraday_adapter).to eq(adapter)
|
78
78
|
end
|
79
|
+
|
80
|
+
it "debug false by default" do
|
81
|
+
@gibbon = Gibbon::Request.new
|
82
|
+
expect(@gibbon.debug).to be false
|
83
|
+
end
|
84
|
+
|
85
|
+
it "sets debug in the constructor" do
|
86
|
+
@gibbon = Gibbon::Request.new(debug: true)
|
87
|
+
expect(@gibbon.debug).to be true
|
88
|
+
end
|
79
89
|
end
|
80
90
|
|
81
91
|
describe "build api url" do
|
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.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amro Mousa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|