Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Need to subclass Finance::MtGox so the POST goes to a test server.
This works as expected, but it's blocking.use Data::Dump; BEGIN { package Local::Finance::MtGox; use base 'Finance::MtGox'; sub _build_api_method_uri { return URI->new("https://h.wrttn.me/post"); } }
This works and is non-blocking, but it is not very efficient if it is called many times or the parent process is large.my $mtgox = Local::Finance::MtGox->new({ key => 'key', secret => 'secr +et' }); $mtgox->{mech}->ssl_opts(verify_hostname => 0); dd $mtgox->call_auth('getFunds');
This doesn't work, it returns a 400 Bad Request.use AnyEvent; use AnyEvent::Util 'fork_call'; my $mtgox = Local::Finance::MtGox->new({ key => 'key', secret => 'secr +et' }); $mtgox->{mech}->ssl_opts(verify_hostname => 0); my $cv = AE::cv; fork_call { $mtgox->call_auth('getFunds') } sub { dd @_; $cv->send }; $cv->wait;
This also doesn't work and returns a 400 Bad Request.use Coro; use LWP::Protocol::AnyEvent::http; my $mtgox = Local::Finance::MtGox->new({ key => 'key', secret => 'secr +et' }); my $coro = async { say "before"; $mtgox->call_auth('getFunds'); }; dd $coro->join;
use AnyEvent; use AnyEvent::HTTP::Request; use AnyEvent::HTTP::Response; my $mtgox = Local::Finance::MtGox->new({ key => 'key', secret => 'secr +et' }); my $cv = AE::cv; my $req = AnyEvent::HTTP::Request->new( # Returns an HTTP::Request $mtgox->_build_api_method_request(POST => 'getFunds'), { cb => sub { my $res = AnyEvent::HTTP::Response->new(@_)->to_http_messa +ge; dd $res; $cv->send; } } ); $req->send; $cv->wait;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling LWP/Mech from AnyEvent
by Anonymous Monk on Oct 30, 2012 at 19:11 UTC | |
|
Re: Calling LWP/Mech from AnyEvent
by Anonymous Monk on Nov 04, 2012 at 21:04 UTC | |
by rwstauner (Acolyte) on Jan 26, 2013 at 17:37 UTC |