| 1 | package Webservice::OVH::Order; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Webservice::OVH::Order | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Webservice::OVH; | ||
| 12 | |||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||
| 14 | |||
| 15 | my $carts = $ovh->order->carts; | ||
| 16 | my $cart_id = $carts->[0]->id; | ||
| 17 | my $cart = $ovh->order->cart($cart_id); | ||
| 18 | |||
| 19 | my $new_cart = $ovh->order->new_cart(ovh_subsidiary => 'DE'); | ||
| 20 | |||
| 21 | $ovh->order->hosting->web; | ||
| 22 | $ovh->order->email->domain; | ||
| 23 | $ovh->order->domain->zone; | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Module that support carts and domain/transfer orders at the moment | ||
| 28 | |||
| 29 | =head1 METHODS | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | use Carp qw{ carp croak }; | ||
| 36 | |||
| 37 | our $VERSION = 0.47; | ||
| 38 | |||
| 39 | # sub modules | ||
| 40 | use Webservice::OVH::Order::Cart; | ||
| 41 | use Webservice::OVH::Order::Hosting; | ||
| 42 | use Webservice::OVH::Order::Email; | ||
| 43 | use Webservice::OVH::Order::Domain; | ||
| 44 | |||
| 45 | =head2 _new | ||
| 46 | |||
| 47 | Internal Method to create the order object. | ||
| 48 | This method is not ment to be called external. | ||
| 49 | |||
| 50 | =over | ||
| 51 | |||
| 52 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object | ||
| 53 | |||
| 54 | =item * Return: L<Webservice::OVH::Order> | ||
| 55 | |||
| 56 | =item * Synopsis: Webservice::OVH::Order->_new($ovh_api_wrapper, $self); | ||
| 57 | |||
| 58 | =back | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub _new { | ||
| 63 | |||
| 64 | my ( $class, %params ) = @_; | ||
| 65 | |||
| 66 | die "Missing module" unless $params{module}; | ||
| 67 | die "Missing wrapper" unless $params{wrapper}; | ||
| 68 | |||
| 69 | my $module = $params{module}; | ||
| 70 | my $api_wrapper = $params{wrapper}; | ||
| 71 | |||
| 72 | my $hosting = Webservice::OVH::Order::Hosting->_new( wrapper => $api_wrapper, module => $module ); | ||
| 73 | my $email = Webservice::OVH::Order::Email->_new( wrapper => $api_wrapper, module => $module ); | ||
| 74 | my $domain = Webservice::OVH::Order::Domain->_new( wrapper => $api_wrapper, module => $module ); | ||
| 75 | |||
| 76 | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _cards => {}, _hosting => $hosting, _email => $email, _domain => $domain }, $class; | ||
| 77 | |||
| 78 | return $self; | ||
| 79 | } | ||
| 80 | |||
| 81 | =head2 new_cart | ||
| 82 | |||
| 83 | Creates a new 'shopping' cart. | ||
| 84 | Items can be put into it, to create orders. | ||
| 85 | |||
| 86 | =over | ||
| 87 | |||
| 88 | =item * Parameter: %params - key => value (required) ovh_subsidiary => 'DE' (optional) expire => DateTime-str description => "shopping" | ||
| 89 | |||
| 90 | =item * Return: L<Webservice::OVH::Order::Cart> | ||
| 91 | |||
| 92 | =item * Synopsis: my $cart = $ovh->order->new_cart(ovh_subsidiary => 'DE'); | ||
| 93 | |||
| 94 | =back | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | sub new_cart { | ||
| 99 | |||
| 100 | my ( $self, %params ) = @_; | ||
| 101 | |||
| 102 | my $api = $self->{_api_wrapper}; | ||
| 103 | my $cart = Webservice::OVH::Order::Cart->_new( wrapper => $api, module => $self->{_module}, %params ); | ||
| 104 | return $cart; | ||
| 105 | } | ||
| 106 | |||
| 107 | =head2 carts | ||
| 108 | |||
| 109 | Produces an array of all available carts that are connected to the used account. | ||
| 110 | |||
| 111 | =over | ||
| 112 | |||
| 113 | =item * Return: ARRAY | ||
| 114 | |||
| 115 | =item * Synopsis: my $carts = $ovh->order->carts(); | ||
| 116 | |||
| 117 | =back | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | sub carts { | ||
| 122 | |||
| 123 | my ($self) = @_; | ||
| 124 | |||
| 125 | my $api = $self->{_api_wrapper}; | ||
| 126 | my $response = $api->rawCall( method => 'get', path => "/order/cart", noSignature => 0 ); | ||
| 127 | croak $response->error if $response->error; | ||
| 128 | |||
| 129 | my $card_ids = $response->content; | ||
| 130 | my $cards = []; | ||
| 131 | |||
| 132 | foreach my $card_id (@$card_ids) { | ||
| 133 | |||
| 134 | my $card = $self->{_cards}{$card_id} = $self->{_cards}{$card_id} || Webservice::OVH::Order::Cart->_new_existing( wrapper => $api, id => $card_id, module => $self->{_module} ); | ||
| 135 | push @$cards, $card; | ||
| 136 | } | ||
| 137 | |||
| 138 | return $cards; | ||
| 139 | } | ||
| 140 | |||
| 141 | =head2 cart | ||
| 142 | |||
| 143 | Returns a single cart by id | ||
| 144 | |||
| 145 | =over | ||
| 146 | |||
| 147 | =item * Parameter: cart_id - cart id | ||
| 148 | |||
| 149 | =item * Return: L<Webservice::OVH::Order::Cart> | ||
| 150 | |||
| 151 | =item * Synopsis: my $cart = $ovh->order->cart(1234567); | ||
| 152 | |||
| 153 | =back | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | sub cart { | ||
| 158 | |||
| 159 | my ( $self, $card_id ) = @_; | ||
| 160 | |||
| 161 | my $api = $self->{_api_wrapper}; | ||
| 162 | my $from_array_card = $self->{_cards}{$card_id} if $self->{_cards}{$card_id} && $self->{_cards}{$card_id}->is_valid; | ||
| 163 | my $card = $self->{_cards}{$card_id} = $from_array_card || Webservice::OVH::Order::Cart->_new_existing( wrapper => $api, id => $card_id, module => $self->{_module} ); | ||
| 164 | return $card; | ||
| 165 | } | ||
| 166 | |||
| 167 | =head2 hosting | ||
| 168 | |||
| 169 | Gives Acces to the /order/hosting/ methods of the ovh api | ||
| 170 | |||
| 171 | =over | ||
| 172 | |||
| 173 | =item * Return: L<Webservice::OVH::Order::Hosting> | ||
| 174 | |||
| 175 | =item * Synopsis: $ovh->order->hosting | ||
| 176 | |||
| 177 | =back | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||
| 181 | sub hosting { | ||
| 182 | |||
| 183 | my ($self) = @_; | ||
| 184 | |||
| 185 | return $self->{_hosting}; | ||
| 186 | } | ||
| 187 | |||
| 188 | =head2 email | ||
| 189 | |||
| 190 | Gives Acces to the /order/email/ methods of the ovh api | ||
| 191 | |||
| 192 | =over | ||
| 193 | |||
| 194 | =item * Return: L<Webservice::OVH::Order::Email> | ||
| 195 | |||
| 196 | =item * Synopsis: $ovh->order->email | ||
| 197 | |||
| 198 | =back | ||
| 199 | |||
| 200 | =cut | ||
| 201 | |||
| 202 | sub email { | ||
| 203 | |||
| 204 | my ($self) = @_; | ||
| 205 | |||
| 206 | return $self->{_email}; | ||
| 207 | } | ||
| 208 | |||
| 209 | =head2 domain | ||
| 210 | |||
| 211 | Gives Acces to the /order/domain/ methods of the ovh api | ||
| 212 | |||
| 213 | =over | ||
| 214 | |||
| 215 | =item * Return: L<Webservice::OVH::Order::Domain> | ||
| 216 | |||
| 217 | =item * Synopsis: $ovh->order->domain | ||
| 218 | |||
| 219 | =back | ||
| 220 | |||
| 221 | =cut | ||
| 222 | |||
| 223 | sub domain { | ||
| 224 | |||
| 225 | my ($self) = @_; | ||
| 226 | |||
| 227 | return $self->{_domain}; | ||
| 228 | } | ||
| 229 | |||
| 230 | 1; |