gibbon 0.4.3 → 0.4.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.

@@ -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 = "0.4.3"
6
+ s.version = "0.4.4"
7
7
  s.authors = ["Amro Mousa"]
8
8
  s.email = ["amromousa@gmail.com"]
9
9
  s.homepage = "http://github.com/amro/gibbon"
@@ -1,5 +1,5 @@
1
1
  require 'httparty'
2
- require 'json'
2
+ require 'multi_json'
3
3
  require 'cgi'
4
4
 
5
5
  class Gibbon
@@ -38,12 +38,12 @@ class Gibbon
38
38
  def call(method, params = {})
39
39
  api_url = base_api_url + method
40
40
  params = @default_params.merge(params)
41
- response = self.class.post(api_url, body: CGI::escape(params.to_json), timeout: @timeout)
42
-
41
+ response = self.class.post(api_url, body: CGI::escape(MultiJson.dump(params)), timeout: @timeout)
42
+
43
43
  # MailChimp API sometimes returns JSON fragments (e.g. true from listSubscribe)
44
44
  # so we parse after adding brackets to create a JSON array so
45
- # JSON.parse succeeds in those cases.
46
- parsed_response = JSON.parse("[#{response.body}]").first
45
+ # parsing succeeds. This also handles the case of an empty response
46
+ parsed_response = MultiJson.load("[#{response.body}]").first
47
47
 
48
48
  if should_raise_for_response?(parsed_response)
49
49
  raise MailChimpError.new("MailChimp API Error: #{parsed_response["error"]} (code #{parsed_response["code"]})")
@@ -121,11 +121,11 @@ class GibbonExport < Gibbon
121
121
  def call(method, params = {})
122
122
  api_url = export_api_url + method + "/"
123
123
  params = @default_params.merge(params)
124
- response = self.class.post(api_url, body: CGI::escape(params.to_json), timeout: @timeout)
124
+ response = self.class.post(api_url, body: CGI::escape(MultiJson.dump(params)), timeout: @timeout)
125
125
 
126
126
  lines = response.body.lines
127
127
  if @throws_exceptions
128
- first_line = JSON.parse(lines.first) if lines.first
128
+ first_line = MultiJson.load(lines.first) if lines.first
129
129
 
130
130
  if should_raise_for_response?(first_line)
131
131
  raise MailChimpError.new("MailChimp Export API Error: #{first_line["error"]} (code #{first_line["code"]})")
@@ -162,7 +162,7 @@ class TestGibbon < Test::Unit::TestCase
162
162
  @gibbon = Gibbon.new(@key)
163
163
  @url = "https://us1.api.mailchimp.com/1.3/?method=sayHello"
164
164
  @body = {"apikey" => @key}
165
- @returns = Struct.new(:body).new(["array", "entries"].to_json)
165
+ @returns = Struct.new(:body).new(MultiJson.dump(["array", "entries"]))
166
166
  end
167
167
 
168
168
  should "produce a good exporter" do
@@ -172,7 +172,7 @@ class TestGibbon < Test::Unit::TestCase
172
172
 
173
173
  should "not throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
174
174
  @gibbon.throws_exceptions = false
175
- Gibbon.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
175
+ Gibbon.stubs(:post).returns(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
176
176
  assert_nothing_raised do
177
177
  @gibbon.say_hello
178
178
  end
@@ -180,7 +180,7 @@ class TestGibbon < Test::Unit::TestCase
180
180
 
181
181
  should "throw exception if configured to and the API replies with a JSON hash containing a key called 'error'" do
182
182
  @gibbon.throws_exceptions = true
183
- Gibbon.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
183
+ Gibbon.stubs(:post).returns(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
184
184
  assert_raise Gibbon::MailChimpError do
185
185
  @gibbon.say_hello
186
186
  end
@@ -198,14 +198,14 @@ class TestGibbon < Test::Unit::TestCase
198
198
  @gibbon = GibbonExport.new(@key)
199
199
  @url = "http://us1.api.mailchimp.com/export/1.0/"
200
200
  @body = {:apikey => @key, :id => "listid"}
201
- @returns = Struct.new(:body).new(["array", "entries"].to_json)
201
+ @returns = Struct.new(:body).new(MultiJson.dump(["array", "entries"]))
202
202
  end
203
203
 
204
204
  should "handle api key with dc" do
205
205
  @api_key = "TESTKEY-us2"
206
206
  @gibbon = GibbonExport.new(@api_key)
207
207
 
208
- params = {:body => CGI::escape(@body.to_json), :timeout => 30}
208
+ params = {:body => CGI::escape(MultiJson.dump(@body)), :timeout => 30}
209
209
 
210
210
  url = @url.gsub('us1', 'us2') + "sayHello/"
211
211
  GibbonExport.expects(:post).with(url, params).returns(@returns)
@@ -214,7 +214,7 @@ class TestGibbon < Test::Unit::TestCase
214
214
 
215
215
  should "not throw exception if the Export API replies with a JSON hash containing a key called 'error'" do
216
216
  @gibbon.throws_exceptions = false
217
- GibbonExport.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things'}.to_json))
217
+ GibbonExport.stubs(:post).returns(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things'})))
218
218
 
219
219
  assert_nothing_raised do
220
220
  @gibbon.say_hello(@body)
@@ -224,7 +224,7 @@ class TestGibbon < Test::Unit::TestCase
224
224
  should "throw exception if configured to and the Export API replies with a JSON hash containing a key called 'error'" do
225
225
  @gibbon.throws_exceptions = true
226
226
  params = {:body => @body, :timeout => 30}
227
- GibbonExport.stubs(:post).returns(Struct.new(:body).new({'error' => 'bad things', 'code' => '123'}.to_json))
227
+ GibbonExport.stubs(:post).returns(Struct.new(:body).new(MultiJson.dump({'error' => 'bad things', 'code' => '123'})))
228
228
 
229
229
  assert_raise Gibbon::MailChimpError do
230
230
  @gibbon.say_hello(@body)
@@ -238,8 +238,8 @@ class TestGibbon < Test::Unit::TestCase
238
238
  def expect_post(expected_url, expected_body, expected_timeout=30)
239
239
  Gibbon.expects(:post).with do |url, opts|
240
240
  url == expected_url &&
241
- JSON.parse(URI::decode(opts[:body])) == expected_body &&
241
+ MultiJson.load(URI::decode(opts[:body])) == expected_body &&
242
242
  opts[:timeout] == expected_timeout
243
- end.returns(Struct.new(:body).new("") )
243
+ end.returns(Struct.new(:body).new(""))
244
244
  end
245
245
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
12
+ date: 2013-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: 2873655008867381541
146
+ hash: -509516147355860148
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements:
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  segments:
154
154
  - 0
155
- hash: 2873655008867381541
155
+ hash: -509516147355860148
156
156
  requirements: []
157
157
  rubyforge_project: gibbon
158
158
  rubygems_version: 1.8.24