File Coverage

lib/Webservice/OVH/Order/Email/Domain.pm
Criterion Covered Total %
statement 9 49 18.3
branch 0 28 0.0
condition n/a
subroutine 3 8 37.5
pod 3 4 75.0
total 15 89 16.8


line stmt bran cond sub pod time code
1             package Webservice::OVH::Order::Email::Domain;
2              
3             =encoding utf-8
4              
5             =head1 NAME
6              
7             Webservice::OVH::Order::Email::Domain
8              
9             =head1 SYNOPSIS
10              
11             use Webservice::OVH;
12            
13             my $ovh = Webservice::OVH->new_from_json("credentials.json");
14            
15             my $available_services = $ovh->order->email->domain->available_services;
16              
17             =head1 DESCRIPTION
18              
19             Provides the possibility to order MX packaged. The api methods are deprecated, but no alternative is give at the moment.
20              
21             =head1 METHODS
22              
23             =cut
24              
25 36     36   263 use strict;
  36         83  
  36         1064  
26 36     36   185 use warnings;
  36         83  
  36         969  
27 36     36   188 use Carp qw{ carp croak };
  36         73  
  36         23815  
28              
29             our $VERSION = 0.46;
30              
31             =head2 _new
32              
33             Internal Method to create the Domain object.
34             This method is not ment to be called directly.
35              
36             =over
37              
38             =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object
39              
40             =item * Return: L<Webservice::OVH::Order::Email::Domain>
41              
42             =item * Synopsis: Webservice::OVH::Order::Email::Domain->_new($ovh_api_wrapper, $module);
43              
44             =back
45              
46             =cut
47              
48             sub _new {
49            
50 0     0     my ( $class, %params ) = @_;
51              
52 0 0         die "Missing module" unless $params{module};
53 0 0         die "Missing wrapper" unless $params{wrapper};
54              
55 0           my $module = $params{module};
56 0           my $api_wrapper = $params{wrapper};
57            
58 0           my $self = bless { _module => $module, _api_wrapper => $api_wrapper}, $class;
59              
60 0           return $self;
61             }
62              
63             =head2 _new
64              
65             Returns an array of available services.
66              
67             =over
68              
69             =item * Return: L<ARRAY>
70              
71             =item * Synopsis: Webservice::OVH::Order::Email::Domain->_new($ovh_api_wrapper, $module);
72              
73             =back
74              
75             =cut
76              
77             sub available_services {
78            
79 0     0 0   my ($self) = @_;
80            
81 0           my $api = $self->{_api_wrapper};
82 0           my $response = $api->rawCall( method => 'get', path => "/order/email/domain", noSignature => 0 );
83 0 0         croak $response->error if $response->error;
84            
85 0           return $response->content;
86             }
87              
88             =head2 allowed_durations
89              
90             Returns an array of allowed durations.
91             DEPRECATED
92              
93             =over
94              
95             =item * Parameter: $domain - target domain for MX package, $offer - MX offer
96              
97             =item * Return: L<ARRAY>
98              
99             =item * Synopsis: $ovh->order->email->domain->allowed_durations('mydomain.de', '100');
100              
101             =back
102              
103             =cut
104              
105             sub allowed_durations {
106            
107 0     0 1   my ($self, $domain, $offer) = @_;
108            
109 0 0         croak "Missing offer" unless $offer;
110 0 0         croak "Missing domain" unless $domain;
111            
112 0           my $filter = Webservice::OVH::Helper->construct_filter( "domain" => $domain, "offer" => $offer );
113            
114 0           my $api = $self->{_api_wrapper};
115 0           my $response = $api->rawCall( method => 'get', path => "/order/email/domain/new$filter", noSignature => 0 );
116 0 0         croak $response->error if $response->error;
117            
118 0           return $response->content;
119             }
120              
121             =head2 allowed_durations
122              
123             Returns information for a desired MX package.
124             DEPRECATED
125              
126             =over
127              
128             =item * Parameter: $domain - target domain for MX package, $offer - MX offer, $duration - allowed duration
129              
130             =item * Return: L<ARRAY>
131              
132             =item * Synopsis: $ovh->order->email->domain->info('mydomain.de', '100', $allowed_durations->[0]);
133              
134             =back
135              
136             =cut
137              
138             sub info {
139            
140 0     0 1   my ($self, $domain, $offer, $duration) = @_;
141            
142 0 0         croak "Missing offer" unless $offer;
143 0 0         croak "Missing duration" unless $duration;
144 0 0         croak "Missing domain" unless $domain;
145            
146 0           my $filter = Webservice::OVH::Helper->construct_filter( "domain" => $domain, "offer" => $offer );
147            
148 0           my $api = $self->{_api_wrapper};
149 0           my $response = $api->rawCall( method => 'get', path => sprintf("/order/email/domain/new/%s%s", $duration, $filter), noSignature => 0 );
150 0 0         croak $response->error if $response->error;
151            
152 0           return $response->content;
153             }
154              
155             =head2 new
156              
157             Generates an order for the desired MX package.
158             DEPRECATED
159              
160             =over
161              
162             =item * Parameter: $domain - target domain for MX package, $offer - MX offer, $duration - allowed duration
163              
164             =item * Return: L<ARRAY>
165              
166             =item * Synopsis: $ovh->order->email->domain->new('mydomain.de', '100', $allowed_durations->[0]);
167              
168             =back
169              
170             =cut
171              
172             sub new {
173            
174 0     0 1   my ($self, $domain, $offer, $duration) = @_;
175            
176 0 0         croak "Missing offer" unless $offer;
177 0 0         croak "Missing duration" unless $duration;
178 0 0         croak "Missing domain" unless $domain;
179            
180 0           my $api = $self->{_api_wrapper};
181 0           my $module = $self->{_module};
182 0           my $body = { offer => $offer, domain => $domain };
183 0           my $response = $api->rawCall( method => 'post', path => "/order/email/domain/new/$duration", body => $body, noSignature => 0 );
184 0 0         croak $response->error if $response->error;
185            
186 0           my $order = $module->me->order($response->content->{orderId});
187            
188 0           return $order;
189             }
190              
191              
192             1;