1 package WWW
::BackpackTF
;
6 use parent qw
/Exporter/;
7 our $VERSION = '0.000_003';
8 our @EXPORT_OK = qw
/TF2 DOTA2/;
14 QUALITIES
=> [qw
/Normal Genuine rarity2 Vintage rarity3 Unusual Unique Community Valve Self-Made Customized Strange Completed Haunted Collector's/],
18 my @qualities = @
{QUALITIES
()};
19 for (0 .. $#qualities) {
20 my $name = uc $qualities[$_];
21 $name =~ y/A-Z0-9//cd;
22 constant
->import($name, $_)
26 use JSON
::MaybeXS qw
/decode_json/;
29 use WWW
::BackpackTF
::Currency
;
30 use WWW
::BackpackTF
::Item
;
31 use WWW
::BackpackTF
::User
;
33 my $ht = HTTP
::Tiny
->new(agent
=> "WWW-BackpackTF/$VERSION");
36 my ($self, $url, %params) = @_;
37 $params{key
} = $self->{key
} if $self->{key
};
38 $url = $self->{base
} . $url;
39 $url .= "&$_=$params{$_}" for keys %params;
40 my $htr = $ht->get($url);
41 die $htr->{reason
} unless $htr->{success
};
42 my $response = decode_json
($htr->{content
})->{response
};
43 die $response->{message
} unless $response->{success
};
48 my ($class, %args) = @_;
49 $args{base
} //= 'http://backpack.tf/api/';
54 my ($self, $appid, $raw) = @_;
55 my $response = $self->request('IGetPrices/v4/?compress=1', maybe appid
=> $appid, maybe raw
=> $raw);
56 map { WWW
::BackpackTF
::Item
->new($_, $response->{items
}{$_}) } keys %{$response->{items
}}
60 my ($self, @users) = @_;
61 my $response = $self->request('IGetUsers/v3/?compress=1', steamids
=> join ',', @users);
62 @users = map { WWW
::BackpackTF
::User
->new($_) } values %{$response->{players
}};
63 wantarray ?
@users : $users[0]
67 my ($self, $appid) = @_;
68 my $response = $self->request('IGetCurrencies/v1/?compress=1', maybe appid
=> $appid);
69 map { WWW
::BackpackTF
::Currency
->new($_, $response->{currencies
}{$_}) } keys %{$response->{currencies
}};
77 WWW::BackpackTF - interface to the backpack.tf trading service
82 my $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
83 my $user_id = <STDIN>;
84 my $bp = WWW::BackpackTF->new($api_key);
85 my $user = $bp->get_users($user_id);
86 print 'This user is named ', $user->name, ' and has ', $user->notifications, ' unread notification(s)';
87 my @all_items_in_dota2 = $bp->get_prices(WWW::BackpackTF::DOTA2);
88 my @currencies = $bp->get_currencies;
89 print 'The first currency is ', $currencies[0]->name;
93 WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2/Counter-Strike: Global Offensive trading service.
99 =item B<new>([key => I<$api_key>], [base => I<$base_url>])
101 Create a new WWW::BackpackTF object. Takes a hash of parameters. Possible parameters:
107 The API key. Defaults to nothing. Most methods require an API key.
111 The base URL. Defaults to http://backpack.tf/api/.
115 =item B<get_prices>([I<$appid>, [I<$raw>]])
117 Get price information for all items. Takes two optional parameters. The first parameter is the appid and defaults to WWW::BackpackTF::TF2. The second (if true) adds a value_raw property to prices and defaults to false. Returns a list of L<WWW::BackpackTF::Item> objects.
119 =item B<get_users>(I<@users>)
121 Get profile information for a list of users. Takes any number of 64-bit Steam IDs as arguments and returns a list of L<WWW::BackpackTF::User> objects. This method does not require an API key. Dies with an error message if the operation is unsuccessful.
123 =item B<get_currencies>([I<$appid>])
125 Get currency information. Takes one optional parameter, the appid, which defaults to WWW::BackpackTF::TF2. Returns a list of L<WWW::BackpackTF::Currency> objects.
137 Constant (440) representing Team Fortress 2.
141 Constant (570) representing Dota 2.
145 Constant (730) representing Counter-Strike: Global Offensive
149 The Normal item quality (0).
153 The Genuine item quality (1).
157 The unused rarity2 item quality (2).
161 The Vintage item quality (3).
165 The unused rarity3 item quality (4).
169 The Unusual item quality (5).
173 The Unique item quality (6).
177 The Community item quality (7).
181 The Valve item quality (8).
185 The Self-Made item quality (9).
189 The unused Customized item quality (10).
193 The Strange item quality (11).
197 The Completed item quality (12).
201 The Haunted item quality (13).
205 The Collector's item quality (14).
211 L<http://backpack.tf/>, L<http://backpack.tf/api>
215 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
217 =head1 COPYRIGHT AND LICENSE
219 Copyright (C) 2014 by Marius Gavrilescu
221 This library is free software; you can redistribute it and/or modify
222 it under the same terms as Perl itself, either Perl version 5.18.2 or,
223 at your option, any later version of Perl 5 you may have available.
This page took 0.031614 seconds and 4 git commands to generate.