gibbon 1.1.1 → 1.1.2

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: 34d4b58a97f16a89c75bf58613f549aa65254a06
4
- data.tar.gz: e8daf0d12e8f4d180eece626ad64a0740a1a2fb3
3
+ metadata.gz: 5863ce163571867687599035a3efb7ae64f0be27
4
+ data.tar.gz: bc2afd9c27b43999b3fae7e20332af73945305f1
5
5
  SHA512:
6
- metadata.gz: 7b627afea51e05ed36a958982ce2e0cdfab1f8abc013e36dc12850da2c8d05fb37218fa44d90dd97864e9e0daa182ee4c3bb68d704e04f2e46f65929348fbdc8
7
- data.tar.gz: 4b9c3d6718612ba070dd15d156794fde5324d6b9c2717e02e3f5315f519710be6f65f8d0f85c0fd4c33725396bce2f0d2e94fc73dffdce866f58f1153a60f672
6
+ metadata.gz: 6cd38d270b357e015498fb881e2556efb4ea89e1926ef1c81dbb6072eb825d0632b51cd3ce6877465e9daa330f412bcb5f67246185c28e6b05141a898abedb8a
7
+ data.tar.gz: 3c3f56bdbb3654b366ed4ea557f07a7ed986611638a4e679cd312778f461938d3c65478b7fdadcd8e41cc92dd0b020eaed28cc1d1d34c36f36098b1c611843c5
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ before_install: gem install bundler -v 1.5.1
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  platforms :rbx do
4
4
  gem 'rubysl', '~> 2.0'
data/README.markdown CHANGED
@@ -11,7 +11,7 @@ Gibbon now targets MailChimp API 2.0, which is substantially different from API
11
11
  * Supports MailChimp API 2.0 and Export API 1.0
12
12
  * Errors are raised by default since 0.4.x
13
13
  * Timeouts can be specified per request during initialization
14
- * Ruby 1.9.x+ for now. A future version may be Ruby 2.0 only to take advantage of lazy iteration when using the Export API.
14
+ * Ruby 1.9.3+ for now. A future version may be Ruby 2.0 only to take advantage of lazy iteration when using the Export API.
15
15
 
16
16
  ##Installation
17
17
 
@@ -34,13 +34,13 @@ You can set `api_key`, `timeout` and `throws_exceptions` globally:
34
34
  Gibbon::API.api_key = "your_api_key"
35
35
  Gibbon::API.timeout = 15
36
36
  Gibbon::API.throws_exceptions = false
37
-
37
+
38
38
  similarly
39
39
 
40
40
  Gibbon::Export.api_key = "your_api_key"
41
41
  Gibbon::Export.timeout = 15
42
42
  Gibbon::Export.throws_exceptions = false
43
-
43
+
44
44
  For example, you could set the values above in an `initializer` file in your `Rails` app (e.g. your\_app/config/initializers/gibbon.rb).
45
45
 
46
46
  Assuming you've set an `api_key` on Gibbon, you can conveniently make API calls on the class itself:
@@ -97,6 +97,10 @@ Subscribe a member to a list:
97
97
 
98
98
  > Note: This will send a welcome email to the new subscriber
99
99
 
100
+ Here's an example showing pagination. The following code fetches the first page of 100 members subscribed to your list:
101
+
102
+ gb.lists.members({:id => list_id, :opts => {:start => 0, :limit => 100}})
103
+
100
104
  or
101
105
 
102
106
  Batch subscribe members to a list:
@@ -108,15 +112,15 @@ Batch subscribe members to a list:
108
112
  If you want to update the existing members you need to send the boolean update_existing in true
109
113
 
110
114
  gb.lists.batch_subscribe(:id => list_id, :batch => [{:email => {:email => "email1"}, :merge_vars => {:FNAME => "FirstName1", :LNAME => "LastName1"}}], :update_existing => true)
111
-
115
+
112
116
  > Note: The `email` hash can also accept either a unique email id or a list email id. Please see the [lists/batch-subscribe](http://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php) documentation for more information.
113
117
 
114
118
  You can also unsubscribe a member from a list:
115
119
 
116
120
  gb.lists.unsubscribe(:id => list_id, :email => {:email => "user_email"}, :delete_member => true, :send_notify => true)
117
-
118
- > Note: :delete_member defaults to false, meaning the member stays on your mailchimp list as "unsubscribed". See [Api Docs](http://apidocs.mailchimp.com/api/2.0/lists/unsubscribe.php) for details of options.
119
-
121
+
122
+ > Note: :delete_member defaults to false, meaning the member stays on your mailchimp list as "unsubscribed". See [Api Docs](http://apidocs.mailchimp.com/api/2.0/lists/unsubscribe.php) for details of options.
123
+
120
124
  Fetch recipients who opened particular campaign:
121
125
 
122
126
  email_stats = gb.reports.opened({:cid => campaign_id})
@@ -164,8 +168,8 @@ at the bottom of each page. Here's how you might do that:
164
168
 
165
169
  Some API endpoints, like `[lists/batch-subscribe](http://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php)`
166
170
  return errors to let you know that some of your actions failed, but some suceeded. Gibbon will not
167
- raise Gibbon::MailChimpError for these endpoints because the key for the success count varies from endpoint to endpoint.
168
- This makes it difficult to determine whether all of your actions failed in a generic way. **Because of this, you're responsible
171
+ raise Gibbon::MailChimpError for these endpoints because the key for the success count varies from endpoint to endpoint.
172
+ This makes it difficult to determine whether all of your actions failed in a generic way. **Because of this, you're responsible
169
173
  for checking the response body for the `errors` array in these cases.**
170
174
 
171
175
  > Note: In an effort to make Gibbon easier to use, errors are raised automatically as of version 0.4.0.
data/gibbon.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "gibbon"
6
- s.version = "1.1.1"
6
+ s.version = "1.1.2"
7
7
  s.authors = ["Amro Mousa"]
8
8
  s.email = ["amromousa@gmail.com"]
9
9
  s.homepage = "http://github.com/amro/gibbon"
data/lib/gibbon.rb CHANGED
@@ -2,6 +2,7 @@ require 'httparty'
2
2
  require 'multi_json'
3
3
  require 'cgi'
4
4
 
5
+ require 'gibbon/gibbon_error'
5
6
  require 'gibbon/mailchimp_error'
6
7
  require 'gibbon/api_category'
7
8
  require 'gibbon/api'
@@ -20,6 +20,8 @@ module Gibbon
20
20
  end
21
21
 
22
22
  def call(method, params = {})
23
+ ensure_api_key params
24
+
23
25
  api_url = base_api_url + method
24
26
  params = @default_params.merge(params).merge({:apikey => @api_key})
25
27
  headers = params.delete(:headers) || {}
@@ -88,5 +90,14 @@ module Gibbon
88
90
 
89
91
  data_center
90
92
  end
93
+
94
+
95
+ private
96
+
97
+ def ensure_api_key(params)
98
+ unless @api_key || @default_params[:apikey] || params[:apikey]
99
+ raise Gibbon::GibbonError, "You must set an api_key prior to making a call"
100
+ end
101
+ end
91
102
  end
92
103
  end
data/lib/gibbon/export.rb CHANGED
@@ -15,6 +15,8 @@ module Gibbon
15
15
  end
16
16
 
17
17
  def call(method, params = {})
18
+ ensure_api_key params
19
+
18
20
  api_url = export_api_url + method + "/"
19
21
  params = @default_params.merge(params).merge({:apikey => @api_key})
20
22
  response = self.class.post(api_url, :body => MultiJson.dump(params), :timeout => @timeout)
@@ -57,6 +59,15 @@ module Gibbon
57
59
  %w{list ecommOrders ecomm_orders campaignSubscriberActivity campaign_subscriber_activity}.include?(method.to_s) || super
58
60
  end
59
61
 
62
+
63
+ private
64
+
65
+ def ensure_api_key(params)
66
+ unless @api_key || @default_params[:apikey] || params[:apikey]
67
+ raise Gibbon::GibbonError, "You must set an api_key prior to making a call"
68
+ end
69
+ end
70
+
60
71
  class << self
61
72
  attr_accessor :api_key, :timeout, :throws_exceptions
62
73
 
@@ -0,0 +1,3 @@
1
+ module Gibbon
2
+ class GibbonError < StandardError; end
3
+ end
@@ -57,9 +57,8 @@ describe Gibbon do
57
57
  @url = "https://api.mailchimp.com/2.0/say/hello"
58
58
  end
59
59
 
60
- it "handle empty api key" do
61
- expect_post(@url, {"apikey" => nil})
62
- @gibbon.say.hello
60
+ it "doesn't allow empty api key" do
61
+ expect {@gibbon.say.hello}.to raise_error(Gibbon::GibbonError)
63
62
  end
64
63
 
65
64
  it "handle malformed api key" do
@@ -70,7 +69,8 @@ describe Gibbon do
70
69
  end
71
70
 
72
71
  it "handle timeout" do
73
- expect_post(@url, {"apikey" => nil}, 120)
72
+ expect_post(@url, {"apikey" => 'test'}, 120)
73
+ @gibbon.api_key = 'test'
74
74
  @gibbon.timeout=120
75
75
  @gibbon.say.hello
76
76
  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: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amro Mousa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -85,6 +85,7 @@ files:
85
85
  - lib/gibbon/api.rb
86
86
  - lib/gibbon/api_category.rb
87
87
  - lib/gibbon/export.rb
88
+ - lib/gibbon/gibbon_error.rb
88
89
  - lib/gibbon/mailchimp_error.rb
89
90
  - spec/gibbon/gibbon_spec.rb
90
91
  - spec/spec_helper.rb
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project: gibbon
114
- rubygems_version: 2.2.0
115
+ rubygems_version: 2.2.1
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: A wrapper for MailChimp API 2.0 and Export API 1.0