Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove addressable since current version doesn't fix encoding issue. …
…temporarily monkeypatch HTTParty until new Addressable is released.
- Loading branch information
Showing
3 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
require 'httparty' | ||
require 'json' | ||
require 'cgi' | ||
require 'addressable/uri' | ||
|
||
class Gibbon | ||
include HTTParty | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
amro
Author
Owner
|
||
|
||
lines = response.body.lines | ||
if @throws_exceptions | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert a
params = @default_params.merge(params)
here and you'll be golden.