Initial commit
[www-backpacktf.git] / lib / WWW / BackpackTF.pm
CommitLineData
6e8c48c3
MG
1package WWW::BackpackTF;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our $VERSION = '0.000_001';
8our @EXPORT_OK = qw/TF2 DOTA2/;
9
10use constant TF2 => 440;
11use constant DOTA2 => 570;
12
13use JSON qw/decode_json/;
14use LWP::Simple qw/get/;
15use WWW::BackpackTF::User;
16
17sub new{
18 my ($class, $key) = @_;
19 bless {key => $key}, $class
20}
21
22sub get_users{
23 my ($self, @users) = @_;
24 my $response = decode_json get "http://backpack.tf/api/IGetUsers/v3/?compress=1&format=json&steamids=" . join ',', @users;
25 $response = $response->{response};
26 die $response->{message} unless $response->{success};
27 @users = map { WWW::BackpackTF::User->new($_) } values $response->{players};
28 wantarray ? @users : $users[0]
29}
30
311;
32__END__
33
34=head1 NAME
35
36WWW::BackpackTF - interface to the backpack.tf trading service
37
38=head1 SYNOPSIS
39
40 use WWW::BackpackTF;
41 my $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
42 my $user_id = <STDIN>;
43 my $bp = WWW::BackpackTF->new($api_key);
44 my $user = $bp->get_users($user_id);
45 print 'This user is named ', $user->name, ' and has ', $user->notifications, ' unread notification(s)';
46
47=head1 DESCRIPTION
48
49WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2 trading service.
50
51The only call implemented so far is I<IGetUsers>.
52
53=head2 METHODS
54
55=over
56
57=item B<new>(I<[$api_key]>)
58
59Create a new WWW::BackpackTF object. Takes a single optional parameter, the API key.
60
61=item B<get_users>(I<@users>)
62
63Get profile information for a list of users. Takes any number of 64-bit Steam IDs as arguments and returns a list of WWW::BackpackTF::User objects. This method does not require an API key.
64
65=back
66
67=head2 EXPORTS
68
69None by default.
70
71=over
72
73=item B<TF2>
74
75Constant (440) representing Team Fortress 2.
76
77=item B<DOTA2>
78
79Constant (570) representing Dota 2.
80
81=back
82
83=head1 SEE ALSO
84
85L<http://backpack.tf/>, L<http://backpack.tf/api>
86
87=head1 AUTHOR
88
89Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
90
91=head1 COPYRIGHT AND LICENSE
92
93Copyright (C) 2014 by Marius Gavrilescu
94
95This library is free software; you can redistribute it and/or modify
96it under the same terms as Perl itself, either Perl version 5.18.2 or,
97at your option, any later version of Perl 5 you may have available.
98
99
100=cut
This page took 0.016333 seconds and 4 git commands to generate.