Implement IGetMarketPrices and IGetUserListings
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 17 Dec 2016 18:34:02 +0000 (20:34 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 17 Dec 2016 18:34:02 +0000 (20:34 +0200)
MANIFEST
lib/WWW/BackpackTF.pm
lib/WWW/BackpackTF/Currency.pm
lib/WWW/BackpackTF/Item.pm
lib/WWW/BackpackTF/Listing.pm [new file with mode: 0644]
lib/WWW/BackpackTF/MarketItem.pm [new file with mode: 0644]
lib/WWW/BackpackTF/User.pm

index 0ef90fe612fe6c449acad8ac8d21ff5c546e3706..c54cf21e8233199fab2ea68a01c30342a5e369cd 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2,6 +2,8 @@ Changes
 lib/WWW/BackpackTF.pm
 lib/WWW/BackpackTF/Currency.pm
 lib/WWW/BackpackTF/Item.pm
 lib/WWW/BackpackTF.pm
 lib/WWW/BackpackTF/Currency.pm
 lib/WWW/BackpackTF/Item.pm
+lib/WWW/BackpackTF/Listing.pm
+lib/WWW/BackpackTF/MarketItem.pm
 lib/WWW/BackpackTF/User.pm
 Makefile.PL
 MANIFEST
 lib/WWW/BackpackTF/User.pm
 Makefile.PL
 MANIFEST
index ad39d73175774356775477f0a1d31cd1cedb246d..deb0fde80bfcfe06d25e4093d51c26fb0db53fe2 100644 (file)
@@ -4,8 +4,8 @@ use 5.014000;
 use strict;
 use warnings;
 use parent qw/Exporter/;
 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,
 
 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;
        for (0 .. $#qualities) {
                my $name = uc $qualities[$_];
                $name =~ y/A-Z0-9//cd;
+               push @EXPORT_OK, $name;
                constant->import($name, $_)
        }
 }
                constant->import($name, $_)
        }
 }
@@ -28,6 +29,8 @@ use HTTP::Tiny;
 use PerlX::Maybe;
 use WWW::BackpackTF::Currency;
 use WWW::BackpackTF::Item;
 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");
 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}};
 }
 
        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__
 
 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.
 
 
 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
 =back
 
 =head2 EXPORTS
index 66427c28965d44c26dd9842e37c8b2ef1751ca8a..769465517a3dd5cebd2112e101fe7cd02f3348ef 100644 (file)
@@ -3,7 +3,7 @@ package WWW::BackpackTF::Currency;
 use 5.014000;
 use strict;
 use warnings;
 use 5.014000;
 use strict;
 use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
 
 sub new{
        my ($class, $name, $content) = @_;
 
 sub new{
        my ($class, $name, $content) = @_;
index 74b9e953bfbeff8dfe14c4eca62272eb346182cc..ed13ed0df922aa527edbe6faf26e469f13302d7c 100644 (file)
@@ -3,7 +3,7 @@ package WWW::BackpackTF::Item;
 use 5.014000;
 use strict;
 use warnings;
 use 5.014000;
 use strict;
 use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
 
 sub new{
        my ($class, $name, $content) = @_;
 
 sub new{
        my ($class, $name, $content) = @_;
@@ -35,6 +35,7 @@ WWW::BackpackTF::Item - Class representing item information
   use WWW::BackpackTF qw/VINTAGE GENUINE UNUSUAL/;
   use Data::Dumper qw/Dumper/;
 
   use WWW::BackpackTF qw/VINTAGE GENUINE UNUSUAL/;
   use Data::Dumper qw/Dumper/;
 
+  my $bp = WWW::BackpackTF->new(key => '...');
   my @items = $bp->get_prices;
   my $item = $items[0];
   say 'Name: ', $item->name;
   my @items = $bp->get_prices;
   my $item = $items[0];
   say 'Name: ', $item->name;
@@ -99,7 +100,7 @@ The difference bitween the former price and the current price. 0 if the current
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO
 
-L<http://backpack.tf/api/prices>
+L<http://backpack.tf/api/IGetPrices>
 
 =head1 AUTHOR
 
 
 =head1 AUTHOR
 
diff --git a/lib/WWW/BackpackTF/Listing.pm b/lib/WWW/BackpackTF/Listing.pm
new file mode 100644 (file)
index 0000000..c7b8c4c
--- /dev/null
@@ -0,0 +1,120 @@
+package WWW::BackpackTF::Listing;
+
+use 5.014000;
+use strict;
+use warnings;
+our $VERSION = '0.002';
+
+sub new{
+       my ($class, $content) = @_;
+       bless $content, $class
+}
+
+sub id         { shift->{id} }
+sub currencies { shift->{currencies} }
+sub item       { shift->{item} }
+sub details    { shift->{details} }
+sub bump       { shift->{bump} }
+sub created    { shift->{created} }
+sub intent     { shift->{intent} }
+sub is_selling { shift->intent == 1 }
+sub is_buying  { shift->intent == 0 }
+
+1;
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+WWW::BackpackTF::Listing - Class representing a classified listing
+
+=head1 SYNOPSIS
+
+  use WWW::BackpackTF;
+  use Data::Dumper qw/Dumper/;
+  use POSIX qw/strftime/;
+
+  my $bp = WWW::BackpackTF->new(key => '...');
+  my $steamid = $ARGV[0];
+  my @listings = $bp->get_user_listings($steamid);
+  my $listing = $listings[0];
+
+  say 'Item: ', Dumper $listing->item;
+  say 'The user is selling this item' if $listing->is_selling;
+  say 'The user is buying this item'  if $listing->is_buying;
+  my %currencies = %{$listing->currencies};
+  say 'Price: ', join ' + ', map { "$currencies{$_} $_" } keys %currencies;
+  say 'Details: ', $listing->details;
+  say 'Created at: ',     strftime '%c', localtime $listing->created;
+  say 'Last bumped at: ', strftime '%c', localtime $listing->bump;
+
+=head1 DESCRIPTION
+
+WWW::BackpackTF::Listing is a class representing a classified listing.
+
+=head2 METHODS
+
+=over
+
+=item B<item>
+
+The item being sold, as a hashref. Contains keys like C<defindex> and
+C<quality>.
+
+=item B<currencies>
+
+The price of the listing, as a hashref. The keys are the internal
+names of the currencies (can be identified using B<get_currencies> in
+L<WWW::BackpackTF>) and the values are the amounts.
+
+=item B<details>
+
+The message on the listing
+
+=item B<bump>
+
+UNIX timestamp of when the listing was last bumped.
+
+=item B<created>
+
+UNIX timestamp of when the listing was created.
+
+=item B<id>
+
+The internal ID of the listing.
+
+=item B<is_selling>
+
+True if the user is selling this item.
+
+=item B<is_buying>
+
+True if the user is buying this item.
+
+=item B<intent>
+
+1 if the user is selling the item, 0 if the user is buying.
+
+=back
+
+=back
+
+=head1 SEE ALSO
+
+L<http://backpack.tf/api/IGetPrices>
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014-2016 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.2 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
diff --git a/lib/WWW/BackpackTF/MarketItem.pm b/lib/WWW/BackpackTF/MarketItem.pm
new file mode 100644 (file)
index 0000000..843ac60
--- /dev/null
@@ -0,0 +1,88 @@
+package WWW::BackpackTF::MarketItem;
+
+use 5.014000;
+use strict;
+use warnings;
+our $VERSION = '0.002';
+
+sub new{
+       my ($class, $name, $content) = @_;
+       $content->{name} = $name;
+       bless $content, $class
+}
+
+sub name         { shift->{name} }
+sub last_updated { shift->{last_updated} }
+sub quantity     { shift->{quantity} }
+sub value        { shift->{value} }
+
+1;
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+WWW::BackpackTF::MarketItem - Class representing market item information
+
+=head1 SYNOPSIS
+
+  use WWW::BackpackTF;
+  use Data::Dumper qw/Dumper/;
+  use POSIX qw/strftime/;
+
+  my $bp = WWW::BackpackTF->new(key => '...');
+  my @items = $bp->get_market_prices;
+  my $item = $items[0];
+  say 'Name: ', $item->name;
+  say strftime 'Last updated on: %c', localtime $item->last_updated;
+  say 'Quantity available on market: ', $item->quantity;
+  say 'Value of item: $', sprintf '%.2f', $item->value / 100;
+
+=head1 DESCRIPTION
+
+WWW::BackpackTF::MarketItem is a class representing Steam Community
+Market price information about an item.
+
+=head2 METHODS
+
+=over
+
+=item B<name>
+
+The name of the item.
+
+=item B<last_updated>
+
+The timestamp of this information, as seconds since unix epoch.
+
+=item B<quantity>
+
+How many items of this kind are there on the SCM.
+
+=item B<value>
+
+The price this item is selling for, in cents (USD 0.01).
+
+=back
+
+=back
+
+=head1 SEE ALSO
+
+L<http://backpack.tf/api/docs/IGetMarketPrices>
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014-2016 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.2 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
index 539ec0f6d81af38e746c22c36eb9636af3027dcb..6248b85b8b5d270e06755c7d99863f7d924a97c3 100644 (file)
@@ -3,7 +3,7 @@ package WWW::BackpackTF::User;
 use 5.014000;
 use strict;
 use warnings;
 use 5.014000;
 use strict;
 use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
 
 sub new{
        my ($class, $content) = @_;
 
 sub new{
        my ($class, $content) = @_;
This page took 0.019252 seconds and 4 git commands to generate.