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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b314077a25462ff39bc051da9964e8d059e8adc9
4
- data.tar.gz: 6da6d33d428f4dca0f45cff51a1e05912470c17c
3
+ metadata.gz: 50f6e393e4d3bca4e56673db5f615de6f45008d4
4
+ data.tar.gz: 36eb3eee9d7a618fd29a4d5de4d0f8facd3a7563
5
5
  SHA512:
6
- metadata.gz: 684701c680aa61b443a25c550cf3a8e2df935d1cd35ffd25137cd3114fca3eca28f1611bc90a96933f81110f9d65688f546f79896783e0a545729222f7329770
7
- data.tar.gz: 4aff56999fb044b547e7647e1adb75d9c3b5eca995d1844ea144c72aafede155a53692b98feb85752e0c168efc40a1962ed8c3d5190d1c7b135e1faaa0213644
6
+ metadata.gz: 97c4755405474f78cb0674f4caf23389786d22aafa351b7ba2fc08e4666ada7f33c6fa8709d071ee2d83b451a5b6426748993593f40a7705c2a63abb8fc7c1f9
7
+ data.tar.gz: e426ee592429a2fe4c919ed11f2ecbdef11fcb5017fd721712a4c5beff67cd3e7a59fac98de95c085be1a700a994cb8973222c8b03b5bade6b4cbaccb9f29fbe
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased][unreleased]
2
2
 
3
+ ## [2.2.4] - 2016-05-21
4
+ - Add debug logging
5
+
3
6
  ## [2.2.3] - 2016-03-16
4
7
  - Capture status code and raw body when response is not json.
5
8
 
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ platforms :rbx do
6
6
  end
7
7
 
8
8
  group :development, :test do
9
- gem 'webmock'
9
+ gem 'webmock', '~>1.24.0'
10
10
  end
11
11
 
12
12
  gemspec
@@ -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
- MailChimp's [resource documentation](http://kb.mailchimp.com/api/resources) is a list of available resources. Substitute an underscore if
70
- a resource name contains a hyphen.
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:
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Gibbon
2
- VERSION = "2.2.3"
2
+ VERSION = "2.2.4"
3
3
  end
@@ -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
@@ -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.3
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-03-16 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday