blib/lib/Webservice/OVH/Me/Task.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 97 SCAR 53.5
CC
14
Cov
0%
_new
72.0
accept
12.0
refuse
12.0
CRAP 210.0
1 package Webservice::OVH::Me::Task;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Me::Task
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12
13 my $ovh = Webservice::OVH->new_from_json("credentials.json");
14
15 my $task = $ovh->domain->service->change_contact(contact_billing => 'ovhaccount-ovh');
16
17 $task->resend_email;
18  
19 =head1 DESCRIPTION
20  
21 Module only provides basic functionality for contact_change tasks.
22  
23 =head1 METHODS
24  
25 =cut
26  
27 use strict;
28 use warnings;
29 use Carp qw{ carp croak };
30  
31 our $VERSION = 0.47;
32  
33 =head2 _new
34  
35 Internal Method to create the Task object.
36 This method is not ment to be called directly.
37  
38 =over
39  
40 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object, $type - intern type
41  
42 =item * Return: L<Webservice::OVH::Me::Task>
43  
44 =item * Synopsis: Webservice::OVH::Me::Task->_new($ovh_api_wrapper, $type, $module);
45  
46 =back
47  
48 =cut
49  
50 sub _new {
51  
52 my ( $class, %params ) = @_;
53  
54 die "Missing module" unless $params{module};
55 die "Missing wrapper" unless $params{wrapper};
56 die "Missing id" unless $params{id};
57 die "Missing task type" unless $params{type};
58  
59 my $module = $params{module};
60 my $api_wrapper = $params{wrapper};
61 my $task_id = $params{id};
62 my $type = $params{type};
63  
64 die "Missing contact_id" unless $task_id;
65 die "Missing type" unless $type;
66  
67 my $response = $api_wrapper->rawCall( method => 'get', path => "/me/task/contactChange/$task_id", noSignature => 0 );
68 croak $response->error if $response->error;
69  
70 my $porperties = $response->content;
71 my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _id => $task_id, _type => $type, _properties => $porperties }, $class;
72  
73 return $self;
74 }
75  
76 =head2 type
77  
78 Returns intern type. At the moment only contact_change.
79  
80 =over
81  
82 =item * Return: VALUE
83  
84 =item * Synopsis: my $type = $task->type;
85  
86 =back
87  
88 =cut
89  
90 sub type {
91  
92 my ($self) = @_;
93  
94 return $self->{_type};
95 }
96  
97 =head2 id
98  
99 Returns the api id.
100  
101 =over
102  
103 =item * Return: VALUE
104  
105 =item * Synopsis: my $id = $task->id;
106  
107 =back
108  
109 =cut
110  
111 sub id {
112  
113 my ($self) = @_;
114  
115 return $self->{_id};
116 }
117  
118 =head2 properties
119  
120 Retrieves properties.
121 This method updates the intern property variable.
122  
123 =over
124  
125 =item * Return: HASH
126  
127 =item * Synopsis: my $properties = $task->properties;
128  
129 =back
130  
131 =cut
132  
133 sub properties {
134  
135 my ($self) = @_;
136  
137 my $task_id = $self->id;
138 my $api = $self->{_api_wrapper};
139 my $response = $api->rawCall( method => 'get', path => "/me/task/contactChange/$task_id", noSignature => 0 );
140 croak $response->error if $response->error;
141  
142 $self->{_properties} = $response->content;
143  
144 return $self->{_properties};
145 }
146  
147 =head2 accept
148  
149 Accepts a contact change.
150  
151 =over
152  
153 =item * Synopsis: $task->accept;
154  
155 =back
156  
157 =cut
158  
159 sub accept {
160  
161 my ( $self, $token ) = @_;
162  
163 croak "Missing Token" unless $token;
164  
165 my $task_id = $self->id;
166 my $api = $self->{_api_wrapper};
167 my $response = $api->rawCall( method => 'post', path => "/me/task/contactChange/$task_id/accept", body => { token => $token }, noSignature => 0 );
168 croak $response->error if $response->error;
169 }
170  
171 =head2 refuse
172  
173 Refuses a contact change.
174  
175 =over
176  
177 =item * Synopsis: $task->accept;
178  
179 =back
180  
181 =cut
182  
183 sub refuse {
184  
185 my ( $self, $token ) = @_;
186  
187 croak "Missing Token" unless $token;
188  
189 my $task_id = $self->id;
190 my $api = $self->{_api_wrapper};
191 my $response = $api->rawCall( method => 'post', path => "/me/task/contactChange/$task_id/refuse", body => { token => $token }, noSignature => 0 );
192 croak $response->error if $response->error;
193  
194 }
195  
196 =head2 resend_email
197  
198 Resends the contact change request.
199  
200 =over
201  
202 =item * Synopsis: $task->resend_email;
203  
204 =back
205  
206 =cut
207  
208 sub resend_email {
209  
210 my ($self) = @_;
211  
212 my $task_id = $self->id;
213 my $api = $self->{_api_wrapper};
214 my $response = $api->rawCall( method => 'post', path => "/me/task/contactChange/$task_id/resendEmail", body => {}, noSignature => 0 );
215 croak $response->error if $response->error;
216  
217 }
218  
219 1;