SelectPdf/UsageClient.pm

filter: Statementstmt 46.1% 12 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 45.9% 17 / 37 CC 3 SCAR 17.7
CC
3
Cov
40%
getUsage
12.0
new
2.0
BEGIN
1.0
CRAP 5.9
« SelectPdf/InvoiceClient.pm ↑ Summary SelectPdf/WebElementsClient.pm »
1 package SelectPdf::UsageClient;
2
3 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use SelectPdf::ApiClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our @ISA = qw(SelectPdf::ApiClient);
7
8 1 our $VERSION = '1.6.0';
9
10 =head1 NAME
11
12 SelectPdf::UsageClient - Get usage details for SelectPdf Online API.
13
14 =head1 METHODS
15
16 =head2 new( $apiKey )
17
18 Construct the Usage client.
19
20 my $client = SelectPdf::UsageClient->new($apiKey);
21
22 Parameters:
23
24 - $apiKey API Key.
25 =cut
26 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
27 0 my $type = shift;
28 0 my $self = $type->SUPER::new;
29
30 # API endpoint
31 0 $self->{apiEndpoint} = "https://selectpdf.com/api2/usage/";
32
33 0 $self->{parameters}{"key"} = shift;
34
35 0 bless $self, $type;
36 0 return $self;
37 }
38
39 =head2 getUsage( $getHistory )
40
41 Get API usage information with history, if specified.
42
43 my $client = SelectPdf::UsageClient->new($apiKey);
44 $usageInfo = $client->getUsage($getHistory);
45 print("Conversions remained this month: ". $usageInfo->{"available"});
46
47 Parameters:
48
49 - $getHistory Get history or not.
50
51 Returns:
52
53 - Usage information.
54 =cut
55 0 ▶sub getUsage($) {
Subroutine getUsage: not called CC=3 SCAR=24.8
Pod documented
56 0 my($self, $getHistory) = @_;
57
58 0 $self->{headers}{"Accept"} = "text/json";
59
60 0 ▶ if ($getHistory) {
Branch: 1 branch
BranchTrueFalseTotal
if ($getHistory) 0 0 0
61 0 $self->{parameters}{"get_history"} = "True";
62 }
63
64 0 my $result = $self->SUPER::performPost();
65
66 0 ▶ if ($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) { } 0 0 0
67 0 return decode_json($result);
68 }
69 else {
70 0 return {};
71 }
72 }
73
74 1 1;
« SelectPdf/InvoiceClient.pm ↑ Summary SelectPdf/WebElementsClient.pm »