X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWWW%2FBackpackTF.pm;h=5e33b57d67e0055394290ac18fd4d5d7e83003ce;hb=72f329fe90d7d3aaee7400d639a332d55b30179f;hp=448ebbb10b6ed0e61c79c23dcffa3904114ea7e4;hpb=011cd8b54a2bac28ce3a83f8b3afcab3b93677f3;p=www-backpacktf.git diff --git a/lib/WWW/BackpackTF.pm b/lib/WWW/BackpackTF.pm index 448ebbb..5e33b57 100644 --- a/lib/WWW/BackpackTF.pm +++ b/lib/WWW/BackpackTF.pm @@ -4,7 +4,7 @@ use 5.014000; use strict; use warnings; use parent qw/Exporter/; -our $VERSION = '0.000_001'; +our $VERSION = '0.000_002'; our @EXPORT_OK = qw/TF2 DOTA2/; use constant +{ @@ -22,7 +22,7 @@ BEGIN { } } -use JSON qw/decode_json/; +use JSON::MaybeXS qw/decode_json/; use LWP::Simple qw/get/; use PerlX::Maybe; use WWW::BackpackTF::Currency; @@ -48,20 +48,20 @@ sub new{ sub get_prices { my ($self, $appid, $raw) = @_; my $response = $self->request('IGetPrices/v4/?compress=1', maybe appid => $appid, maybe raw => $raw); - map { WWW::BackpackTF::Item->new($_, $response->{items}{$_}) } keys $response->{items} + map { WWW::BackpackTF::Item->new($_, $response->{items}{$_}) } keys %{$response->{items}} } sub get_users { my ($self, @users) = @_; my $response = $self->request('IGetUsers/v3/?compress=1', steamids => join ',', @users); - @users = map { WWW::BackpackTF::User->new($_) } values $response->{players}; + @users = map { WWW::BackpackTF::User->new($_) } values %{$response->{players}}; wantarray ? @users : $users[0] } sub get_currencies { my ($self, $appid) = @_; my $response = $self->request('IGetCurrencies/v1/?compress=1', maybe appid => $appid); - map { WWW::BackpackTF::Currency->new($_, $response->{currencies}{$_}) } keys $response->{currencies}; + map { WWW::BackpackTF::Currency->new($_, $response->{currencies}{$_}) } keys %{$response->{currencies}}; } 1; @@ -91,9 +91,21 @@ WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2 tradin =over -=item B(I<[$api_key]>) +=item B([key => I<$api_key>], [base => I<$base_url>]) -Create a new WWW::BackpackTF object. Takes a single optional parameter, the API key. +Create a new WWW::BackpackTF object. Takes a hash of parameters. Possible parameters: + +=over + +=item B + +The API key. Defaults to nothing. Most methods require an API key. + +=item B + +The base URL. Defaults to http://backpack.tf/api/. + +=back =item B([I<$appid>, [I<$raw>]])