]>
Commit | Line | Data |
---|---|---|
1 | package WWW::BackpackTF::Listing; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | our $VERSION = '0.002001'; | |
7 | ||
8 | sub new{ | |
9 | my ($class, $content) = @_; | |
10 | bless $content, $class | |
11 | } | |
12 | ||
13 | sub id { shift->{id} } | |
14 | sub currencies { shift->{currencies} } | |
15 | sub item { shift->{item} } | |
16 | sub details { shift->{details} } | |
17 | sub bump { shift->{bump} } | |
18 | sub created { shift->{created} } | |
19 | sub intent { shift->{intent} } | |
20 | sub is_selling { shift->intent == 1 } | |
21 | sub is_buying { shift->intent == 0 } | |
22 | ||
23 | 1; | |
24 | __END__ | |
25 | ||
26 | =encoding utf-8 | |
27 | ||
28 | =head1 NAME | |
29 | ||
30 | WWW::BackpackTF::Listing - Class representing a classified listing | |
31 | ||
32 | =head1 SYNOPSIS | |
33 | ||
34 | use WWW::BackpackTF; | |
35 | use Data::Dumper qw/Dumper/; | |
36 | use POSIX qw/strftime/; | |
37 | ||
38 | my $bp = WWW::BackpackTF->new(key => '...'); | |
39 | my $steamid = $ARGV[0]; | |
40 | my @listings = $bp->get_user_listings($steamid); | |
41 | my $listing = $listings[0]; | |
42 | ||
43 | say 'Item: ', Dumper $listing->item; | |
44 | say 'The user is selling this item' if $listing->is_selling; | |
45 | say 'The user is buying this item' if $listing->is_buying; | |
46 | my %currencies = %{$listing->currencies}; | |
47 | say 'Price: ', join ' + ', map { "$currencies{$_} $_" } keys %currencies; | |
48 | say 'Details: ', $listing->details; | |
49 | say 'Created at: ', strftime '%c', localtime $listing->created; | |
50 | say 'Last bumped at: ', strftime '%c', localtime $listing->bump; | |
51 | ||
52 | =head1 DESCRIPTION | |
53 | ||
54 | WWW::BackpackTF::Listing is a class representing a classified listing. | |
55 | ||
56 | =head2 METHODS | |
57 | ||
58 | =over | |
59 | ||
60 | =item B<item> | |
61 | ||
62 | The item being sold, as a hashref. Contains keys like C<defindex> and | |
63 | C<quality>. | |
64 | ||
65 | =item B<currencies> | |
66 | ||
67 | The price of the listing, as a hashref. The keys are the internal | |
68 | names of the currencies (can be identified using B<get_currencies> in | |
69 | L<WWW::BackpackTF>) and the values are the amounts. | |
70 | ||
71 | =item B<details> | |
72 | ||
73 | The message on the listing | |
74 | ||
75 | =item B<bump> | |
76 | ||
77 | UNIX timestamp of when the listing was last bumped. | |
78 | ||
79 | =item B<created> | |
80 | ||
81 | UNIX timestamp of when the listing was created. | |
82 | ||
83 | =item B<id> | |
84 | ||
85 | The internal ID of the listing. | |
86 | ||
87 | =item B<is_selling> | |
88 | ||
89 | True if the user is selling this item. | |
90 | ||
91 | =item B<is_buying> | |
92 | ||
93 | True if the user is buying this item. | |
94 | ||
95 | =item B<intent> | |
96 | ||
97 | 1 if the user is selling the item, 0 if the user is buying. | |
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-2017 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 |