Paubox_Email_SDK/ApiHelper.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 47 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
callToAPIByGet
2.0
callToAPIByPost
2.0
CRAP 2.0
1 package Paubox_Email_SDK::ApiHelper;
2
3 use strict;
4 use warnings;
5
6 require Exporter;
7 our @ISA = qw(Exporter);
8
9 our @EXPORT_OK = qw(
10 callToAPIByGet
11 callToAPIByPost
12 );
13
14 our $VERSION = '1.2';
15
16 use REST::Client;
17 use JSON;
18
19 #
20 # Default Constructor
21 #
22 sub new {
23 my $this = {};
24 bless $this;
25 return $this
26 }
27
28 sub callToAPIByGet {
29
30 my($class, $baseUrl, $apiUrl, $authHeader) = @_;
31
32 my $client = REST::Client -> new();
33
34 $client -> addHeader('Content-Type', 'application/json');
35 $client -> addHeader('Authorization', $authHeader);
36
37 $client -> setHost($baseUrl);
38 $client -> GET(
39 $apiUrl
40 );
41 return $client -> responseContent();
42 }
43
44 sub callToAPIByPost {
45
46 my($class, $baseUrl, $apiUrl, $authHeader, $reqBody) = @_;
47
48 my $client = REST::Client -> new();
49
50 $client -> addHeader('Content-Type', 'application/json');
51 $client -> addHeader('Authorization', $authHeader);
52 $client -> addHeader('Accept', 'application/json');
53
54 $client -> setHost($baseUrl);
55 $client -> POST(
56 $apiUrl,
57 $reqBody
58 );
59 return $client -> responseContent();
60 }
61
62 1;