File Coverage

lib/Webservice/OVH/Me/Task.pm
Criterion Covered Total %
statement 9 53 16.9
branch 0 26 0.0
condition n/a
subroutine 3 10 30.0
pod 6 6 100.0
total 18 95 18.9


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