blib/lib/Webservice/OVH/Hosting/Web/Service.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 105 SCAR 48.8
CC
11
Cov
0%
change_service_infos
56.0
_new
20.0
service_infos
6.0
CRAP 132.0
1 package Webservice::OVH::Hosting::Web::Service;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Hosting::Web::Service
8  
9 =head1 SYNOPSIS
10  
11 =head1 DESCRIPTION
12  
13 Provieds basic functionality for webhosting Services
14  
15 =head1 METHODS
16  
17 =cut
18  
19 use strict;
20 use warnings;
21 use Carp qw{ carp croak };
22 use DateTime;
23 use JSON;
24  
25 our $VERSION = 0.47;
26  
27 =head2 _new
28  
29 Internal Method to create the service object.
30 This method is not ment to be called external.
31  
32 =over
33  
34 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object
35  
36 =item * Return: L<Webservice::OVH::Hosting::Web::service>
37  
38 =item * Synopsis: Webservice::OVH::Hosting::Web::service->_new($ovh_api_wrapper, $service_name, $module);
39  
40 =back
41  
42 =cut
43  
44 sub _new {
45  
46 my ( $class, %params ) = @_;
47  
48 die "Missing module" unless $params{module};
49 die "Missing wrapper" unless $params{wrapper};
50 die "Missing id" unless $params{id};
51  
52 my $module = $params{module};
53 my $api_wrapper = $params{wrapper};
54 my $service_name = $params{id};
55  
56 my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _name => $service_name, _service_info => undef, _properties => undef }, $class;
57  
58 return $self;
59 }
60  
61 =head2 name
62  
63 Name is the unique identifier.
64  
65 =over
66  
67 =item * Return: VALUE
68  
69 =item * Synopsis: my $name = $service->name;
70  
71 =back
72  
73 =cut
74  
75 sub name {
76  
77 my ($self) = @_;
78  
79 return $self->{_name};
80 }
81  
82 =head2 service_infos
83  
84 Retrieves additional infos about the service.
85 Infos that are not part of the properties
86  
87 =over
88  
89 =item * Return: HASH
90  
91 =item * Synopsis: my $info = $service->service_info;
92  
93 =back
94  
95 =cut
96  
97 sub service_infos {
98  
99 my ($self) = @_;
100  
101 my $api = $self->{_api_wrapper};
102 my $service_name = $self->name;
103 my $response_service_info = $api->rawCall( method => 'get', path => "/hosting/web/$service_name/serviceInfos", noSignature => 0 );
104  
105 croak $response_service_info->error if $response_service_info->error;
106  
107 $self->{_service_info} = $response_service_info->content;
108  
109 return $self->{_service_info};
110 }
111  
112 =head2 change_service_infos
113  
114 Change service_infos let you change the autorenewal method for this service
115  
116 =over
117  
118 =item * Parameter: %params - key => value renew(required) => { automatic(required), delete_at_expiration(required), forced(required), period(required) }
119  
120 =item * Synopsis: $service->change_service_infos(renew => { automatic => 'yes', delete_at_expiration => 'yes', forced => 'yes', period => 12 });
121  
122 =back
123  
124 =cut
125  
126 sub change_service_infos {
127  
128 my ( $self, %params ) = @_;
129  
130 croak "Missing parameter: renew" unless $params{renew};
131  
132 my @keys = qw{ automatic delete_at_expiration forced period };
133 if ( my @missing_parameters = grep { not exists $params{renew}{$_} } @keys ) {
134  
135 croak "Missing parameter: @missing_parameters";
136 }
137  
138 my $options = {};
139 $options->{automatic} = $params{renew}{automatic} eq 'true' || $params{renew}{automatic} eq 'yes' || $params{renew}{automatic} eq '1' ? JSON::true : JSON::false;
140 $options->{deleteAtExpiration} = $params{renew}{delete_at_expiration} eq 'true' || $params{renew}{delete_at_expiration} eq 'yes' || $params{renew}{delete_at_expiration} eq '1' ? JSON::true : JSON::false;
141 $options->{forced} = $params{renew}{forced} eq 'true' || $params{renew}{forced} eq 'yes' || $params{renew}{forced} eq '1' ? JSON::true : JSON::false;
142  
143 my $api = $self->{_api_wrapper};
144 my $service_name = $self->name;
145 my $body = {};
146 $body->{renew}{period} = $params{renew}{period};
147 $body->{renew}{automatic} = $options->{automatic};
148 $body->{renew}{deleteAtExpiration} = $options->{deleteAtExpiration};
149 $body->{renew}{forced} = $options->{forced};
150  
151 my $response = $api->rawCall( method => 'put', body => $body, path => "/hosting/web/$service_name/serviceInfos", noSignature => 0 );
152 croak $response->error if $response->error;
153  
154 }
155  
156 1