1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Added to_s when doing Hash#to_param so that numbers don't throw error when then get encoded.

This commit is contained in:
John Nunemaker 2008-12-06 23:54:40 -05:00
parent 0b5579783a
commit 05c388dc72
4 changed files with 8 additions and 7 deletions

View file

@ -1,14 +1,14 @@
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty') require File.join(dir, 'httparty')
require 'pp'
class Rubyurl class Rubyurl
include HTTParty include HTTParty
base_uri 'rubyurl.com' base_uri 'rubyurl.com'
def self.shorten( website_url ) def self.shorten( website_url )
xml = post('/api/links.json', :query => {'link[website_url]' => website_url}) post( '/api/links.json', :query => { :link => { :website_url => website_url } } )
xml['link'] && xml['link']['permalink']
end end
end end
puts Rubyurl.shorten( 'http://istwitterdown.com/' ).inspect pp Rubyurl.shorten( 'http://istwitterdown.com/' )

View file

@ -28,4 +28,4 @@ twitter = Twitter.new(config['email'], config['password'])
pp twitter.timeline pp twitter.timeline
# pp twitter.timeline(:friends, :query => {:since_id => 868482746}) # pp twitter.timeline(:friends, :query => {:since_id => 868482746})
# pp twitter.timeline(:friends, :query => 'since_id=868482746') # pp twitter.timeline(:friends, :query => 'since_id=868482746')
pp twitter.post('this is a test of 0.2.0') # pp twitter.post('this is a test of 0.2.0')

View file

@ -6,4 +6,5 @@ class Rep
include HTTParty include HTTParty
end end
puts Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544').inspect pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})

View file

@ -322,7 +322,7 @@ class Hash
elsif value.is_a?(Hash) elsif value.is_a?(Hash)
stack << [key,value] stack << [key,value]
else else
param << "#{key}=#{URI.encode(value)}&" param << "#{key}=#{URI.encode(value.to_s)}&"
end end
stack.each do |parent, hash| stack.each do |parent, hash|