line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::BackpackTF; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
61661
|
use 5.014000; |
|
2
|
|
|
|
|
6
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
6
|
2
|
|
|
2
|
|
2045
|
use parent qw/Exporter/; |
|
2
|
|
|
|
|
568
|
|
|
2
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.002001'; |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/TF2 DOTA2 CSGO/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant +{ ## no critic (Capitalization) |
11
|
2
|
|
|
|
|
358
|
TF2 => 440, |
12
|
|
|
|
|
|
|
DOTA2 => 570, |
13
|
|
|
|
|
|
|
CSGO => 730, |
14
|
|
|
|
|
|
|
QUALITIES => [qw/Normal Genuine rarity2 Vintage rarity3 Unusual Unique Community Valve Self-Made Customized Strange Completed Haunted Collector's/], |
15
|
2
|
|
|
2
|
|
185
|
}; |
|
2
|
|
|
|
|
3
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
2
|
|
|
2
|
|
3
|
my @qualities = @{QUALITIES()}; |
|
2
|
|
|
|
|
8
|
|
19
|
2
|
|
|
|
|
7
|
for (0 .. $#qualities) { |
20
|
30
|
|
|
|
|
43
|
my $name = uc $qualities[$_]; |
21
|
30
|
|
|
|
|
35
|
$name =~ y/A-Z0-9//cd; |
22
|
30
|
|
|
|
|
37
|
push @EXPORT_OK, $name; |
23
|
30
|
|
|
|
|
692
|
constant->import($name, $_) |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
1086
|
use JSON::MaybeXS qw/decode_json/; |
|
2
|
|
|
|
|
13286
|
|
|
2
|
|
|
|
|
91
|
|
28
|
2
|
|
|
2
|
|
1184
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
62905
|
|
|
2
|
|
|
|
|
66
|
|
29
|
2
|
|
|
2
|
|
727
|
use PerlX::Maybe; |
|
2
|
|
|
|
|
2392
|
|
|
2
|
|
|
|
|
96
|
|
30
|
2
|
|
|
2
|
|
641
|
use WWW::BackpackTF::Currency; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
31
|
2
|
|
|
2
|
|
624
|
use WWW::BackpackTF::Item; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
32
|
2
|
|
|
2
|
|
588
|
use WWW::BackpackTF::MarketItem; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
33
|
2
|
|
|
2
|
|
885
|
use WWW::BackpackTF::Listing; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
40
|
|
34
|
2
|
|
|
2
|
|
625
|
use WWW::BackpackTF::User; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
875
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $ht = HTTP::Tiny->new(agent => "WWW-BackpackTF/$VERSION"); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub request { |
39
|
1
|
|
|
1
|
0
|
2
|
my ($self, $url, %params) = @_; |
40
|
1
|
50
|
|
|
|
5
|
$params{key} = $self->{key} if $self->{key}; |
41
|
1
|
|
|
|
|
2
|
$url = $self->{base} . $url; |
42
|
1
|
|
|
|
|
6
|
$url .= "&$_=$params{$_}" for keys %params; |
43
|
1
|
|
|
|
|
22
|
my $htr = $ht->get($url); |
44
|
1
|
50
|
|
|
|
5182704
|
die $htr->{reason} unless $htr->{success}; ## no critic (RequireCarping) |
45
|
1
|
|
|
|
|
46
|
my $response = decode_json($htr->{content})->{response}; |
46
|
1
|
50
|
|
|
|
4
|
die $response->{message} unless $response->{success}; ## no critic (RequireCarping) |
47
|
1
|
|
|
|
|
8
|
$response |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new{ |
51
|
1
|
|
|
1
|
1
|
7
|
my ($class, %args) = @_; |
52
|
1
|
|
50
|
|
|
5
|
$args{base} //= 'http://backpack.tf/api/'; |
53
|
1
|
|
|
|
|
3
|
bless \%args, $class |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_prices { |
57
|
0
|
|
|
0
|
1
|
0
|
my ($self, $appid, $raw) = @_; |
58
|
0
|
|
|
|
|
0
|
my $response = $self->request('IGetPrices/v4/?compress=1', maybe appid => $appid, maybe raw => $raw); |
59
|
0
|
|
|
|
|
0
|
map { WWW::BackpackTF::Item->new($_, $response->{items}{$_}) } keys %{$response->{items}} |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_users { |
63
|
1
|
|
|
1
|
1
|
4
|
my ($self, @users) = @_; |
64
|
1
|
|
|
|
|
5
|
my $response = $self->request('IGetUsers/v3/?compress=1', steamids => join ',', @users); |
65
|
1
|
|
|
|
|
3
|
@users = map { WWW::BackpackTF::User->new($_) } values %{$response->{players}}; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
4
|
|
66
|
1
|
50
|
|
|
|
9
|
wantarray ? @users : $users[0] |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_currencies { |
70
|
0
|
|
|
0
|
1
|
|
my ($self, $appid) = @_; |
71
|
0
|
|
|
|
|
|
my $response = $self->request('IGetCurrencies/v1/?compress=1', maybe appid => $appid); |
72
|
0
|
|
|
|
|
|
map { WWW::BackpackTF::Currency->new($_, $response->{currencies}{$_}) } keys %{$response->{currencies}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# get_price_history not implemented |
76
|
|
|
|
|
|
|
# get_special_items not implemented |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_market_prices { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $appid) = @_; |
80
|
0
|
|
|
|
|
|
my $response = $self->request('IGetMarketPrices/v1/?compress=1', maybe appid => $appid); |
81
|
0
|
|
|
|
|
|
map { WWW::BackpackTF::MarketItem->new($_, $response->{items}{$_}) } keys %{$response->{items}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_user_listings { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $steamid, $appid) = @_; |
86
|
0
|
|
|
|
|
|
my $response = $self->request('IGetUserListings/v2/?compress=1', steamid => $steamid, maybe appid => $appid); |
87
|
0
|
|
|
|
|
|
map { WWW::BackpackTF::Listing->new($_) } @{$response->{listings}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |