gibbon 2.2.5 → 3.0.1

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: 4264e8ea898f75f9239b7d03d6c5dcb1cadc915d
4
- data.tar.gz: c5e810141d2a9767d6e754128cd2b7d395e62bd1
3
+ metadata.gz: 3cadf43e229868a253bae8af2b7e609db5ffd11b
4
+ data.tar.gz: 95049f9c9ce5f1d3b9cde18f4650d5be52b13947
5
5
  SHA512:
6
- metadata.gz: aefbdbd257c1483028840b02bfd1e8952e25f185cdea4cd14b4adc8f6dd928826312605f7d66d264f2856e5a376ecfb841e218488361ab63d400b34bbf9e3d0d
7
- data.tar.gz: 4f789cb640563d3979b5b498852ea8b3552429b17a601eb6c1aab87f9d38c5650b7b55d09cac227fc47f232ea5d940ffdb5682c43c9a332ed642e5ab635d2892
6
+ metadata.gz: 58ab02cdd0ebd1cff4c0211b3a6674484db6a50b52aa34dc7efc746e1c75792dca7a4dedd58e8efc7e38fef73fc285f4859c809bba1f1b5cf1d674bc89cca436
7
+ data.tar.gz: 15459d6835355d637505ffc34c3aecbac0a6232a271d1481952c60028f30bd7264c35bd5e922d12ec12717b36a83df59046c808f43b02c19dda60d9f60f2f33f
@@ -1,8 +1,20 @@
1
1
  ## [Unreleased][unreleased]
2
2
 
3
+ ## [3.0.1] - 2017-01-13
4
+ - Gibbon::Request (API 3.0) now returns a `Gibbon::Response` object that exposes `headers` and the parsed response `body`
5
+ - Remove Export API support (this is deprected after all)
6
+ - Adds `symbolize_keys`, `debug`, and `faraday_adapter` as class vars
7
+ - Bump version to 3.0.1 (not sticking to semver here so folks who downloaded 3.0.0 have a way to easily move forward)
8
+
9
+ ## [3.0.0] - 2017-01-13
10
+ - Gibbon::Request (API 3.0) now returns a `Gibbon::Response` object that exposes `headers` and the parsed response `body`
11
+ - Adds Export API support
12
+ - Adds `symbolize_keys`, `debug`, and `faraday_adapter` as class vars
13
+ - Bump version to 3.0.0 due to breaking API change
14
+
3
15
  ## [2.2.5] - 2016-12-23
4
16
  - Adds open_timeout
5
- - Adds symbolize_keys
17
+ - Adds `symbolize_keys`
6
18
  - Change default timeout from 30 to 60 seconds
7
19
 
8
20
  ## [2.2.4] - 2016-05-21
@@ -54,8 +66,21 @@
54
66
  ## [1.1.4] - 2012-11-04
55
67
  - Fix JSON::ParserError on export calls that return blank results
56
68
 
57
- [unreleased]: https://github.com/amro/gibbon/compare/v2.0.0...HEAD
69
+ [unreleased]: https://github.com/amro/gibbon/compare/v3.0.1...HEAD
70
+ [3.0.1]: https://github.com/amro/gibbon/compare/v3.0.0...v3.0.1
71
+ [3.0.0]: https://github.com/amro/gibbon/compare/v2.2.5...v3.0.0
72
+ [2.2.5]: https://github.com/amro/gibbon/compare/v2.2.4...v2.2.5
73
+ [2.2.4]: https://github.com/amro/gibbon/compare/v2.2.2...v2.2.4
74
+ [2.2.3]: https://github.com/amro/gibbon/compare/v2.2.2...v2.2.3
75
+ [2.2.2]: https://github.com/amro/gibbon/compare/v2.2.1...v2.2.2
76
+ [2.2.1]: https://github.com/amro/gibbon/compare/v2.2.0...v2.2.1
77
+ [2.2.0]: https://github.com/amro/gibbon/compare/v2.1.3...v2.2.0
78
+ [2.1.3]: https://github.com/amro/gibbon/compare/v2.1.2...v2.1.3
79
+ [2.1.2]: https://github.com/amro/gibbon/compare/v2.1.1...v2.1.2
80
+ [2.1.1]: https://github.com/amro/gibbon/compare/v2.1.0...v2.1.1
81
+ [2.1.0]: https://github.com/amro/gibbon/compare/v2.0.0...v2.1.0
58
82
  [2.0.0]: https://github.com/amro/gibbon/compare/v1.2.0...v2.0.0
59
83
  [1.2.0]: https://github.com/amro/gibbon/compare/v1.1.5...v1.2.0
60
- [1.1.5]: https://github.com/amro/gibbon/compare/v1.1.5...v1.1.4
84
+ [1.1.6]: https://github.com/amro/gibbon/compare/v1.1.5...v1.1.6
85
+ [1.1.5]: https://github.com/amro/gibbon/compare/v1.1.4...v1.1.5
61
86
  [1.1.4]: https://github.com/amro/gibbon/compare/v1.1.3...v1.1.4
@@ -6,10 +6,10 @@ Gibbon is an API wrapper for MailChimp's [API](http://kb.mailchimp.com/api/).
6
6
  [![Dependency Status](https://gemnasium.com/amro/gibbon.svg)](https://gemnasium.com/amro/gibbon)
7
7
  ##Important Notes
8
8
 
9
- Gibbon now targets MailChimp API 3.0, which is substantially different from the previous API. Please use Gibbon 1.1.x if you need to use API 2.0.
10
-
11
9
  Please read MailChimp's [Getting Started Guide](http://kb.mailchimp.com/api/article/api-3-overview).
12
10
 
11
+ Gibbon 3.0.0+ returns a `Gibbon::Response` instead of the response body directly. `Gibbon::Response` exposes the parsed response `body` and `headers`.
12
+
13
13
  ##Installation
14
14
 
15
15
  $ gem install gibbon
@@ -20,7 +20,7 @@ A MailChimp account and API key. You can see your API keys [here](http://admin.m
20
20
 
21
21
  ##Usage
22
22
 
23
- First, create a *one-time use instance* of Gibbon::Request:
23
+ First, create a *one-time use instance* of `Gibbon::Request`:
24
24
 
25
25
  ```ruby
26
26
  gibbon = Gibbon::Request.new(api_key: "your_api_key")
@@ -50,12 +50,14 @@ gibbon.lists.retrieve(headers: {"SomeHeader": "SomeHeaderValue"}, params: {"quer
50
50
 
51
51
  Of course, `body` is only supported on `create`, `update`, and `upsert` calls. Those map to HTTP `POST`, `PATCH`, and `PUT` verbs respectively.
52
52
 
53
- You can set `api_key`, `timeout`, and `open_timeout` globally:
53
+ You can set `api_key`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, and `debug` globally:
54
54
 
55
55
  ```ruby
56
56
  Gibbon::Request.api_key = "your_api_key"
57
57
  Gibbon::Request.timeout = 15
58
58
  Gibbon::Request.open_timeout = 15
59
+ Gibbon::Request.symbolize_keys = true
60
+ Gibbon::Request.debug = false
59
61
  ```
60
62
 
61
63
  For example, you could set the values above in an `initializer` file in your `Rails` app (e.g. your\_app/config/initializers/gibbon.rb).
@@ -201,7 +203,7 @@ This will create a new batch job and return a Batch response. The response will
201
203
  gibbon.batches(batch_id).retrieve
202
204
  ```
203
205
 
204
- ###### Response
206
+ ###### Response Body (i.e. `response.body`)
205
207
  ```ruby
206
208
  {
207
209
  "id"=>"0ca62e43cc",
@@ -332,7 +334,7 @@ So how do we get the interest IDs? When you query the API for a specific list me
332
334
  gibbon.lists(list_id).members(member_id).retrieve
333
335
  ```
334
336
 
335
- The response looks someting like this (unrelated things removed):
337
+ The response body (i.e. `response.body`) looks someting like this (unrelated things removed):
336
338
 
337
339
  ```ruby
338
340
  {"id"=>"...", "email_address"=>"...", ..., "interests"=>{"3def637141"=>true, "f7cc4ee841"=>false, "fcdc951b9f"=>false, "3daf3cf27d"=>true, "293a3703ed"=>false, "72370e0d1f"=>false, "d434d21a1c"=>false, "bdb1ff199f"=>false, "a54e78f203"=>false, "c4527fd018"=>false} ...}
@@ -344,7 +346,7 @@ The API returns a map of interest ID to boolean value. Now we to get interest de
344
346
  gibbon.lists(list_id).interest_categories.retrieve
345
347
  ```
346
348
 
347
- To get a list of interest categories. That gives us something like:
349
+ To get a list of interest categories. That gives us something like (again, this is the `response.body`):
348
350
 
349
351
  ```ruby
350
352
  {"list_id"=>"...", "categories"=>[{"list_id"=>"...", "id"=>"0ace7aa498", "title"=>"Food Preferences", ...}] ...}
@@ -396,7 +398,7 @@ gibbon = Gibbon::Request.new(api_key: "your_api_key", faraday_adapter: :net_http
396
398
 
397
399
  ### Migrating from Gibbon 1.x
398
400
 
399
- Gibbon 2.x has different syntax from version 1.x. This is because Gibbon maps to MailChimp's API and because version 3 of the API is quite different from version 2. First, the name of the primary class has changed from `API` to `Request`. And the way you pass an API key during initialization is different. A few examples below.
401
+ Gibbon 2.x+ exposes a different API from version 1.x. This is because Gibbon maps to MailChimp's API and because version 3 of the API is quite different from version 2. First, the name of the primary class has changed from `API` to `Request`. And the way you pass an API key during initialization is different. A few examples below.
400
402
 
401
403
  #### Initialization
402
404
 
@@ -406,7 +408,7 @@ Gibbon 1.x:
406
408
  gibbon = Gibbon::API.new("your_api_key")
407
409
  ```
408
410
 
409
- Gibbon 2.x:
411
+ Gibbon 2.x+:
410
412
 
411
413
  ```ruby
412
414
  gibbon = Gibbon::Request.new(api_key: "your_api_key")
@@ -422,7 +424,7 @@ Gibbon 1.x:
422
424
  gibbon.lists.list
423
425
  ```
424
426
 
425
- Gibbon 2.x:
427
+ Gibbon 2.x+:
426
428
 
427
429
  ```ruby
428
430
  gibbon.lists.retrieve
@@ -436,7 +438,7 @@ Gibbon 1.x:
436
438
  gibbon.lists.members({:id => list_id})
437
439
  ```
438
440
 
439
- Gibbon 2.x:
441
+ Gibbon 2.x+:
440
442
 
441
443
  ```ruby
442
444
  gibbon.lists(list_id).members.retrieve
@@ -450,7 +452,7 @@ Gibbon 1.x:
450
452
  gibbon.lists.subscribe({:id => list_id, :email => {:email => "foo@bar.com"}, :merge_vars => {:FNAME => "Bob", :LNAME => "Smith"}})
451
453
  ```
452
454
 
453
- Gibbon 2.x:
455
+ Gibbon 2.x+:
454
456
 
455
457
  ```ruby
456
458
  gibbon.lists(list_id).members.create(body: {email_address: "foo@bar.com", status: "subscribed", merge_fields: {FNAME: "Bob", LNAME: "Smith"}})
@@ -462,5 +464,5 @@ Thanks to everyone who has [contributed](https://github.com/amro/gibbon/contribu
462
464
 
463
465
  ## Copyright
464
466
 
465
- * Copyright (c) 2010-2016 Amro Mousa. See LICENSE.txt for details.
466
- * MailChimp (c) 2001-2016 The Rocket Science Group.
467
+ * Copyright (c) 2010-2017 Amro Mousa. See LICENSE.txt for details.
468
+ * MailChimp (c) 2001-2017 The Rocket Science Group.
@@ -3,10 +3,12 @@ require 'multi_json'
3
3
  require 'cgi'
4
4
  require 'logger'
5
5
 
6
+ require 'gibbon/gibbon_helpers'
6
7
  require 'gibbon/gibbon_error'
7
8
  require 'gibbon/mailchimp_error'
8
9
  require 'gibbon/request'
9
10
  require 'gibbon/api_request'
11
+ require 'gibbon/response'
10
12
 
11
13
  module Gibbon
12
14
  end
@@ -1,5 +1,7 @@
1
1
  module Gibbon
2
2
  class APIRequest
3
+ include Helpers
4
+
3
5
  def initialize(builder: nil)
4
6
  @request_builder = builder
5
7
  end
@@ -11,7 +13,7 @@ module Gibbon
11
13
  response = self.rest_client.post do |request|
12
14
  configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body))
13
15
  end
14
- parse_response(response.body)
16
+ parse_response(response)
15
17
  rescue => e
16
18
  handle_error(e)
17
19
  end
@@ -24,7 +26,7 @@ module Gibbon
24
26
  response = self.rest_client.patch do |request|
25
27
  configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body))
26
28
  end
27
- parse_response(response.body)
29
+ parse_response(response)
28
30
  rescue => e
29
31
  handle_error(e)
30
32
  end
@@ -37,7 +39,7 @@ module Gibbon
37
39
  response = self.rest_client.put do |request|
38
40
  configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body))
39
41
  end
40
- parse_response(response.body)
42
+ parse_response(response)
41
43
  rescue => e
42
44
  handle_error(e)
43
45
  end
@@ -50,7 +52,7 @@ module Gibbon
50
52
  response = self.rest_client.get do |request|
51
53
  configure_request(request: request, params: params, headers: headers)
52
54
  end
53
- parse_response(response.body)
55
+ parse_response(response)
54
56
  rescue => e
55
57
  handle_error(e)
56
58
  end
@@ -63,7 +65,7 @@ module Gibbon
63
65
  response = self.rest_client.delete do |request|
64
66
  configure_request(request: request, params: params, headers: headers)
65
67
  end
66
- parse_response(response.body)
68
+ parse_response(response)
67
69
  rescue => e
68
70
  handle_error(e)
69
71
  end
@@ -100,7 +102,7 @@ module Gibbon
100
102
  def symbolize_keys
101
103
  @request_builder.symbolize_keys
102
104
  end
103
-
105
+
104
106
  # Helpers
105
107
 
106
108
  def handle_error(error)
@@ -151,14 +153,16 @@ module Gibbon
151
153
  client
152
154
  end
153
155
 
154
- def parse_response(response_body)
156
+ def parse_response(response)
155
157
  parsed_response = nil
156
158
 
157
- if response_body && !response_body.empty?
159
+ if response.body && !response.body.empty?
158
160
  begin
159
- parsed_response = MultiJson.load(response_body, symbolize_keys: symbolize_keys)
161
+ headers = response.headers
162
+ body = MultiJson.load(response.body, symbolize_keys: symbolize_keys)
163
+ parsed_response = Response.new(headers: headers, body: body)
160
164
  rescue MultiJson::ParseError
161
- error = MailChimpError.new("Unparseable response: #{response_body}")
165
+ error = MailChimpError.new("Unparseable response: #{response.body}")
162
166
  error.title = "UNPARSEABLE_RESPONSE"
163
167
  error.status_code = 500
164
168
  raise error
@@ -180,20 +184,8 @@ module Gibbon
180
184
  end
181
185
 
182
186
  def base_api_url
183
- computed_api_endpoint = "https://#{get_data_center_from_api_key}api.mailchimp.com"
187
+ computed_api_endpoint = "https://#{get_data_center_from_api_key(self.api_key)}api.mailchimp.com"
184
188
  "#{self.api_endpoint || computed_api_endpoint}/3.0/"
185
189
  end
186
-
187
- def get_data_center_from_api_key
188
- # Return an empty string for invalid API keys so Gibbon hits the main endpoint
189
- data_center = ""
190
-
191
- if self.api_key && self.api_key["-"]
192
- # Add a period since the data_center is a subdomain and it keeps things dry
193
- data_center = "#{self.api_key.split('-').last}."
194
- end
195
-
196
- data_center
197
- end
198
190
  end
199
191
  end
@@ -0,0 +1,15 @@
1
+ module Gibbon
2
+ module Helpers
3
+ def get_data_center_from_api_key(api_key)
4
+ # Return an empty string for invalid API keys so Gibbon hits the main endpoint
5
+ data_center = ""
6
+
7
+ if api_key && api_key["-"]
8
+ # Add a period since the data_center is a subdomain and it keeps things dry
9
+ data_center = "#{api_key.split('-').last}."
10
+ end
11
+
12
+ data_center
13
+ end
14
+ end
15
+ end
@@ -14,9 +14,9 @@ module Gibbon
14
14
  @open_timeout = open_timeout || self.class.open_timeout || DEFAULT_OPEN_TIMEOUT
15
15
  @proxy = proxy || self.class.proxy || ENV['MAILCHIMP_PROXY']
16
16
  @faraday_adapter = faraday_adapter || Faraday.default_adapter
17
- @symbolize_keys = symbolize_keys
17
+ @symbolize_keys = symbolize_keys || self.class.symbolize_keys || false
18
+ @debug = debug || self.class.debug || false
18
19
  @logger = logger || self.class.logger || ::Logger.new(STDOUT)
19
- @debug = debug
20
20
  end
21
21
 
22
22
  def method_missing(method, *args)
@@ -76,10 +76,10 @@ module Gibbon
76
76
  end
77
77
 
78
78
  class << self
79
- attr_accessor :api_key, :timeout, :open_timeout, :api_endpoint, :proxy, :logger
79
+ attr_accessor :api_key, :timeout, :open_timeout, :api_endpoint, :proxy, :faraday_adapter, :symbolize_keys, :debug, :logger
80
80
 
81
81
  def method_missing(sym, *args, &block)
82
- new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, open_timeout: self.open_timeout, proxy: self.proxy, logger: self.logger).send(sym, *args, &block)
82
+ new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, logger: self.logger).send(sym, *args, &block)
83
83
  end
84
84
  end
85
85
  end
@@ -0,0 +1,10 @@
1
+ module Gibbon
2
+ class Response
3
+ attr_accessor :body, :headers
4
+
5
+ def initialize(body: {}, headers: {})
6
+ @body = body
7
+ @headers = headers
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Gibbon
2
- VERSION = "2.2.5"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -102,6 +102,10 @@ describe Gibbon do
102
102
  expect(@gibbon.symbolize_keys).to be true
103
103
  end
104
104
 
105
+ it "sets symbolize_keys in the constructor" do
106
+ @gibbon = Gibbon::Request.new(symbolize_keys: true)
107
+ expect(@gibbon.symbolize_keys).to be true
108
+ end
105
109
  it "debug false by default" do
106
110
  @gibbon = Gibbon::Request.new
107
111
  expect(@gibbon.debug).to be false
@@ -123,7 +127,6 @@ describe Gibbon do
123
127
  expect(@gibbon.logger).to be_a Logger
124
128
  end
125
129
 
126
-
127
130
  end
128
131
 
129
132
  describe "build api url" do
@@ -131,7 +134,6 @@ describe Gibbon do
131
134
  Gibbon::APIRequest.send(:public, *Gibbon::APIRequest.protected_instance_methods)
132
135
 
133
136
  @gibbon = Gibbon::Request.new
134
- @url = "https://api.mailchimp.com/3.0/lists/"
135
137
  end
136
138
 
137
139
  it "doesn't allow empty api key" do
@@ -170,6 +172,10 @@ describe Gibbon do
170
172
  Gibbon::Request.timeout = 15
171
173
  Gibbon::Request.api_endpoint = 'https://us6.api.mailchimp.com'
172
174
  Gibbon::Request.logger = logger
175
+ Gibbon::Request.proxy = "http://1234.com"
176
+ Gibbon::Request.symbolize_keys = true
177
+ Gibbon::Request.faraday_adapter = :net_http
178
+ Gibbon::Request.debug = true
173
179
  end
174
180
 
175
181
  after do
@@ -177,6 +183,10 @@ describe Gibbon do
177
183
  Gibbon::Request.timeout = nil
178
184
  Gibbon::Request.api_endpoint = nil
179
185
  Gibbon::Request.logger = nil
186
+ Gibbon::Request.proxy = nil
187
+ Gibbon::Request.symbolize_keys = nil
188
+ Gibbon::Request.faraday_adapter = nil
189
+ Gibbon::Request.debug = nil
180
190
  end
181
191
 
182
192
  it "set api key on new instances" do
@@ -192,6 +202,22 @@ describe Gibbon do
192
202
  expect(Gibbon::Request.new.api_endpoint).to eq(Gibbon::Request.api_endpoint)
193
203
  end
194
204
 
205
+ it "set proxy on new instances" do
206
+ expect(Gibbon::Request.new.proxy).to eq(Gibbon::Request.proxy)
207
+ end
208
+
209
+ it "set symbolize_keys on new instances" do
210
+ expect(Gibbon::Request.new.symbolize_keys).to eq(Gibbon::Request.symbolize_keys)
211
+ end
212
+
213
+ it "set debug on new instances" do
214
+ expect(Gibbon::Request.new.debug).to eq(Gibbon::Request.debug)
215
+ end
216
+
217
+ it "set faraday_adapter on new instances" do
218
+ expect(Gibbon::Request.new.faraday_adapter).to eq(Gibbon::Request.faraday_adapter)
219
+ end
220
+
195
221
  it "set logger on new instances" do
196
222
  expect(Gibbon::Request.new.logger).to eq(logger)
197
223
  end
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.5
4
+ version: 3.0.1
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-12-24 00:00:00.000000000 Z
11
+ date: 2017-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -99,8 +99,10 @@ files:
99
99
  - lib/gibbon.rb
100
100
  - lib/gibbon/api_request.rb
101
101
  - lib/gibbon/gibbon_error.rb
102
+ - lib/gibbon/gibbon_helpers.rb
102
103
  - lib/gibbon/mailchimp_error.rb
103
104
  - lib/gibbon/request.rb
105
+ - lib/gibbon/response.rb
104
106
  - lib/gibbon/version.rb
105
107
  - spec/gibbon/api_request_spec.rb
106
108
  - spec/gibbon/gibbon_spec.rb