Initial commit
[www-backpacktf.git] / lib / WWW / BackpackTF.pm
1 package WWW::BackpackTF;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use parent qw/Exporter/;
7 our $VERSION = '0.000_001';
8 our @EXPORT_OK = qw/TF2 DOTA2/;
9
10 use constant TF2 => 440;
11 use constant DOTA2 => 570;
12
13 use JSON qw/decode_json/;
14 use LWP::Simple qw/get/;
15 use WWW::BackpackTF::User;
16
17 sub new{
18 my ($class, $key) = @_;
19 bless {key => $key}, $class
20 }
21
22 sub 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
31 1;
32 __END__
33
34 =head1 NAME
35
36 WWW::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
49 WWW::BackpackTF is an interface to the backpack.tf Team Fortress 2/Dota 2 trading service.
50
51 The only call implemented so far is I<IGetUsers>.
52
53 =head2 METHODS
54
55 =over
56
57 =item B<new>(I<[$api_key]>)
58
59 Create a new WWW::BackpackTF object. Takes a single optional parameter, the API key.
60
61 =item B<get_users>(I<@users>)
62
63 Get 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
69 None by default.
70
71 =over
72
73 =item B<TF2>
74
75 Constant (440) representing Team Fortress 2.
76
77 =item B<DOTA2>
78
79 Constant (570) representing Dota 2.
80
81 =back
82
83 =head1 SEE ALSO
84
85 L<http://backpack.tf/>, L<http://backpack.tf/api>
86
87 =head1 AUTHOR
88
89 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
90
91 =head1 COPYRIGHT AND LICENSE
92
93 Copyright (C) 2014 by Marius Gavrilescu
94
95 This library is free software; you can redistribute it and/or modify
96 it under the same terms as Perl itself, either Perl version 5.18.2 or,
97 at your option, any later version of Perl 5 you may have available.
98
99
100 =cut
This page took 0.023686 seconds and 4 git commands to generate.