Skip to content

Commit

Permalink
remove addressable since current version doesn't fix encoding issue. …
Browse files Browse the repository at this point in the history
…temporarily monkeypatch HTTParty until new Addressable is released.
  • Loading branch information
amro committed Dec 6, 2011
1 parent b51d2bb commit 022db41
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -4,7 +4,6 @@ gem "json", "> 1.4.0"
gem "httparty", "> 0.6.0"
gem "activesupport", ">= 2.3.14"
gem "rdoc"
gem "addressable"

group :development, :test do
gem "shoulda", ">= 0"
Expand Down
40 changes: 36 additions & 4 deletions lib/gibbon.rb
Expand Up @@ -2,7 +2,6 @@
require 'httparty'
require 'json'
require 'cgi'
require 'addressable/uri'

class Gibbon
include HTTParty
Expand Down Expand Up @@ -84,9 +83,7 @@ def export_api_url

def call(method, params = {})
api_url = export_api_url + method + "/"
uri = Addressable::URI.new
uri.query_values = @default_params.merge(params)
response = self.class.post(api_url, :body => uri.query, :timeout => @timeout)
response = self.class.post(api_url, :body => params, :timeout => @timeout)

This comment has been minimized.

Copy link
@daveworth

daveworth Dec 6, 2011

Contributor

insert a params = @default_params.merge(params) here and you'll be golden.

This comment has been minimized.

Copy link
@amro

amro Dec 6, 2011

Author Owner

Ah, definitely didn't mean to clobber that. Fixed in subsequent commit. Good catch!


lines = response.body.lines
if @throws_exceptions
Expand All @@ -97,3 +94,38 @@ def call(method, params = {})
lines
end
end

module HTTParty
module HashConversions
# @param key<Object> The key for the param.
# @param value<Object> The value for the param.
#
# @return <String> This key value pair as a param
#
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
def self.normalize_param(key, value)
param = ''
stack = []

if value.is_a?(Array)
param << Hash[*(0...value.length).to_a.zip(value).flatten].map {|i,element| normalize_param("#{key}[#{i}]", element)}.join
elsif value.is_a?(Hash)
stack << [key,value]
else
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
end

stack.each do |parent, hash|
hash.each do |key, value|
if value.is_a?(Hash)
stack << ["#{parent}[#{key}]", value]
else
param << normalize_param("#{parent}[#{key}]", value)
end
end
end

param
end
end
end
5 changes: 1 addition & 4 deletions test/test_gibbon.rb
@@ -1,7 +1,6 @@
require 'helper'
require 'cgi'
require 'ruby-debug'
require 'addressable/uri'

class TestGibbon < Test::Unit::TestCase

Expand Down Expand Up @@ -161,9 +160,7 @@ class TestGibbon < Test::Unit::TestCase
@api_key = "TESTKEY-us2"
@gibbon = GibbonExport.new(@api_key)

uri = Addressable::URI.new
uri.query_values = @body
params = {:body => uri.query, :timeout => nil}
params = {:body => @body, :timeout => nil}

url = @url.gsub('us1', 'us2') + "sayHello/"
GibbonExport.expects(:post).with(url, params).returns(@returns)
Expand Down

0 comments on commit 022db41

Please sign in to comment.