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