« blib/lib/auto/share/dist/Beekeeper/scraper/client.pl
↑ Summary
blib/lib/auto/share/dist/Beekeeper/websocket/client.pl »
| 1 | package MyApp::Service::Scraper; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Beekeeper::Client; | ||
| 7 | |||
| 8 | |||
| 9 | # These two implementations call exactly the same remote method | ||
| 10 | |||
| 11 | sub get_title { | ||
| 12 | my ($self, $url) = @_; | ||
| 13 | |||
| 14 | # This will block until a response is received | ||
| 15 | |||
| 16 | my $client = Beekeeper::Client->instance; | ||
| 17 | |||
| 18 | my $response = $client->call_remote( | ||
| 19 | method => 'myapp.scraper.get_title', | ||
| 20 | params => { url => $url }, | ||
| 21 | raise_error => 0, | ||
| 22 | ); | ||
| 23 | |||
| 24 | return $response; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub get_title_async { | ||
| 28 | my ($self, $url, $on_complete) = @_; | ||
| 29 | |||
| 30 | # This will return immediately. The response will be received asynchronously | ||
| 31 | |||
| 32 | my $client = Beekeeper::Client->instance; | ||
| 33 | |||
| 34 | my $request = $client->call_remote_async( | ||
| 35 | method => 'myapp.scraper.get_title', | ||
| 36 | params => { url => $url }, | ||
| 37 | on_success => $on_complete, | ||
| 38 | on_error => $on_complete, | ||
| 39 | ); | ||
| 40 | |||
| 41 | return $request; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; |