X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWWW%2FBackpackTF.pm;h=af3511ff372aedc2dbce18c4faa481c2d0bedb5e;hb=921096c3dd19c68c1045e3119600364b69de5af7;hp=4e4ee154dc537bfe7e819a96cc0f81e8f73fdda1;hpb=1e12c1b3436847490415181df23d46f735a3cb47;p=www-backpacktf.git diff --git a/lib/WWW/BackpackTF.pm b/lib/WWW/BackpackTF.pm index 4e4ee15..af3511f 100644 --- a/lib/WWW/BackpackTF.pm +++ b/lib/WWW/BackpackTF.pm @@ -4,12 +4,13 @@ use 5.014000; use strict; use warnings; use parent qw/Exporter/; -our $VERSION = '0.000_002'; +our $VERSION = '0.000_003'; our @EXPORT_OK = qw/TF2 DOTA2/; use constant +{ TF2 => 440, DOTA2 => 570, + CSGO => 730, QUALITIES => [qw/Normal Genuine rarity2 Vintage rarity3 Unusual Unique Community Valve Self-Made Customized Strange Completed Haunted Collector's/], }; @@ -23,18 +24,22 @@ BEGIN { } use JSON::MaybeXS qw/decode_json/; -use LWP::Simple qw/get/; +use HTTP::Tiny; use PerlX::Maybe; use WWW::BackpackTF::Currency; use WWW::BackpackTF::Item; use WWW::BackpackTF::User; +my $ht = HTTP::Tiny->new(agent => "WWW-BackpackTF/$VERSION"); + sub request { my ($self, $url, %params) = @_; - $params{key} = $self->{key}; + $params{key} = $self->{key} if $self->{key}; $url = $self->{base} . $url; $url .= "&$_=$params{$_}" for keys %params; - my $response = decode_json(get $url)->{response}; + my $htr = $ht->get($url); + die $htr->{reason} unless $htr->{success}; + my $response = decode_json($htr->{content})->{response}; die $response->{message} unless $response->{success}; $response } @@ -48,20 +53,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; @@ -85,7 +90,7 @@ WWW::BackpackTF - interface to the backpack.tf trading service =head1 DESCRIPTION -WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2 trading service. +WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2/Counter-Strike: Global Offensive trading service. =head2 METHODS @@ -135,6 +140,10 @@ Constant (440) representing Team Fortress 2. Constant (570) representing Dota 2. +=item B + +Constant (730) representing Counter-Strike: Global Offensive + =item B The Normal item quality (0).