WebService::APIKeys::AutoChanger - Throttler and auto-changer for Web-API's restriction.
For example, use it with WebService::Simple for YahooJapan Web-API.
use WebService::Simple; use WebService::APIKeys::AutoChanger; use Data::Dumper; my $changer = WebService::APIKeys::AutoChanger->new; $changer->set( api_keys => [ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', ], ## you don't have to set below explicitly throttle_class => 'Data::Valve', # backend throttler class. (default: Data::Valve) throttle_config => { max_items => 50000, # default: 50000 interval => 86400, # default: 86400 }, ); my $yahooJapan = WebService::Simple->new( base_url => 'http://search.yahooapis.jp/WebSearchService/V1/webSearch', ); my @query = qw( foo bar baz ... ); for my $query(@query){ # available APIKey(appid) will be changed automatically my $available_key = $changer->get_available; # you can use it my $response = $yahooJapan->get( { appid => $available_key, query => $query } ); do_something($response); }
WebService::APIKeys::AutoChanger is a throttler and auto-changer for Web API's restriction.
For example, YahooJapan sets a restriction 50,000 times per day as an API-key. You can use it over the limitation if you set plural APIKey beforehand.
This module provides available-key, seamlessly.
my $changer = WebService::APIKeys::AutoChanger->new( api_keys => \@api_keys, throttle_class => 'Data::Valve', throttle_config => { max_items => 50000, interval => 86400, } );
Create and return new WebService::APIKeys::AutoChanger object. You can set api-keys and throttle information as option parameters.
$changer->set( api_keys => \@api_keys, throttle_class => 'Data::Valve', throttle_config => { max_items => 50000, interval => 86400, } );
If your circumstance does not allow use Moose, set 'Data::Throttler' instead of 'Data::Valve' for throttle_class. (But Data::Throttler is slower than Data::Valve)
Returns an available API Key at that point.
Takeshi Miki <miki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WebService::APIKeys::AutoChanger, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::APIKeys::AutoChanger
CPAN shell
perl -MCPAN -e shell install WebService::APIKeys::AutoChanger
For more information on module installation, please visit the detailed CPAN module installation guide.