]>
iEval git - www-backpacktf.git/blob - BackpackTF.pm
448ebbb10b6ed0e61c79c23dcffa3904114ea7e4
1 package WWW
:: BackpackTF
;
6 use parent qw
/Exporter/ ;
7 our $VERSION = '0.000_001' ;
8 our @EXPORT_OK = qw
/TF2 DOTA2/ ;
13 QUALITIES
=> [ qw
/Normal Genuine rarity2 Vintage rarity3 Unusual Unique Community Valve Self-Made Customized Strange Completed Haunted Collector's/ ],
17 my @qualities = @
{ QUALITIES
()};
18 for ( 0 .. $#qualities ) {
19 my $name = uc $qualities [ $_ ];
20 $name =~ y/A-Z0-9//cd ;
21 constant
-> import ( $name , $_ )
25 use JSON qw
/decode_json/ ;
26 use LWP
:: Simple qw
/get/ ;
28 use WWW
:: BackpackTF
:: Currency
;
29 use WWW
:: BackpackTF
:: Item
;
30 use WWW
:: BackpackTF
:: User
;
33 my ( $self , $url , %params ) = @_ ;
34 $params { key
} = $self ->{ key
};
35 $url = $self ->{ base
} . $url ;
36 $url .= "& $_ = $params { $_ }" for keys %params ;
37 my $response = decode_json
( get
$url )->{ response
};
38 die $response ->{ message
} unless $response ->{ success
};
43 my ( $class , %args ) = @_ ;
44 $args { base
} // = 'http://backpack.tf/api/' ;
49 my ( $self , $appid , $raw ) = @_ ;
50 my $response = $self -> request ( 'IGetPrices/v4/?compress=1' , maybe appid
=> $appid , maybe raw
=> $raw );
51 map { WWW
:: BackpackTF
:: Item
-> new ( $_ , $response ->{ items
}{ $_ }) } keys $response ->{ items
}
55 my ( $self , @users ) = @_ ;
56 my $response = $self -> request ( 'IGetUsers/v3/?compress=1' , steamids
=> join ',' , @users );
57 @users = map { WWW
:: BackpackTF
:: User
-> new ( $_ ) } values $response ->{ players
};
58 wantarray ?
@users : $users [ 0 ]
62 my ( $self , $appid ) = @_ ;
63 my $response = $self -> request ( 'IGetCurrencies/v1/?compress=1' , maybe appid
=> $appid );
64 map { WWW
:: BackpackTF
:: Currency
-> new ( $_ , $response ->{ currencies
}{ $_ }) } keys $response ->{ currencies
};
72 WWW::BackpackTF - interface to the backpack.tf trading service
77 my $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
78 my $user_id = <STDIN>;
79 my $bp = WWW::BackpackTF->new($api_key);
80 my $user = $bp->get_users($user_id);
81 print 'This user is named ', $user->name, ' and has ', $user->notifications, ' unread notification(s)';
82 my @all_items_in_dota2 = $bp->get_prices(WWW::BackpackTF::DOTA2);
83 my @currencies = $bp->get_currencies;
84 print 'The first currency is ', $currencies[0]->name;
88 WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2 trading service.
94 =item B<new>(I<[$api_key]>)
96 Create a new WWW::BackpackTF object. Takes a single optional parameter, the API key.
98 =item B<get_prices>([I<$appid>, [I<$raw>]])
100 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.
102 =item B<get_users>(I<@users>)
104 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.
106 =item B<get_currencies>([I<$appid>])
108 Get currency information. Takes one optional parameter, the appid, which defaults to WWW::BackpackTF::TF2. Returns a list of L<WWW::BackpackTF::Currency> objects.
120 Constant (440) representing Team Fortress 2.
124 Constant (570) representing Dota 2.
128 The Normal item quality (0).
132 The Genuine item quality (1).
136 The unused rarity2 item quality (2).
140 The Vintage item quality (3).
144 The unused rarity3 item quality (4).
148 The Unusual item quality (5).
152 The Unique item quality (6).
156 The Community item quality (7).
160 The Valve item quality (8).
164 The Self-Made item quality (9).
168 The unused Customized item quality (10).
172 The Strange item quality (11).
176 The Completed item quality (12).
180 The Haunted item quality (13).
184 The Collector's item quality (14).
190 L<http://backpack.tf/>, L<http://backpack.tf/api>
194 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
196 =head1 COPYRIGHT AND LICENSE
198 Copyright (C) 2014 by Marius Gavrilescu
200 This library is free software; you can redistribute it and/or modify
201 it under the same terms as Perl itself, either Perl version 5.18.2 or,
202 at your option, any later version of Perl 5 you may have available.
This page took 0.05815 seconds and 3 git commands to generate.