Skip to content
Browse files

Convert arrays to json for post data

  • Loading branch information...
1 parent 35a2e4b commit d5bcc4172bac654f618dcefb35584edf4be308e1 @kyledrake kyledrake committed Jun 6, 2011
Showing with 17 additions and 7 deletions.
  1. +1 −1 lib/geoloqi/session.rb
  2. +1 −1 lib/geoloqi/version.rb
  3. +15 −5 spec/geoloqi_spec.rb
View
2 lib/geoloqi/session.rb
@@ -42,7 +42,7 @@ def post(path, body=nil)
def run(meth, path, body=nil)
renew_access_token! if auth[:expires_at] && auth[:expires_at] <= Time.now
- body = body.to_json if body.is_a? Hash
+ body = body.to_json if [Hash, Array].include? body.class
retry_attempt = 0
begin
View
2 lib/geoloqi/version.rb
@@ -1,3 +1,3 @@
module Geoloqi
- VERSION = '0.9.1'
+ VERSION = '0.9.2'
end
View
20 spec/geoloqi_spec.rb
@@ -44,7 +44,7 @@
before do
WebMock.allow_net_connect!
end
-
+
describe 'with nothing passed' do
before do
@session = Geoloqi::Session.new
@@ -60,13 +60,17 @@
@session = Geoloqi::Session.new :access_token => ARGV[2]
end
+ it 'successfully makes mock call with array' do
+ expect { @session.post('play_record_at_geoloqi_hq', [{:artist => 'Television'}])['result'] == 'ok' }
+ end
+
it 'successfully makes call to api with forward slash' do
response = @session.get '/layer/info/Gx'
expect { response['layer_id'] == 'Gx' }
end
it 'successfully makes call to api without forward slash' do
- response = @session.get '/layer/info/Gx'
+ response = @session.get 'layer/info/Gx'
expect { response['layer_id'] == 'Gx' }
end
@@ -157,7 +161,7 @@
:refresh_token => 'refresh_token1234'} }
end
end
-
+
describe 'with config and expired auth' do
before do
@session = Geoloqi::Session.new :config => {:client_id => ARGV[0], :client_secret => ARGV[1]},
@@ -167,7 +171,7 @@
:expires_at => Time.at(0),
:refresh_token => 'refresh_token1234' }
end
-
+
it 'retrieves new access token and retries query if expired' do
WebMock.disable_net_connect!
begin
@@ -208,4 +212,10 @@
stub_request(:get, "https://api.geoloqi.com/1/account/username").
with(:headers => {'Authorization'=>'OAuth access_token4567'}).
to_return(:status => 200,
- :body => {'username' => 'pikachu4lyfe'}.to_json)
+ :body => {'username' => 'pikachu4lyfe'}.to_json)
+
+# This is not a real API call, we're using it to test that arrays are JSON encoded.
+stub_request(:post, "https://api.geoloqi.com/1/play_record_at_geoloqi_hq").
+ with(:body => [{:artist => 'Television'}].to_json).
+ to_return(:status => 200,
+ :body => {'result' => 'ok'}.to_json)

0 comments on commit d5bcc41

Please sign in to comment.
Something went wrong with that request. Please try again.