File Coverage

lib/Smartcat/Client/Object/UploadedFile.pm
Criterion Covered Total %
statement 37 66 56.0
branch 0 10 0.0
condition n/a
subroutine 11 15 73.3
pod 1 4 25.0
total 49 95 51.5


line stmt bran cond sub pod time code
1              
2             =begin comment
3              
4             Smartcat Integration API
5              
6             No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
7              
8             OpenAPI spec version: v1
9              
10             Generated by: https://github.com/swagger-api/swagger-codegen.git
11              
12             =end comment
13              
14             =cut
15              
16             #
17             # NOTE: This class is auto generated by the swagger code generator program.
18             # Do not edit the class manually.
19             # Ref: https://github.com/swagger-api/swagger-codegen
20             #
21             package Smartcat::Client::Object::UploadedFile;
22              
23             require 5.6.0;
24 4     4   780 use strict;
  4         8  
  4         128  
25 4     4   21 use warnings;
  4         6  
  4         100  
26 4     4   646 use utf8;
  4         18  
  4         23  
27 4     4   785 use JSON qw(decode_json);
  4         8783  
  4         23  
28 4     4   1046 use Data::Dumper;
  4         6609  
  4         231  
29 4     4   563 use Module::Runtime qw(use_module);
  4         1844  
  4         28  
30 4     4   746 use Log::Any qw($log);
  4         8872  
  4         22  
31 4     4   3405 use Date::Parse;
  4         8122  
  4         430  
32 4     4   994 use DateTime;
  4         522008  
  4         132  
33              
34 4     4   23 use base ( "Class::Accessor", "Class::Data::Inheritable" );
  4         8  
  4         3157  
35              
36             #
37             #
38             #
39             # NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
40             # REF: https://github.com/swagger-api/swagger-codegen
41             #
42              
43             =begin comment
44              
45             Smartcat Integration API
46              
47             No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
48              
49             OpenAPI spec version: v1
50              
51             Generated by: https://github.com/swagger-api/swagger-codegen.git
52              
53             =end comment
54              
55             =cut
56              
57             #
58             # NOTE: This class is auto generated by the swagger code generator program.
59             # Do not edit the class manually.
60             # Ref: https://github.com/swagger-api/swagger-codegen
61             #
62             __PACKAGE__->mk_classdata( 'attribute_map' => {} );
63             __PACKAGE__->mk_classdata( 'swagger_types' => {} );
64             __PACKAGE__->mk_classdata( 'method_documentation' => {} );
65             __PACKAGE__->mk_classdata( 'class_documentation' => {} );
66              
67             # new object
68             sub new {
69 1     1 1 698 my ( $class, %args ) = @_;
70              
71 1         3 my $self = bless {}, $class;
72              
73 1         2 foreach my $attribute ( keys %{ $class->attribute_map } ) {
  1         4  
74 5         65 my $args_key = $class->attribute_map->{$attribute};
75 5         41 $self->$attribute( $args{$args_key} );
76             }
77              
78 1         13 return $self;
79             }
80              
81             # return perl hash
82             sub to_hash {
83 0     0 0   return decode_json( JSON->new->convert_blessed->encode(shift) );
84             }
85              
86             # used by JSON for serialization
87             sub TO_JSON {
88 0     0 0   my $self = shift;
89 0           my $_data = {};
90 0           foreach my $_key ( keys %{ $self->attribute_map } ) {
  0            
91 0 0         if ( defined $self->{$_key} ) {
92 0           $_data->{ $self->attribute_map->{$_key} } = $self->{$_key};
93             }
94             }
95 0           return $_data;
96             }
97              
98             # from Perl hashref
99             sub from_hash {
100 0     0 0   my ( $self, $hash ) = @_;
101              
102             # loop through attributes and use swagger_types to deserialize the data
103 0           while ( my ( $_key, $_type ) = each %{ $self->swagger_types } ) {
  0            
104 0           my $_json_attribute = $self->attribute_map->{$_key};
105 0 0         if ( $_type =~ /^array\[/i ) { # array
    0          
106 0           my $_subclass = substr( $_type, 6, -1 );
107 0           my @_array = ();
108 0           foreach my $_element ( @{ $hash->{$_json_attribute} } ) {
  0            
109 0           push @_array, $self->_deserialize( $_subclass, $_element );
110             }
111 0           $self->{$_key} = \@_array;
112             }
113             elsif ( exists $hash->{$_json_attribute} )
114             { #hash(model), primitive, datetime
115             $self->{$_key} =
116 0           $self->_deserialize( $_type, $hash->{$_json_attribute} );
117             }
118             else {
119 0           $log->debugf( "Warning: %s (%s) does not exist in input hash\n",
120             $_key, $_json_attribute );
121             }
122             }
123              
124 0           return $self;
125             }
126              
127             # deserialize non-array data
128             sub _deserialize {
129 0     0     my ( $self, $type, $data ) = @_;
130 0           $log->debugf( "deserializing %s with %s", Dumper($data), $type );
131              
132 0 0         if ( $type eq 'DateTime' ) {
    0          
133 0           return DateTime->from_epoch( epoch => str2time($data) );
134             }
135             elsif ( grep( /^$type$/, ( 'int', 'double', 'string', 'boolean' ) ) ) {
136 0           return $data;
137             }
138             else { # hash(model)
139 0           my $_instance = eval "Smartcat::Client::Object::$type->new()";
140 0           return $_instance->from_hash($data);
141             }
142             }
143              
144             __PACKAGE__->class_documentation(
145             {
146             description => '',
147             class => 'UploadedFile',
148             required => [], # TODO
149             }
150             );
151              
152             __PACKAGE__->method_documentation(
153             {
154             'full_name' => {
155             datatype => 'string',
156             base_name => 'FullName',
157             description => '',
158             format => '',
159             read_only => '',
160             },
161             'name' => {
162             datatype => 'string',
163             base_name => 'Name',
164             description => '',
165             format => '',
166             read_only => '',
167             },
168             'extension' => {
169             datatype => 'string',
170             base_name => 'Extension',
171             description => '',
172             format => '',
173             read_only => '',
174             },
175             'media_type' => {
176             datatype => 'string',
177             base_name => 'MediaType',
178             description => '',
179             format => '',
180             read_only => '',
181             },
182             'file_size' => {
183             datatype => 'int',
184             base_name => 'FileSize',
185             description => '',
186             format => '',
187             read_only => '',
188             },
189             }
190             );
191              
192             __PACKAGE__->swagger_types(
193             {
194             'full_name' => 'string',
195             'name' => 'string',
196             'extension' => 'string',
197             'media_type' => 'string',
198             'file_size' => 'int'
199             }
200             );
201              
202             __PACKAGE__->attribute_map(
203             {
204             'full_name' => 'FullName',
205             'name' => 'Name',
206             'extension' => 'Extension',
207             'media_type' => 'MediaType',
208             'file_size' => 'FileSize'
209             }
210             );
211              
212             __PACKAGE__->mk_accessors( keys %{ __PACKAGE__->attribute_map } );
213              
214             1;