gibbon 1.0.3 → 1.0.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/gibbon.gemspec +1 -1
- data/lib/gibbon/api.rb +6 -6
- data/lib/gibbon/api_category.rb +10 -10
- data/lib/gibbon/export.rb +7 -7
- data/spec/gibbon/gibbon_spec.rb +3 -7
- 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: 179ae4117301bfcbfb7d78011c395df230568bb2
|
4
|
+
data.tar.gz: bd2ffd6e9f3ae5d5fef1f739589645440856f3a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08d20f09120b756973c4bc271618f373898c0f24e0825e008057c2fafa41a8d06134ae57ed73951e7fbc986f3daeadde639136274819f3214bec15954a0e68ba
|
7
|
+
data.tar.gz: 393e9e3796276fcb4164292eadc9080bc919302093e0e5dad5d85762051ac39eb7b50e180619db3ee2f41566fbe9b064a56207c42e59966c4c14a9d1865cac6d
|
data/gibbon.gemspec
CHANGED
data/lib/gibbon/api.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Gibbon
|
2
2
|
class API
|
3
3
|
attr_accessor :api_key, :api_endpoint, :timeout, :throws_exceptions
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(api_key = nil, default_parameters = {})
|
6
6
|
@api_key = api_key || self.class.api_key || ENV['MAILCHIMP_API_KEY']
|
7
7
|
@api_key = @api_key.strip if @api_key
|
@@ -9,14 +9,14 @@ module Gibbon
|
|
9
9
|
@api_endpoint = default_parameters.delete(:api_endpoint) || self.class.api_endpoint
|
10
10
|
@timeout = default_parameters.delete(:timeout) || self.class.timeout
|
11
11
|
@throws_exceptions = default_parameters.has_key?(:throws_exceptions) ? default_parameters.delete(:throws_exceptions) : self.class.throws_exceptions
|
12
|
-
|
13
|
-
@default_params = {apikey
|
12
|
+
|
13
|
+
@default_params = {:apikey => @api_key}.merge(default_parameters)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def get_exporter
|
17
17
|
Export.new(@api_key, @default_params)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def method_missing(method, *args)
|
21
21
|
api = APICategory.new(method.to_s, @api_key, @timeout, @throws_exceptions, @api_endpoint, @default_params)
|
22
22
|
api.api_endpoint = @api_endpoint if @api_endpoint
|
@@ -27,7 +27,7 @@ module Gibbon
|
|
27
27
|
attr_accessor :api_key, :timeout, :throws_exceptions, :api_endpoint
|
28
28
|
|
29
29
|
def method_missing(sym, *args, &block)
|
30
|
-
new(self.api_key, {api_endpoint
|
30
|
+
new(self.api_key, {:api_endpoint => self.api_endpoint, :timeout => self.timeout, :throws_exceptions => self.throws_exceptions}).send(sym, *args, &block)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/gibbon/api_category.rb
CHANGED
@@ -7,7 +7,7 @@ module Gibbon
|
|
7
7
|
default_timeout 30
|
8
8
|
|
9
9
|
attr_accessor :category_name, :api_key, :api_endpoint, :timeout, :throws_exceptions, :default_params
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(category_name, api_key, timeout, throws_exceptions, api_endpoint, default_params)
|
12
12
|
@category_name = category_name
|
13
13
|
@api_key = api_key
|
@@ -21,11 +21,11 @@ module Gibbon
|
|
21
21
|
|
22
22
|
def call(method, params = {})
|
23
23
|
api_url = base_api_url + method
|
24
|
-
params = @default_params.merge(params).merge({apikey
|
25
|
-
response = self.class.post(api_url, body
|
26
|
-
|
24
|
+
params = @default_params.merge(params).merge({:apikey => @api_key})
|
25
|
+
response = self.class.post(api_url, :body => MultiJson.dump(params), :timeout => @timeout)
|
26
|
+
|
27
27
|
parsed_response = nil
|
28
|
-
|
28
|
+
|
29
29
|
if (response.body)
|
30
30
|
parsed_response = MultiJson.load(response.body)
|
31
31
|
|
@@ -38,13 +38,13 @@ module Gibbon
|
|
38
38
|
|
39
39
|
parsed_response
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def method_missing(method, *args)
|
43
43
|
# To support underscores, we replace them with hyphens when calling the API
|
44
44
|
method = method.to_s.gsub("_", "-").downcase
|
45
45
|
call("#{@category_name}/#{method}", *args)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def send(*args)
|
49
49
|
if ((args.length > 0) && args[0].is_a?(Hash))
|
50
50
|
method_missing(:send, args[0])
|
@@ -52,7 +52,7 @@ module Gibbon
|
|
52
52
|
__send__(args)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def set_instance_defaults
|
57
57
|
@timeout = (API.timeout || 30) if @timeout.nil?
|
58
58
|
# Two lines because the class variable could be false and (false || true) is always true
|
@@ -63,7 +63,7 @@ module Gibbon
|
|
63
63
|
def api_key=(value)
|
64
64
|
@api_key = value.strip if value
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def should_raise_for_response?(response)
|
68
68
|
@throws_exceptions && response.is_a?(Hash) && response["error"]
|
69
69
|
end
|
@@ -88,4 +88,4 @@ module Gibbon
|
|
88
88
|
data_center
|
89
89
|
end
|
90
90
|
end
|
91
|
-
end
|
91
|
+
end
|
data/lib/gibbon/export.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Gibbon
|
2
2
|
class Export < APICategory
|
3
|
-
|
3
|
+
|
4
4
|
def initialize(api_key = nil, default_params = {})
|
5
5
|
@api_key = api_key
|
6
6
|
@default_params = default_params
|
@@ -16,13 +16,13 @@ module Gibbon
|
|
16
16
|
|
17
17
|
def call(method, params = {})
|
18
18
|
api_url = export_api_url + method + "/"
|
19
|
-
params = @default_params.merge(params).merge({apikey
|
20
|
-
response = self.class.post(api_url, body
|
19
|
+
params = @default_params.merge(params).merge({:apikey => @api_key})
|
20
|
+
response = self.class.post(api_url, :body => MultiJson.dump(params), :timeout => @timeout)
|
21
21
|
|
22
22
|
lines = response.body.lines
|
23
23
|
if @throws_exceptions
|
24
24
|
first_line = MultiJson.load(lines.first) if lines.first
|
25
|
-
|
25
|
+
|
26
26
|
if should_raise_for_response?(first_line)
|
27
27
|
error = MailChimpError.new("MailChimp Export API Error: #{first_line["error"]} (code #{first_line["code"]})")
|
28
28
|
error.code = first_line["code"]
|
@@ -32,7 +32,7 @@ module Gibbon
|
|
32
32
|
|
33
33
|
lines
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def set_instance_defaults
|
37
37
|
super
|
38
38
|
@api_key = self.class.api_key if @api_key.nil?
|
@@ -57,8 +57,8 @@ module Gibbon
|
|
57
57
|
attr_accessor :api_key, :timeout, :throws_exceptions
|
58
58
|
|
59
59
|
def method_missing(sym, *args, &block)
|
60
|
-
new(self.api_key, {timeout
|
60
|
+
new(self.api_key, {:timeout => self.timeout, :throws_exceptions => self.throws_exceptions}).send(sym, *args, &block)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
data/spec/gibbon/gibbon_spec.rb
CHANGED
@@ -184,16 +184,14 @@ describe Gibbon do
|
|
184
184
|
it "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
|
185
185
|
@gibbon.throws_exceptions = true
|
186
186
|
Gibbon::APICategory.stub(:post).and_return(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
|
187
|
-
expect(
|
188
|
-
@gibbon.say.hello
|
189
|
-
}).to raise_error(Gibbon::MailChimpError)
|
187
|
+
expect {@gibbon.say.hello}.to raise_error(Gibbon::MailChimpError)
|
190
188
|
end
|
191
189
|
|
192
190
|
it "not raise exception if the api returns no response body" do
|
193
191
|
Gibbon::APICategory.stub(:post).and_return(Struct.new(:body).new(nil))
|
194
192
|
expect(@gibbon.say.hello).to be_nil
|
195
193
|
end
|
196
|
-
|
194
|
+
|
197
195
|
it "can send a campaign" do
|
198
196
|
Gibbon::APICategory.stub(:post).and_return(Struct.new(:body).new(MultiJson.dump({"cid" => "1234567"})))
|
199
197
|
expect(@gibbon.campaigns.send({"cid" => "1234567"})).to eq({"cid" => "1234567"})
|
@@ -234,9 +232,7 @@ describe Gibbon do
|
|
234
232
|
reply = Struct.new(:body).new MultiJson.dump({'error' => 'bad things', 'code' => '123'})
|
235
233
|
Gibbon::Export.stub(:post).and_return reply
|
236
234
|
|
237
|
-
expect(
|
238
|
-
@gibbon.say_hello(@body)
|
239
|
-
}).to raise_error(Gibbon::MailChimpError)
|
235
|
+
expect {@gibbon.say_hello(@body)}.to raise_error(Gibbon::MailChimpError)
|
240
236
|
end
|
241
237
|
|
242
238
|
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.0.
|
4
|
+
version: 1.0.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: 2013-
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|