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
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,
for (0 .. $#qualities) {
my $name = uc $qualities[$_];
$name =~ y/A-Z0-9//cd;
+ push @EXPORT_OK, $name;
constant->import($name, $_)
}
}
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");
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__
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
use 5.014000;
use strict;
use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
sub new{
my ($class, $name, $content) = @_;
use 5.014000;
use strict;
use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
sub new{
my ($class, $name, $content) = @_;
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;
=head1 SEE ALSO
-L<http://backpack.tf/api/prices>
+L<http://backpack.tf/api/IGetPrices>
=head1 AUTHOR
--- /dev/null
+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
--- /dev/null
+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
use 5.014000;
use strict;
use warnings;
-our $VERSION = '0.001001';
+our $VERSION = '0.002';
sub new{
my ($class, $content) = @_;