Bump version and update Changes
[www-backpacktf.git] / lib / WWW / BackpackTF / Item.pm
CommitLineData
011cd8b5
MG
1package WWW::BackpackTF::Item;
2
3use 5.014000;
4use strict;
5use warnings;
0aaa9b98 6our $VERSION = '0.001001';
011cd8b5
MG
7
8sub new{
9 my ($class, $name, $content) = @_;
10 $content->{name} = $name;
11 bless $content, $class
12}
13
14sub name { shift->{name} }
15sub defindex { wantarray ? @{shift->{defindex}} : shift->{defindex}->[0] }
16sub price {
17 my ($self, $quality, $tradable, $craftable, $priceindex) = (@_, 6, 1, 1);
18 $tradable = $tradable ? 'Tradable' : 'Non-Tradable';
19 $craftable = $craftable ? 'Craftable' : 'Non-Craftable';
20 my $price = shift->{prices}->{$quality}->{$tradable}->{$craftable};
21 defined $priceindex ? $price->{$priceindex} : $price->[0]
22}
23
241;
25__END__
26
27=encoding utf-8
28
29=head1 NAME
30
31WWW::BackpackTF::Item - Class representing item information
32
33=head1 SYNOPSIS
34
35 use WWW::BackpackTF qw/VINTAGE GENUINE UNUSUAL/;
36 use Data::Dumper qw/Dumper/;
37
38 my @items = $bp->get_prices;
39 my $item = $items[0];
40 say 'Name: ', $item->name;
41 say 'Linked defindexes: ', join ' ', $item->defindex;
42 say 'Price of Unique, Tradable, Craftable version: ', $item->price;
43 say 'Price of Vintage, Tradable, Craftable version: ', Dumper $item->price(VINTAGE);
44 say 'Price of Vintage, Non-Tradable, Craftable version: ', Dumper $item->price(VINTAGE, 0);
45 say 'Price of Genuine, Non-Tradable, Non-Craftable version: ', Dumper $item->price(GENUINE, 0, 0);
46 say 'Price of Unusual, Tradable, Craftable version with effect 10: ', Dumper $item->price(UNUSUAL, 1, 1, 10);
47
48=head1 DESCRIPTION
49
50WWW::BackpackTF::Item is a class representing price information about an item.
51
52=head2 METHODS
53
54=over
55
56=item B<name>
57
58The name of the item.
59
60=item B<defindex>
61
62In list context, a list of defindexes linked to the item. In scalar context, the first such defindex.
63
64=item B<price>([I<$quality>, [I<$tradable>, [I<$craftable>, [I<$priceindex>]]]])
65
66The price of an item. Takes four optional arguments: the quality (defaults to 6, which is Unique), the tradability of the item (defaults to true), the craftability of an item (defaults to true), and the priceindex (crate series/unusual effect, defaults to none).
67
68Returns an hashref with the following keys/values:
69
70=over
71
72=item B<currency>
73
74The currency the item's price is in.
75
76=item B<value>
77
78The price.
79
80=item B<value_high>
81
82If present, the upper range of the price range.
83
84=item B<value_raw>
85
86The price in the lowest currency, without rounding. Only present if get_prices was called with a true value for $raw.
87
88=item B<last_update>
89
90Timestamp of last price update.
91
92=item B<difference>
93
94The difference bitween the former price and the current price. 0 if the current price is new.
95
96=back
97
98=back
99
100=head1 SEE ALSO
101
102L<http://backpack.tf/api/prices>
103
104=head1 AUTHOR
105
106Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
107
108=head1 COPYRIGHT AND LICENSE
109
0aaa9b98 110Copyright (C) 2014-2016 by Marius Gavrilescu
011cd8b5
MG
111
112This library is free software; you can redistribute it and/or modify
113it under the same terms as Perl itself, either Perl version 5.18.2 or,
114at your option, any later version of Perl 5 you may have available.
115
116
117=cut
This page took 0.017762 seconds and 4 git commands to generate.