From: Marius Gavrilescu Date: Sat, 17 Dec 2016 18:34:02 +0000 (+0200) Subject: Implement IGetMarketPrices and IGetUserListings X-Git-Tag: 0.002~1 X-Git-Url: http://git.ieval.ro/?p=www-backpacktf.git;a=commitdiff_plain;h=fa7f4d7f5222dc5e0137267caf76a04d5fb2300a Implement IGetMarketPrices and IGetUserListings --- diff --git a/MANIFEST b/MANIFEST index 0ef90fe..c54cf21 100644 --- 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/Listing.pm +lib/WWW/BackpackTF/MarketItem.pm lib/WWW/BackpackTF/User.pm Makefile.PL MANIFEST diff --git a/lib/WWW/BackpackTF.pm b/lib/WWW/BackpackTF.pm index ad39d73..deb0fde 100644 --- a/lib/WWW/BackpackTF.pm +++ b/lib/WWW/BackpackTF.pm @@ -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 objects. +=item B([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 objects. + +=item B(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 objects. + =back =head2 EXPORTS diff --git a/lib/WWW/BackpackTF/Currency.pm b/lib/WWW/BackpackTF/Currency.pm index 66427c2..7694655 100644 --- a/lib/WWW/BackpackTF/Currency.pm +++ b/lib/WWW/BackpackTF/Currency.pm @@ -3,7 +3,7 @@ package WWW::BackpackTF::Currency; use 5.014000; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.002'; sub new{ my ($class, $name, $content) = @_; diff --git a/lib/WWW/BackpackTF/Item.pm b/lib/WWW/BackpackTF/Item.pm index 74b9e95..ed13ed0 100644 --- a/lib/WWW/BackpackTF/Item.pm +++ b/lib/WWW/BackpackTF/Item.pm @@ -3,7 +3,7 @@ package WWW::BackpackTF::Item; use 5.014000; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.002'; 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/; + my $bp = WWW::BackpackTF->new(key => '...'); 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 -L +L =head1 AUTHOR diff --git a/lib/WWW/BackpackTF/Listing.pm b/lib/WWW/BackpackTF/Listing.pm new file mode 100644 index 0000000..c7b8c4c --- /dev/null +++ b/lib/WWW/BackpackTF/Listing.pm @@ -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 + +The item being sold, as a hashref. Contains keys like C and +C. + +=item B + +The price of the listing, as a hashref. The keys are the internal +names of the currencies (can be identified using B in +L) and the values are the amounts. + +=item B
+ +The message on the listing + +=item B + +UNIX timestamp of when the listing was last bumped. + +=item B + +UNIX timestamp of when the listing was created. + +=item B + +The internal ID of the listing. + +=item B + +True if the user is selling this item. + +=item B + +True if the user is buying this item. + +=item B + +1 if the user is selling the item, 0 if the user is buying. + +=back + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=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 index 0000000..843ac60 --- /dev/null +++ b/lib/WWW/BackpackTF/MarketItem.pm @@ -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 + +The name of the item. + +=item B + +The timestamp of this information, as seconds since unix epoch. + +=item B + +How many items of this kind are there on the SCM. + +=item B + +The price this item is selling for, in cents (USD 0.01). + +=back + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=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/User.pm b/lib/WWW/BackpackTF/User.pm index 539ec0f..6248b85 100644 --- a/lib/WWW/BackpackTF/User.pm +++ b/lib/WWW/BackpackTF/User.pm @@ -3,7 +3,7 @@ package WWW::BackpackTF::User; use 5.014000; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.002'; sub new{ my ($class, $content) = @_;