plenigo/LoginManager.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 34 CC 2 SCAR 12.0
CC
2
Cov
0%
createLoginTokens
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package plenigo::LoginManager;
2  
3 =head1 NAME
4  
5 plenigo::LoginManager - Handles log ins of a customer.
6  
7 =head1 SYNOPSIS
8  
9 use plenigo::LoginManager;
10  
11 # Prepare configuration
12  
13 my $use_stage = 0; # set if stage system should be used
14 my $configuration = plenigo::Configuration->new(access_token => 'ACCESS_TOKEN', use_stage => $use_stage);
15
16 # create one or more login tokens for a customer to show the customer snippets
17  
18 my %loginTokens = $login_manager->createLoginTokens($customer_id);
19  
20 =head1 DESCRIPTION
21  
22 plenigo::LoginManager offers functionality to log in a customer.
23  
24 =cut
25  
26 use Moo;
27 use Carp qw(confess);
28 use plenigo::Ex;
29 use plenigo::RestClient;
30  
31 our $VERSION = '3.0002';
32  
33 has configuration => (
34 is => 'ro',
35 required => 1
36 );
37  
38 =head2 createLoginTokens($customer_id, $amount)
39  
40 Create login tokens for a customer to show the customer snippets.
41  
42 =cut
43  
44 sub createLoginTokens {
45 my ($self, $customer_id, $amount) = @_;
46 $amount //= 1;
47  
48 my $rest_client = plenigo::RestClient->new(configuration => $self->configuration);
49 my %result = $rest_client->post('customers/' . $customer_id . '/logInTokens', (amount => $amount));
50 if ($result{'response_code'} == 404) {
51 plenigo::Ex->throw({ code => 404, message => 'There is no customer for the customer id passed.' });
52 }
53 else {
54 return %{$result{'response_content'}};
55 }
56 }
57  
58 1;