Configuration.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 117 CC 7 SCAR 24.0
CC
7
Cov
0%
get_tokens
20.0
accept_tokens
20.0
new
2.0
CRAP 11.0
1 =begin comment
2
3 Aspose.3D Cloud API Reference
4
5 No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
6
7 OpenAPI spec version: 3.0
8
9 Generated by: https://github.com/swagger-api/swagger-codegen.git
10
11 =end comment
12
13 =cut
14
15 #
16 # NOTE: This class is auto generated by the swagger code generator program.
17 # Do not edit the class manually.
18 # Ref: https://github.com/swagger-api/swagger-codegen
19 #
20 package AsposeThreeDCloud::Configuration;
21
22 use strict;
23 use warnings;
24 use utf8;
25
26 use Log::Any qw($log);
27 use Carp;
28
29 use constant VERSION => '20.5';
30
31 =head1 Name
32
33 AsposeThreeDCloud::Configuration - holds the configuration for all AsposeThreeDCloud Modules
34
35 =head1 new(%parameters)
36
37 =over 4
38
39 =item http_timeout: (optional)
40
41 Integer. timeout for HTTP requests in seconds
42
43 default: 180
44
45 =item http_user_agent: (optional)
46
47 String. custom UserAgent header
48
49 default: Swagger-Codegen/20.5/perl
50
51 =item api_key: (optional)
52
53 Hashref. Keyed on the name of each key (there can be multiple tokens).
54
55 api_key => {
56 secretKey => 'aaaabbbbccccdddd',
57 anotherKey => '1111222233334444',
58 };
59
60 =item api_key_prefix: (optional)
61
62 Hashref. Keyed on the name of each key (there can be multiple tokens). Note not all api keys require a prefix.
63
64 api_key_prefix => {
65 secretKey => 'string',
66 anotherKey => 'same or some other string',
67 };
68
69 =item api_key_in: (optional)
70
71 =item username: (optional)
72
73 String. The username for basic auth.
74
75 =item password: (optional)
76
77 String. The password for basic auth.
78
79 =item access_token: (optional)
80
81 String. The OAuth access token.
82
83 =item base_url: (optional)
84
85 String. The base URL of the API
86
87 default: https://api.aspose.cloud/v3.0
88
89 =back
90
91 =cut
92
93 sub new {
94 my ($self, %p) = (shift,@_);
95
96 # class/static variables
97 $p{http_timeout} //= 180;
98 $p{http_user_agent} //= 'Swagger-Codegen/20.5/perl';
99
100 # authentication setting
101 $p{api_key} //= {};
102 $p{api_key_prefix} //= {};
103 $p{api_key_in} //= {};
104
105 # username and password for HTTP basic authentication
106 $p{username} //= '';
107 $p{password} //= '';
108
109 # access token for OAuth
110 $p{access_token} //= '';
111
112 # base_url
113 $p{base_url} //= 'https://api.aspose.cloud/v3.0';
114
115 return bless \%p => $self;
116 }
117
118
119 sub get_tokens {
120 my $self = shift;
121
122 my $tokens = {};
123 $tokens->{username} = $self->{username} if $self->{username};
124 $tokens->{password} = $self->{password} if $self->{password};
125 $tokens->{access_token} = $self->{access_token} if $self->{access_token};
126
127 foreach my $token_name (keys %{ $self->{api_key} }) {
128 $tokens->{$token_name}->{token} = $self->{api_key}{$token_name};
129 $tokens->{$token_name}->{prefix} = $self->{api_key_prefix}{$token_name};
130 $tokens->{$token_name}->{in} = $self->{api_key_in}{$token_name};
131 }
132
133 return $tokens;
134 }
135
136 sub clear_tokens {
137 my $self = shift;
138 my %tokens = %{$self->get_tokens}; # copy
139
140 $self->{username} = '';
141 $self->{password} = '';
142 $self->{access_token} = '';
143
144 $self->{api_key} = {};
145 $self->{api_key_prefix} = {};
146 $self->{api_key_in} = {};
147
148 return \%tokens;
149 }
150
151 sub accept_tokens {
152 my ($self, $tokens) = @_;
153
154 foreach my $known_name (qw(username password access_token)) {
155 next unless $tokens->{$known_name};
156 $self->{$known_name} = delete $tokens->{$known_name};
157 }
158
159 foreach my $token_name (keys %$tokens) {
160 $self->{api_key}{$token_name} = $tokens->{$token_name}{token};
161 if ($tokens->{$token_name}{prefix}) {
162 $self->{api_key_prefix}{$token_name} = $tokens->{$token_name}{prefix};
163 }
164 my $in = $tokens->{$token_name}->{in} || 'head';
165 croak "Tokens can only go in 'head' or 'query' (not in '$in')" unless $in =~ /^(?:head|query)$/;
166 $self->{api_key_in}{$token_name} = $in;
167 }
168 }
169
170 1;