Post parameters

114 views
Skip to first unread message

plot...@googlemail.com

unread,
Oct 27, 2009, 11:58:05 AM10/27/09
to Typhoeus
I am trying to get the post parameters to work but twitter complains
about a missing query parameter.
Here is my call:

class Search < ActiveRecord::Base
require 'json'
require 'typhoeus'
include Typhoeus

remote_defaults :on_success => lambda {|response| JSON.parse
(response.body)},
:on_failure => lambda {|response| puts "error code: #
{response.code}"}

def self.create_search search_query
results = Search.post("http://twitter.com/saved_searches/
create.json",
:post => {:query =>
search_query},
:headers => {"Authorization" => "Basic #
{Base64.b64encode(TWITTER_USERNAME + ":" + TWITTER_PASSWORD)}"})
end

end

Jonathan Bartels

unread,
Oct 27, 2009, 12:04:09 PM10/27/09
to typh...@googlegroups.com
What params does twitter claim to be missing? Can you toss tcpdump or wireshark at it and see what params are actually sent?

Can you post a link to the API for the call you're making?

Can you post samples of what you have tried "search_query" for?
--
-----
Jonathan Bartels

Paul Dix

unread,
Oct 27, 2009, 12:07:45 PM10/27/09
to typh...@googlegroups.com
So the old remote interface is deprecated. I'm sorry, I'll update the
readme this week, I promise.

Anyway, the new interface is Hydra and Reqeust. Using those two your
code would look like this:
hydra = Typhoeus::Hydra.new
hydra.disable_memoization
request = Typhoeus::Request.new("http://twitter.com/saved_searches/create.json",
:method => :post, :params => {:query => search_query}, :headers =>
{"Authorization" => "Basic #{Base64.b64encode(TWITTER_USERNAME + ":" +
TWITTER_PASSWORD)}"}
request.on_complete do |response|
JSON.parse(response.body)
end
hydra.queue request
hydra.run

Although, I'm not sure why the other method wouldn't work. It should.
Have you tried running it against a local server and seeing what the
POST params are?

I think this example also highlights an additional API need. To be
able to send single requests easily.

Anyway, let me know if that works for you.

Paul

On Tue, Oct 27, 2009 at 11:58 AM, plot...@googlemail.com
<plot...@googlemail.com> wrote:
>

Paul Dix

unread,
Oct 27, 2009, 12:25:28 PM10/27/09
to typh...@googlegroups.com
ok, scratch that. I just added the convenience methods. Now in version
0.1.6 (now up on gemcutter) you can just do the following:

response = Typhoeus::Request.post("http://twitter.com/saved_searches/create.json",
:params => {:query => search_query}, :headers => {"Authorization" =>
"Basic #{Base64.b64encode(TWITTER_USERNAME + ":" +
TWITTER_PASSWORD)}"})
foo = JSON.parse(response.body)

booya, enjoy.
Paul
Reply all
Reply to author
Forward
0 new messages