Fastly/Object/RateLimiterResponse.pm untested

filter: Statementstmt 0.0% 0 / 116 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 163 CC 7 SCAR 19.9
CC
7
Cov
0%
from_hash
20.0
_deserialize
20.0
new
2.0
CRAP 7.3
1 =begin comment
2  
3 Fastly API
4  
5 Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/)
6  
7 The version of the API Spec document: 1.0.0
8 Contact: oss@fastly.com
9  
10 =end comment
11  
12 =cut
13  
14 #
15 # NOTE: This class is auto generated.
16 # Do not edit the class manually.
17 #
18 package WebService::Fastly::Object::RateLimiterResponse;
19  
20 require 5.6.0;
21 use strict;
22 use warnings;
23 use utf8;
24 use JSON::MaybeXS qw(decode_json);
25 use Data::Dumper;
26 use Module::Runtime qw(use_module);
27 use Log::Any qw($log);
28 use Date::Parse;
29 use DateTime;
30  
31 use WebService::Fastly::Object::RateLimiter;
32 use WebService::Fastly::Object::RateLimiterResponseAllOf;
33 use WebService::Fastly::Object::ServiceIdAndVersion;
34 use WebService::Fastly::Object::Timestamps;
35  
36 use base ("Class::Accessor", "Class::Data::Inheritable");
37  
38 #
39 #
40 #
41 # NOTE: This class is auto generated. Do not edit the class manually.
42 #
43  
44 =begin comment
45  
46 Fastly API
47  
48 Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/)
49  
50 The version of the API Spec document: 1.0.0
51 Contact: oss@fastly.com
52  
53 =end comment
54  
55 =cut
56  
57 #
58 # NOTE: This class is auto generated.
59 # Do not edit the class manually.
60 #
61 __PACKAGE__->mk_classdata('attribute_map' => {});
62 __PACKAGE__->mk_classdata('openapi_types' => {});
63 __PACKAGE__->mk_classdata('method_documentation' => {});
64 __PACKAGE__->mk_classdata('class_documentation' => {});
65 __PACKAGE__->mk_classdata('openapi_nullable' => {});
66  
67 # new plain object
68 sub new {
69 my ($class, %args) = @_;
70  
71 my $self = bless {}, $class;
72  
73 $self->init(%args);
74  
75 return $self;
76 }
77  
78 # initialize the object
79 sub init
80 {
81 my ($self, %args) = @_;
82  
83 foreach my $attribute (keys %{$self->attribute_map}) {
84 my $args_key = $self->attribute_map->{$attribute};
85 $self->$attribute( $args{ $args_key } );
86 }
87 }
88  
89 # return perl hash
90 sub to_hash {
91 my $self = shift;
92 my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
93  
94 return $_hash;
95 }
96  
97 # used by JSON for serialization
98 sub TO_JSON {
99 my $self = shift;
100 my $_data = {};
101 foreach my $_key (keys %{$self->attribute_map}) {
102 $_data->{$self->attribute_map->{$_key}} = $self->{$_key};
103 }
104  
105 return $_data;
106 }
107  
108 # from Perl hashref
109 sub from_hash {
110 my ($self, $hash) = @_;
111  
112 # loop through attributes and use openapi_types to deserialize the data
113 while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
114 my $_json_attribute = $self->attribute_map->{$_key};
115 my $_is_nullable = ($self->openapi_nullable->{$_key} || 'false') eq 'true';
116 if ($_type =~ /^array\[(.+)\]$/i) { # array
117 my $_subclass = $1;
118 my @_array = ();
119 foreach my $_element (@{$hash->{$_json_attribute}}) {
120 push @_array, $self->_deserialize($_subclass, $_element, $_is_nullable);
121 }
122 $self->{$_key} = \@_array;
123 } elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
124 my $_subclass = $1;
125 my %_hash = ();
126 while (my($_key, $_element) = each %{$hash->{$_json_attribute}}) {
127 $_hash{$_key} = $self->_deserialize($_subclass, $_element, $_is_nullable);
128 }
129 $self->{$_key} = \%_hash;
130 } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime
131 $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}, $_is_nullable);
132 } else {
133 $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute);
134 }
135 }
136  
137 return $self;
138 }
139  
140 # deserialize non-array data
141 sub _deserialize {
142 my ($self, $type, $data, $is_nullable) = @_;
143 $log->debugf("deserializing %s with %s",Dumper($data), $type);
144  
145 if (!(defined $data) && $is_nullable) {
146 return undef;
147 }
148 if ($type eq 'DateTime') {
149 return DateTime->from_epoch(epoch => str2time($data));
150 } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
151 return $data;
152 } else { # hash(model)
153 my $_instance = eval "WebService::Fastly::Object::$type->new()";
154 return $_instance->from_hash($data);
155 }
156 }
157  
158  
159 __PACKAGE__->class_documentation({description => '',
160 class => 'RateLimiterResponse',
161 required => [], # TODO
162 } );
163  
164 __PACKAGE__->method_documentation({
165 'name' => {
166 datatype => 'string',
167 base_name => 'name',
168 description => 'A human readable name for the rate limiting rule.',
169 format => '',
170 read_only => 'false',
171 },
172 'uri_dictionary_name' => {
173 datatype => 'string',
174 base_name => 'uri_dictionary_name',
175 description => 'The name of a Dictionary containing URIs as keys. If not defined or `null`, all origin URIs will be rate limited.',
176 format => '',
177 read_only => 'false',
178 },
179 'http_methods' => {
180 datatype => 'ARRAY[string]',
181 base_name => 'http_methods',
182 description => 'Array of HTTP methods to apply rate limiting to.',
183 format => '',
184 read_only => 'false',
185 },
186 'rps_limit' => {
187 datatype => 'int',
188 base_name => 'rps_limit',
189 description => 'Upper limit of requests per second allowed by the rate limiter.',
190 format => '',
191 read_only => 'false',
192 },
193 'window_size' => {
194 datatype => 'int',
195 base_name => 'window_size',
196 description => 'Number of seconds during which the RPS limit must be exceeded in order to trigger a violation.',
197 format => '',
198 read_only => 'false',
199 },
200 'client_key' => {
201 datatype => 'ARRAY[string]',
202 base_name => 'client_key',
203 description => 'Array of VCL variables used to generate a counter key to identify a client. Example variables include `req.http.Fastly-Client-IP`, `req.http.User-Agent`, or a custom header like `req.http.API-Key`.',
204 format => '',
205 read_only => 'false',
206 },
207 'penalty_box_duration' => {
208 datatype => 'int',
209 base_name => 'penalty_box_duration',
210 description => 'Length of time in minutes that the rate limiter is in effect after the initial violation is detected.',
211 format => '',
212 read_only => 'false',
213 },
214 'action' => {
215 datatype => 'string',
216 base_name => 'action',
217 description => 'The action to take when a rate limiter violation is detected.',
218 format => '',
219 read_only => 'false',
220 },
221 'response' => {
222 datatype => 'HASH[string,string]',
223 base_name => 'response',
224 description => 'Custom response to be sent when the rate limit is exceeded. Required if `action` is `response`.',
225 format => '',
226 read_only => 'false',
227 },
228 'response_object_name' => {
229 datatype => 'string',
230 base_name => 'response_object_name',
231 description => 'Name of existing response object. Required if `action` is `response_object`. Note that the rate limiter response is only updated to reflect the response object content when saving the rate limiter configuration.',
232 format => '',
233 read_only => 'false',
234 },
235 'logger_type' => {
236 datatype => 'string',
237 base_name => 'logger_type',
238 description => 'Name of the type of logging endpoint to be used when action is `log_only`. The logging endpoint type is used to determine the appropriate log format to use when emitting log entries.',
239 format => '',
240 read_only => 'false',
241 },
242 'feature_revision' => {
243 datatype => 'int',
244 base_name => 'feature_revision',
245 description => 'Revision number of the rate limiting feature implementation. Defaults to the most recent revision.',
246 format => '',
247 read_only => 'false',
248 },
249 'service_id' => {
250 datatype => 'string',
251 base_name => 'service_id',
252 description => '',
253 format => '',
254 read_only => 'true',
255 },
256 'version' => {
257 datatype => 'int',
258 base_name => 'version',
259 description => '',
260 format => '',
261 read_only => 'true',
262 },
263 'created_at' => {
264 datatype => 'DateTime',
265 base_name => 'created_at',
266 description => 'Date and time in ISO 8601 format.',
267 format => 'date-time',
268 read_only => 'true',
269 },
270 'deleted_at' => {
271 datatype => 'DateTime',
272 base_name => 'deleted_at',
273 description => 'Date and time in ISO 8601 format.',
274 format => 'date-time',
275 read_only => 'true',
276 },
277 'updated_at' => {
278 datatype => 'DateTime',
279 base_name => 'updated_at',
280 description => 'Date and time in ISO 8601 format.',
281 format => 'date-time',
282 read_only => 'true',
283 },
284 'id' => {
285 datatype => 'string',
286 base_name => 'id',
287 description => 'Alphanumeric string identifying the rate limiter.',
288 format => '',
289 read_only => 'false',
290 },
291 });
292  
293 __PACKAGE__->openapi_types( {
294 'name' => 'string',
295 'uri_dictionary_name' => 'string',
296 'http_methods' => 'ARRAY[string]',
297 'rps_limit' => 'int',
298 'window_size' => 'int',
299 'client_key' => 'ARRAY[string]',
300 'penalty_box_duration' => 'int',
301 'action' => 'string',
302 'response' => 'HASH[string,string]',
303 'response_object_name' => 'string',
304 'logger_type' => 'string',
305 'feature_revision' => 'int',
306 'service_id' => 'string',
307 'version' => 'int',
308 'created_at' => 'DateTime',
309 'deleted_at' => 'DateTime',
310 'updated_at' => 'DateTime',
311 'id' => 'string'
312 } );
313  
314 __PACKAGE__->attribute_map( {
315 'name' => 'name',
316 'uri_dictionary_name' => 'uri_dictionary_name',
317 'http_methods' => 'http_methods',
318 'rps_limit' => 'rps_limit',
319 'window_size' => 'window_size',
320 'client_key' => 'client_key',
321 'penalty_box_duration' => 'penalty_box_duration',
322 'action' => 'action',
323 'response' => 'response',
324 'response_object_name' => 'response_object_name',
325 'logger_type' => 'logger_type',
326 'feature_revision' => 'feature_revision',
327 'service_id' => 'service_id',
328 'version' => 'version',
329 'created_at' => 'created_at',
330 'deleted_at' => 'deleted_at',
331 'updated_at' => 'updated_at',
332 'id' => 'id'
333 } );
334  
335 __PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
336  
337 __PACKAGE__->openapi_nullable( {
338 'uri_dictionary_name' => 'true',
339 'response' => 'true',
340 'response_object_name' => 'true',
341 'created_at' => 'true',
342 'deleted_at' => 'true',
343 'updated_at' => 'true',
344 } );
345  
346  
347 1;