gibbon 2.1.3 → 2.2.0

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: ca357e9533b74ca6b5616efc8e889abecc7b8a11
4
- data.tar.gz: 8967cd26e5356e76bc35524104ce85ae74ef2a90
3
+ metadata.gz: b9bbaffb886d48a6638dad933173180c5fa05a83
4
+ data.tar.gz: 3738e10aac82b774d4e835ef4d920195c08f0989
5
5
  SHA512:
6
- metadata.gz: 78679e70c47bdd67ad5935462b2c5a8b13cb25724721ddfda1a5149458e63cbc77c7436d704d277d944035cce0f1f93396f737ff4ee0f6292c1d1b91d47a9728
7
- data.tar.gz: cd734f687b717a69dbb338fe8120b3f107a1fd7c99a8fc9028974804fcb27077a8e6d9246f9d39a7cb602c957d85b3c91ea900490f381be922b4082d4ae824b8
6
+ metadata.gz: 24b23d7562c0ec6a3b0afc359c2d22e7030438030bddbbec84cc008740e438736fb95f98d419377e91e915073a296a3b82c9f488d7792856deb7dc4530952fe6
7
+ data.tar.gz: 03b4df6bcafa1af1a13694e7dc2a71149a4eb64bb3f43653f006dcb97e7bb0bb346933a2b9e864cc82ac35dcd12b5efa01daea136b2ac632566e04a0cf2c1de7
@@ -1,9 +1,13 @@
1
1
  ## [Unreleased][unreleased]
2
2
 
3
- ## [2.1.3] - 2015-11-05
3
+ ## [2.2.0] - 2015-12-01
4
+ - Adds support for proxies
5
+ - Adds support for faraday_adapters
6
+
7
+ ## [2.1.3] - 2015-11-26
4
8
  - Fixes issue #159, which prevented sending campaigns from working. Thanks to @q3-tech for the bug report.
5
9
 
6
- ## [2.1.2] - 2015-11-05
10
+ ## [2.1.2] - 2015-11-11
7
11
  - Allow Faraday default\_connection\_options to be set
8
12
 
9
13
  ## [2.1.1] - 2015-11-05
@@ -37,23 +37,7 @@ are specified inline and a `CRUD` (`create`, `retrieve`, `update`, `upsert`, or
37
37
 
38
38
  *Please note that `upsert` requires Gibbon version 2.1.0 or newer!*
39
39
 
40
- ```ruby
41
- gibbon.lists.retrieve
42
- ```
43
-
44
- Retrieving a specific list looks like:
45
-
46
- ```ruby
47
- gibbon.lists(list_id).retrieve
48
- ```
49
-
50
- Retrieving a specific list's members looks like:
51
-
52
- ```ruby
53
- gibbon.lists(list_id).members.retrieve
54
- ```
55
-
56
- You can also specify `headers`, `params`, and `body` when calling a `CRUD` method. For example:
40
+ You can specify `headers`, `params`, and `body` when calling a `CRUD` method. For example:
57
41
 
58
42
  ```ruby
59
43
  gibbon.lists.retrieve(headers: {"SomeHeader": "SomeHeaderValue"}, params: {"query_param": "query_param_value"})
@@ -85,23 +69,31 @@ gibbon = Gibbon::Request.new
85
69
  MailChimp's [resource documentation](http://kb.mailchimp.com/api/resources) is a list of available resources. Substitute an underscore if
86
70
  a resource name contains a hyphen.
87
71
 
88
- ### Fetching Campaigns
72
+ ## Examples
73
+
74
+ ### Lists
75
+
76
+ Fetch all lists:
89
77
 
90
78
  ```ruby
91
- campaigns = gb.campaigns.retrieve
79
+ gibbon.lists.retrieve
92
80
  ```
93
81
 
94
- ### Fetching Lists
82
+ Retrieving a specific list looks like:
95
83
 
96
- Similarly, to fetch your lists
84
+ ```ruby
85
+ gibbon.lists(list_id).retrieve
86
+ ```
87
+
88
+ Retrieving a specific list's members looks like:
97
89
 
98
90
  ```ruby
99
- lists = gibbon.lists.retrieve
91
+ gibbon.lists(list_id).members.retrieve
100
92
  ```
101
93
 
102
- ### More Advanced Examples
94
+ ### Subscribers
103
95
 
104
- List subscribers for a list:
96
+ Get all subscribers for a list:
105
97
 
106
98
  ```ruby
107
99
  gibbon.lists(list_id).members.retrieve
@@ -125,17 +117,70 @@ You can also unsubscribe a member from a list:
125
117
  gibbon.lists(list_id).members(member_id).update(body: { status: "unsubscribed" })
126
118
  ```
127
119
 
120
+ ### Campaigns
121
+
122
+ Get all campaigns:
123
+
124
+ ```ruby
125
+ campaigns = gibbon.campaigns.retrieve
126
+ ```
127
+
128
128
  Fetch the number of opens for a campaign
129
129
 
130
130
  ```ruby
131
131
  email_stats = gibbon.reports(campaign_id).retrieve["opens"]
132
132
  ```
133
133
 
134
- Overriding Gibbon's API endpoint (i.e. if using an access token from OAuth and have the `api_endpoint` from the [metadata](http://apidocs.mailchimp.com/oauth2/)):
134
+ Create a new campaign:
135
135
 
136
136
  ```ruby
137
- Gibbon::Request.api_endpoint = "https://us1.api.mailchimp.com"
138
- Gibbon::Request.api_key = your_access_token_or_api_key
137
+ recipients = {
138
+ list_id: list_id,
139
+ segment_opts: {
140
+ saved_segment_id: segment_id
141
+ }
142
+ }
143
+ settings = {
144
+ subject_line: "Subject Line",
145
+ title: "Name of Campaign",
146
+ from_name: "From Name",
147
+ reply_to: "my@email.com"
148
+ }
149
+
150
+ body = {
151
+ type: "regular",
152
+ recipients: recipients,
153
+ settings: settings
154
+ }
155
+
156
+ begin
157
+ gibbon.campaigns.create(body: body)
158
+ rescue Gibbon::MailChimpError => e
159
+ puts "Houston, we have a problem: #{e.message} - #{e.raw_body}"
160
+ end
161
+ ```
162
+
163
+ Add content to a campaign:
164
+
165
+ *(Please note that Mailchimp does not currently support dynamic replacement of mc:edit areas in their drag-and-drop templates using their API. Custom templates [can be used](http://stackoverflow.com/questions/29366766/mailchimp-api-not-replacing-mcedit-content-sections-using-ruby-library) instead.)*
166
+
167
+ ```ruby
168
+ body = {
169
+ template: {
170
+ id: template_id,
171
+ sections: {
172
+ "name-of-mc-edit-area": "Content here"
173
+ }
174
+ }
175
+ }
176
+
177
+ gibbon.campaigns(campaign_id).content.upsert(body: body)
178
+ ```
179
+
180
+ Send a campaign:
181
+
182
+ ```ruby
183
+ gibbon.campaigns(campaign_id).actions.send.create
139
184
  ```
140
185
 
141
186
  ### Interests
@@ -193,6 +238,27 @@ Gibbon raises an error when the API returns an error.
193
238
  Gibbon::MailChimpError has the following attributes: `title`, `detail`, `body`, `raw_body`, `status_code`. Some or all of these may not be
194
239
  available depending on the nature of the error.
195
240
 
241
+ ### Other
242
+
243
+ Overriding Gibbon's API endpoint (i.e. if using an access token from OAuth and have the `api_endpoint` from the [metadata](http://apidocs.mailchimp.com/oauth2/)):
244
+
245
+ ```ruby
246
+ Gibbon::Request.api_endpoint = "https://us1.api.mailchimp.com"
247
+ Gibbon::Request.api_key = your_access_token_or_api_key
248
+ ```
249
+
250
+ You can set an optional proxy url like this (or with an environment variable MAILCHIMP_PROXY):
251
+
252
+ ```ruby
253
+ gibbon.proxy = 'http://your_proxy.com:80'
254
+ ```
255
+
256
+ You can set a different Faraday adapter during initialization:
257
+
258
+ ```ruby
259
+ gibbon = Gibbon::Request.new(api_key: "your_api_key", faraday_adapter: :net_http)
260
+ ```
261
+
196
262
  ### Migrating from Gibbon 1.x
197
263
 
198
264
  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.
@@ -261,5 +327,5 @@ Thanks to everyone who has [contributed](https://github.com/amro/gibbon/contribu
261
327
 
262
328
  ## Copyright
263
329
 
264
- * Copyright (c) 2010-2015 Amro Mousa. See LICENSE.txt for details.
265
- * MailChimp (c) 2001-2015 The Rocket Science Group.
330
+ * Copyright (c) 2010-2016 Amro Mousa. See LICENSE.txt for details.
331
+ * MailChimp (c) 2001-2016 The Rocket Science Group.
@@ -13,9 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{A wrapper for MailChimp API 3.0}
14
14
  s.license = "MIT"
15
15
 
16
- s.post_install_message = "IMPORTANT: Gibbon now targets MailChimp API 3.0, which is very different from API 2.0.\n \
17
- Please install Gibbon 1.2.0 if you need to use API 2.0.\nGibbon's API has changed substantially \
18
- between versions 1.x and 2.x."
16
+ s.post_install_message = "IMPORTANT: Gibbon now targets MailChimp API 3.0, which is very different from API 2.0. Use Gibbon 1.x if you need to target API 2.0."
19
17
 
20
18
  s.rubyforge_project = "gibbon"
21
19
 
@@ -8,4 +8,4 @@ require 'gibbon/request'
8
8
  require 'gibbon/api_request'
9
9
 
10
10
  module Gibbon
11
- end
11
+ end
@@ -16,7 +16,7 @@ module Gibbon
16
16
  handle_error(e)
17
17
  end
18
18
  end
19
-
19
+
20
20
  def patch(params: nil, headers: nil, body: nil)
21
21
  validate_api_key
22
22
 
@@ -42,7 +42,7 @@ module Gibbon
42
42
  handle_error(e)
43
43
  end
44
44
  end
45
-
45
+
46
46
  def get(params: nil, headers: nil)
47
47
  validate_api_key
48
48
 
@@ -55,7 +55,7 @@ module Gibbon
55
55
  handle_error(e)
56
56
  end
57
57
  end
58
-
58
+
59
59
  def delete(params: nil, headers: nil)
60
60
  validate_api_key
61
61
 
@@ -70,20 +70,28 @@ module Gibbon
70
70
  end
71
71
 
72
72
  protected
73
-
73
+
74
74
  # Convenience accessors
75
-
75
+
76
76
  def api_key
77
77
  @request_builder.api_key
78
78
  end
79
-
79
+
80
80
  def api_endpoint
81
81
  @request_builder.api_endpoint
82
82
  end
83
-
83
+
84
84
  def timeout
85
85
  @request_builder.timeout
86
86
  end
87
+
88
+ def proxy
89
+ @request_builder.proxy
90
+ end
91
+
92
+ def adapter
93
+ @request_builder.faraday_adapter
94
+ end
87
95
 
88
96
  # Helpers
89
97
 
@@ -124,9 +132,9 @@ module Gibbon
124
132
  end
125
133
 
126
134
  def rest_client
127
- client = Faraday.new(self.api_url) do |faraday|
135
+ client = Faraday.new(self.api_url, proxy: self.proxy) do |faraday|
128
136
  faraday.response :raise_error
129
- faraday.adapter Faraday.default_adapter
137
+ faraday.adapter adapter
130
138
  end
131
139
  client.basic_auth('apikey', self.api_key)
132
140
  client
@@ -1,15 +1,17 @@
1
1
  module Gibbon
2
2
  class Request
3
- attr_accessor :api_key, :api_endpoint, :timeout
3
+ attr_accessor :api_key, :api_endpoint, :timeout, :proxy, :faraday_adapter
4
4
 
5
5
  DEFAULT_TIMEOUT = 30
6
6
 
7
- def initialize(api_key: nil, api_endpoint: nil, timeout: nil)
7
+ def initialize(api_key: nil, api_endpoint: nil, timeout: nil, proxy: nil, faraday_adapter: nil)
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
11
11
  @api_endpoint = api_endpoint || self.class.api_endpoint
12
12
  @timeout = timeout || self.class.timeout || DEFAULT_TIMEOUT
13
+ @proxy = proxy || self.class.proxy || ENV['MAILCHIMP_PROXY']
14
+ @faraday_adapter = faraday_adapter || Faraday.default_adapter
13
15
  end
14
16
 
15
17
  def method_missing(method, *args)
@@ -19,7 +21,7 @@ module Gibbon
19
21
  @path_parts.flatten!
20
22
  self
21
23
  end
22
-
24
+
23
25
  def send(*args)
24
26
  if args.length == 0
25
27
  method_missing(:send, args)
@@ -27,7 +29,7 @@ module Gibbon
27
29
  __send__(*args)
28
30
  end
29
31
  end
30
-
32
+
31
33
  def path
32
34
  @path_parts.join('/')
33
35
  end
@@ -69,10 +71,10 @@ module Gibbon
69
71
  end
70
72
 
71
73
  class << self
72
- attr_accessor :api_key, :timeout, :api_endpoint
74
+ attr_accessor :api_key, :timeout, :api_endpoint, :proxy
73
75
 
74
76
  def method_missing(sym, *args, &block)
75
- new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout).send(sym, *args, &block)
77
+ new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, proxy: self.proxy).send(sym, *args, &block)
76
78
  end
77
79
  end
78
80
  end
@@ -1,3 +1,3 @@
1
1
  module Gibbon
2
- VERSION = "2.1.3"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -7,32 +7,32 @@ describe Gibbon do
7
7
  Gibbon::APIRequest.send(:public, *Gibbon::APIRequest.protected_instance_methods)
8
8
 
9
9
  @api_key = "123-us1"
10
+ @proxy = 'the_proxy'
10
11
  end
11
12
 
12
13
  it "have no API by default" do
13
14
  @gibbon = Gibbon::Request.new
14
15
  expect(@gibbon.api_key).to be_nil
15
16
  end
16
-
17
- it "set an API key in constructor" do
17
+ it "sets an API key in the constructor" do
18
18
  @gibbon = Gibbon::Request.new(api_key: @api_key)
19
19
  expect(@gibbon.api_key).to eq(@api_key)
20
20
  end
21
21
 
22
- it "set an API key from the 'MAILCHIMP_API_KEY' ENV variable" do
22
+ it "sets an API key from the 'MAILCHIMP_API_KEY' ENV variable" do
23
23
  ENV['MAILCHIMP_API_KEY'] = @api_key
24
24
  @gibbon = Gibbon::Request.new
25
25
  expect(@gibbon.api_key).to eq(@api_key)
26
26
  ENV.delete('MAILCHIMP_API_KEY')
27
27
  end
28
28
 
29
- it "set an API key via setter" do
29
+ it "sets an API key via setter" do
30
30
  @gibbon = Gibbon::Request.new
31
31
  @gibbon.api_key = @api_key
32
32
  expect(@gibbon.api_key).to eq(@api_key)
33
33
  end
34
34
 
35
- it "set timeout and get" do
35
+ it "sets timeout and get" do
36
36
  @gibbon = Gibbon::Request.new
37
37
  timeout = 30
38
38
  @gibbon.timeout = timeout
@@ -52,6 +52,30 @@ describe Gibbon do
52
52
  @gibbon = Gibbon::Request.new(api_key: @api_key, api_endpoint: api_endpoint)
53
53
  expect(api_endpoint).to eq(@gibbon.api_endpoint)
54
54
  end
55
+
56
+ it "has no Proxy url by default" do
57
+ @gibbon = Gibbon::Request.new
58
+ expect(@gibbon.proxy).to be_nil
59
+ end
60
+
61
+ it "sets an proxy url key from the 'MAILCHIMP_PROXY_URL' ENV variable" do
62
+ ENV['MAILCHIMP_PROXY'] = @proxy
63
+ @gibbon = Gibbon::Request.new
64
+ expect(@gibbon.proxy).to eq(@proxy)
65
+ ENV.delete('MAILCHIMP_PROXY')
66
+ end
67
+
68
+ it "sets an API key via setter" do
69
+ @gibbon = Gibbon::Request.new
70
+ @gibbon.proxy = @proxy
71
+ expect(@gibbon.proxy).to eq(@proxy)
72
+ end
73
+
74
+ it "sets an adapter in the constructor" do
75
+ adapter = :em_synchrony
76
+ @gibbon = Gibbon::Request.new(faraday_adapter: adapter)
77
+ expect(@gibbon.faraday_adapter).to eq(adapter)
78
+ end
55
79
  end
56
80
 
57
81
  describe "build api url" do
@@ -117,4 +141,3 @@ describe Gibbon do
117
141
  end
118
142
  end
119
143
  end
120
-
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.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amro Mousa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -110,10 +110,8 @@ homepage: http://github.com/amro/gibbon
110
110
  licenses:
111
111
  - MIT
112
112
  metadata: {}
113
- post_install_message: |-
114
- IMPORTANT: Gibbon now targets MailChimp API 3.0, which is very different from API 2.0.
115
- Please install Gibbon 1.2.0 if you need to use API 2.0.
116
- Gibbon's API has changed substantially between versions 1.x and 2.x.
113
+ post_install_message: 'IMPORTANT: Gibbon now targets MailChimp API 3.0, which is very
114
+ different from API 2.0. Use Gibbon 1.x if you need to target API 2.0.'
117
115
  rdoc_options: []
118
116
  require_paths:
119
117
  - lib