Implement IGetMarketPrices and IGetUserListings
[www-backpacktf.git] / lib / WWW / BackpackTF.pm
index ad39d73175774356775477f0a1d31cd1cedb246d..deb0fde80bfcfe06d25e4093d51c26fb0db53fe2 100644 (file)
@@ -4,8 +4,8 @@ use 5.014000;
 use strict;
 use warnings;
 use parent qw/Exporter/;
-our $VERSION = '0.001001';
-our @EXPORT_OK = qw/TF2 DOTA2/;
+our $VERSION = '0.002';
+our @EXPORT_OK = qw/TF2 DOTA2 CSGO/;
 
 use constant +{ ## no critic (Capitalization)
        TF2 => 440,
@@ -19,6 +19,7 @@ BEGIN {
        for (0 .. $#qualities) {
                my $name = uc $qualities[$_];
                $name =~ y/A-Z0-9//cd;
+               push @EXPORT_OK, $name;
                constant->import($name, $_)
        }
 }
@@ -28,6 +29,8 @@ use HTTP::Tiny;
 use PerlX::Maybe;
 use WWW::BackpackTF::Currency;
 use WWW::BackpackTF::Item;
+use WWW::BackpackTF::MarketItem;
+use WWW::BackpackTF::Listing;
 use WWW::BackpackTF::User;
 
 my $ht = HTTP::Tiny->new(agent => "WWW-BackpackTF/$VERSION");
@@ -69,6 +72,21 @@ sub get_currencies {
        map { WWW::BackpackTF::Currency->new($_, $response->{currencies}{$_}) } keys %{$response->{currencies}};
 }
 
+# get_price_history not implemented
+# get_special_items not implemented
+
+sub get_market_prices {
+       my ($self, $appid) = @_;
+       my $response = $self->request('IGetMarketPrices/v1/?compress=1', maybe appid => $appid);
+       map { WWW::BackpackTF::MarketItem->new($_, $response->{items}{$_}) } keys %{$response->{items}}
+}
+
+sub get_user_listings {
+       my ($self, $steamid, $appid) = @_;
+       my $response = $self->request('IGetUserListings/v2/?compress=1', steamid => $steamid, maybe appid => $appid);
+       map { WWW::BackpackTF::Listing->new($_) } @{$response->{listings}}
+}
+
 1;
 __END__
 
@@ -126,6 +144,14 @@ Get profile information for a list of users. Takes any number of 64-bit Steam ID
 
 Get currency information. Takes one optional parameter, the appid, which defaults to WWW::BackpackTF::TF2. Returns a list of L<WWW::BackpackTF::Currency> objects.
 
+=item B<get_market_prices>([I<$appid>])
+
+Get Steam Community Market price information for all items. Takes one optional parameter, the appid, which defaults to WWW::BackpackTF::TF2. Returns a list of L<WWW::BackpackTF::MarketItem> objects.
+
+=item B<get_user_listings>(I<$steamid>, [I<$appid>])
+
+Get classified listing of a given user. Takes a mandatory 64-bit Steam ID of the user, and an optional parameter, the appid, which defaults to WWW::BackpackTF::TF2. Returns a list of L<WWW::BackpackTF::Listing> objects.
+
 =back
 
 =head2 EXPORTS
This page took 0.010305 seconds and 4 git commands to generate.