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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f00a068a4e2a554c2baba80e7a0a01f934a4714a
4
- data.tar.gz: 96a6a231054b51595e19feeb0c24c31f09078cb5
3
+ metadata.gz: 179ae4117301bfcbfb7d78011c395df230568bb2
4
+ data.tar.gz: bd2ffd6e9f3ae5d5fef1f739589645440856f3a5
5
5
  SHA512:
6
- metadata.gz: 3b95d0ca9fdcb7477c34b8c3aa2ecd1c46715ebd5d41ecd226ea60ef8c57a69d61a135921e9187d8e38800b9040f1a46a928ac8c4fa3147f5115dd885c5ee91d
7
- data.tar.gz: 6fbe89f8c22ca9be5864f5d388fdc9525b8a6636f343f40f2a38b80b36f4e56b515fbb79dcc40bac126029e1ee7fde04032e68c548b9984f8f141e3c35bb1aa0
6
+ metadata.gz: 08d20f09120b756973c4bc271618f373898c0f24e0825e008057c2fafa41a8d06134ae57ed73951e7fbc986f3daeadde639136274819f3214bec15954a0e68ba
7
+ data.tar.gz: 393e9e3796276fcb4164292eadc9080bc919302093e0e5dad5d85762051ac39eb7b50e180619db3ee2f41566fbe9b064a56207c42e59966c4c14a9d1865cac6d
@@ -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.0.3"
6
+ s.version = "1.0.4"
7
7
  s.authors = ["Amro Mousa"]
8
8
  s.email = ["amromousa@gmail.com"]
9
9
  s.homepage = "http://github.com/amro/gibbon"
@@ -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: @api_key}.merge(default_parameters)
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: self.api_endpoint, timeout: self.timeout, throws_exceptions: self.throws_exceptions}).send(sym, *args, &block)
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
@@ -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: @api_key})
25
- response = self.class.post(api_url, body: MultiJson.dump(params), timeout: @timeout)
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
@@ -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: @api_key})
20
- response = self.class.post(api_url, body: MultiJson.dump(params), timeout: @timeout)
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: self.timeout, throws_exceptions: self.throws_exceptions}).send(sym, *args, &block)
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
@@ -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.3
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-09-21 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty