| 1 | package WWW::BackpackTF; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use 5.014000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use parent qw/Exporter/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | our $VERSION = '0.002'; | |||||||||||
| 8 | 2 | our @EXPORT_OK = qw/TF2 DOTA2 CSGO/; | |||||||||||
| 9 | |||||||||||||
| 10 | use constant +{ ## no critic (Capitalization) | ||||||||||||
| 11 | 2 | 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 | ▶ | }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | BEGIN { | ||||||||||||
| 18 | 2 | ▶ | my @qualities = @{QUALITIES()}; | ||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||
| 19 | 2 | for (0 .. $#qualities) { | |||||||||||
| 20 | 30 | my $name = uc $qualities[$_]; | |||||||||||
| 21 | 30 | $name =~ y/A-Z0-9//cd; | |||||||||||
| 22 | 30 | push @EXPORT_OK, $name; | |||||||||||
| 23 | 30 | constant->import($name, $_) | |||||||||||
| 24 | } | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | use JSON::MaybeXS qw/decode_json/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 2 | ▶ | use HTTP::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 2 | ▶ | use PerlX::Maybe; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 2 | ▶ | use WWW::BackpackTF::Currency; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 2 | ▶ | use WWW::BackpackTF::Item; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 2 | ▶ | use WWW::BackpackTF::MarketItem; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 2 | ▶ | use WWW::BackpackTF::Listing; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | 2 | ▶ | use WWW::BackpackTF::User; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | |||||||||||||
| 36 | 2 | my $ht = HTTP::Tiny->new(agent => "WWW-BackpackTF/$VERSION"); | |||||||||||
| 37 | |||||||||||||
| 38 | sub request { | ||||||||||||
| 39 | 1 | ▶ | my ($self, $url, %params) = @_; | ||||||||||
|
Subroutine
request: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||
| 40 | 1 | ▶ | $params{key} = $self->{key} if $self->{key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 1 | $url = $self->{base} . $url; | |||||||||||
| 42 | 1 | $url .= "&$_=$params{$_}" for keys %params; | |||||||||||
| 43 | 1 | my $htr = $ht->get($url); | |||||||||||
| 44 | 1 | ▶ | die $htr->{reason} unless $htr->{success}; ## no critic (RequireCarping) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 1 | my $response = decode_json($htr->{content})->{response}; | |||||||||||
| 46 | 1 | ▶ | die $response->{message} unless $response->{success}; ## no critic (RequireCarping) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 1 | $response | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | sub new{ | ||||||||||||
| 51 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 52 | 1 | ▶ | $args{base} //= 'http://backpack.tf/api/'; | ||||||||||
|
Condition50%1/2
$args{"base"} //= "http://backpack.tf/api/"
MC/DC0%0/1
$args{"base"} //= "http://backpack.tf/api/"
$args{"base"}
Truth table50%1/2
A
A= $args{"base"}
| |||||||||||||
| 53 | 1 | bless \%args, $class | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | sub get_prices { | ||||||||||||
| 57 | 0 | ▶ | my ($self, $appid, $raw) = @_; | ||||||||||
|
Subroutine
get_prices: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 58 | 0 | my $response = $self->request('IGetPrices/v4/?compress=1', maybe appid => $appid, maybe raw => $raw); | |||||||||||
| 59 | 0 | map { WWW::BackpackTF::Item->new($_, $response->{items}{$_}) } keys %{$response->{items}} | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | sub get_users { | ||||||||||||
| 63 | 1 | ▶ | my ($self, @users) = @_; | ||||||||||
|
Subroutine
get_users: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 64 | 1 | my $response = $self->request('IGetUsers/v3/?compress=1', steamids => join ',', @users); | |||||||||||
| 65 | 1 | @users = map { WWW::BackpackTF::User->new($_) } values %{$response->{players}}; | |||||||||||
| 66 | 1 | ▶ | wantarray ? @users : $users[0] | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | sub get_currencies { | ||||||||||||
| 70 | 0 | ▶ | my ($self, $appid) = @_; | ||||||||||
|
Subroutine
get_currencies: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 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}}; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | # get_price_history not implemented | ||||||||||||
| 76 | # get_special_items not implemented | ||||||||||||
| 77 | |||||||||||||
| 78 | sub get_market_prices { | ||||||||||||
| 79 | 0 | ▶ | my ($self, $appid) = @_; | ||||||||||
|
Subroutine
get_market_prices: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 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}} | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | sub get_user_listings { | ||||||||||||
| 85 | 0 | ▶ | my ($self, $steamid, $appid) = @_; | ||||||||||
|
Subroutine
get_user_listings: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 86 | 0 | my $response = $self->request('IGetUserListings/v2/?compress=1', steamid => $steamid, maybe appid => $appid); | |||||||||||
| 87 | 0 | map { WWW::BackpackTF::Listing->new($_) } @{$response->{listings}} | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 2 | 1; | |||||||||||
| 91 | __END__ | ||||||||||||