| 1 | package Webservice::OVH::Me::Order::Detail; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Webservice::OVH::Me::Order::Details | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Webservice::OVH; | ||
| 12 | |||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||
| 14 | |||
| 15 | my $order = $ovh->me->orders->[0]; | ||
| 16 | |||
| 17 | my $details = $order->details; | ||
| 18 | |||
| 19 | foreach my $detail (@$details) { | ||
| 20 | |||
| 21 | print $detail->unit_price; | ||
| 22 | } | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | Provides access to details for an order entry. | ||
| 27 | |||
| 28 | =head1 METHODS | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Carp qw{ carp croak }; | ||
| 35 | |||
| 36 | our $VERSION = 0.47; | ||
| 37 | |||
| 38 | =head2 _new | ||
| 39 | |||
| 40 | Internal Method to create the Detail object. | ||
| 41 | This method is not ment to be called directly. | ||
| 42 | |||
| 43 | =over | ||
| 44 | |||
| 45 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object, $detail_id - api id | ||
| 46 | |||
| 47 | =item * Return: L<Webservice::OVH::Me::Order::Detail> | ||
| 48 | |||
| 49 | =item * Synopsis: Webservice::OVH::Me::Order::Detail->_new($ovh_api_wrapper, $detail_id, $module); | ||
| 50 | |||
| 51 | =back | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | sub _new { | ||
| 56 | |||
| 57 | my ( $class, %params ) = @_; | ||
| 58 | |||
| 59 | die "Missing module" unless $params{module}; | ||
| 60 | die "Missing wrapper" unless $params{wrapper}; | ||
| 61 | die "Missing id" unless $params{id}; | ||
| 62 | die "Missing order" unless $params{order}; | ||
| 63 | |||
| 64 | my $module = $params{module}; | ||
| 65 | my $api_wrapper = $params{wrapper}; | ||
| 66 | my $detail_id = $params{id}; | ||
| 67 | my $order = $params{order}; | ||
| 68 | my $order_id = $order->id; | ||
| 69 | |||
| 70 | my $response = $api_wrapper->rawCall( method => 'get', path => "/me/order/$order_id/details/$detail_id", noSignature => 0 ); | ||
| 71 | croak $response->error if $response->error; | ||
| 72 | |||
| 73 | my $porperties = $response->content; | ||
| 74 | |||
| 75 | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _id => $detail_id, _properties => $porperties, _order => $order }, $class; | ||
| 76 | |||
| 77 | return $self; | ||
| 78 | } | ||
| 79 | |||
| 80 | =head2 order | ||
| 81 | |||
| 82 | Returns root Order object. | ||
| 83 | |||
| 84 | =over | ||
| 85 | |||
| 86 | =item * Return: L<Webservice::OVH::Me::Order> | ||
| 87 | |||
| 88 | =item * Synopsis: my $order = $datail->order; | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | sub order { | ||
| 95 | |||
| 96 | my ($self) = @_; | ||
| 97 | |||
| 98 | return $self->{_order}; | ||
| 99 | } | ||
| 100 | |||
| 101 | =head2 id | ||
| 102 | |||
| 103 | Returns the api id. | ||
| 104 | |||
| 105 | =over | ||
| 106 | |||
| 107 | =item * Return: VALUE | ||
| 108 | |||
| 109 | =item * Synopsis: my $id = $detail->id; | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | sub id { | ||
| 116 | |||
| 117 | my ($self) = @_; | ||
| 118 | |||
| 119 | return $self->{_id}; | ||
| 120 | } | ||
| 121 | |||
| 122 | =head2 properties | ||
| 123 | |||
| 124 | Retrieves properties. | ||
| 125 | This method updates the intern property variable. | ||
| 126 | |||
| 127 | =over | ||
| 128 | |||
| 129 | =item * Return: HASH | ||
| 130 | |||
| 131 | =item * Synopsis: my $properties = $detail->properties; | ||
| 132 | |||
| 133 | =back | ||
| 134 | |||
| 135 | =cut | ||
| 136 | |||
| 137 | sub properties { | ||
| 138 | |||
| 139 | my ($self) = @_; | ||
| 140 | |||
| 141 | my $api = $self->{_api_wrapper}; | ||
| 142 | my $order_id = $self->{_order}->id; | ||
| 143 | my $detail_id = $self->id; | ||
| 144 | my $response = $api->rawCall( method => 'get', path => "/me/order/$order_id/details/$detail_id", noSignature => 0 ); | ||
| 145 | croak $response->error if $response->error; | ||
| 146 | |||
| 147 | $self->{_properties} = $response->content; | ||
| 148 | return $self->{_properties}; | ||
| 149 | } | ||
| 150 | |||
| 151 | =head2 description | ||
| 152 | |||
| 153 | Exposed property value. | ||
| 154 | |||
| 155 | =over | ||
| 156 | |||
| 157 | =item * Return: VALUE | ||
| 158 | |||
| 159 | =item * Synopsis: my $description = $detail->description; | ||
| 160 | |||
| 161 | =back | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | sub description { | ||
| 166 | |||
| 167 | my ($self) = @_; | ||
| 168 | |||
| 169 | return $self->{_properties}->{description}; | ||
| 170 | } | ||
| 171 | |||
| 172 | =head2 domain | ||
| 173 | |||
| 174 | Exposed property value. | ||
| 175 | |||
| 176 | =over | ||
| 177 | |||
| 178 | =item * Return: VALUE | ||
| 179 | |||
| 180 | =item * Synopsis: my $domain = $detail->domain; | ||
| 181 | |||
| 182 | =back | ||
| 183 | |||
| 184 | =cut | ||
| 185 | |||
| 186 | sub domain { | ||
| 187 | |||
| 188 | my ($self) = @_; | ||
| 189 | |||
| 190 | return $self->{_properties}->{domain}; | ||
| 191 | } | ||
| 192 | |||
| 193 | =head2 quantity | ||
| 194 | |||
| 195 | Exposed property value. | ||
| 196 | |||
| 197 | =over | ||
| 198 | |||
| 199 | =item * Return: VALUE | ||
| 200 | |||
| 201 | =item * Synopsis: my $quantity = $detail->quantity; | ||
| 202 | |||
| 203 | =back | ||
| 204 | |||
| 205 | =cut | ||
| 206 | |||
| 207 | sub quantity { | ||
| 208 | |||
| 209 | my ($self) = @_; | ||
| 210 | |||
| 211 | return $self->{_properties}->{quantity}; | ||
| 212 | } | ||
| 213 | |||
| 214 | =head2 total_price | ||
| 215 | |||
| 216 | Exposed property value. | ||
| 217 | |||
| 218 | =over | ||
| 219 | |||
| 220 | =item * Return: VALUE | ||
| 221 | |||
| 222 | =item * Synopsis: my $total_price = $detail->total_price; | ||
| 223 | |||
| 224 | =back | ||
| 225 | |||
| 226 | =cut | ||
| 227 | |||
| 228 | sub total_price { | ||
| 229 | |||
| 230 | my ($self) = @_; | ||
| 231 | |||
| 232 | return $self->{_properties}->{totalPrice}; | ||
| 233 | } | ||
| 234 | |||
| 235 | =head2 unit_price | ||
| 236 | |||
| 237 | Exposed property value. | ||
| 238 | |||
| 239 | =over | ||
| 240 | |||
| 241 | =item * Return: VALUE | ||
| 242 | |||
| 243 | =item * Synopsis: my $unit_price = $detail->unit_price; | ||
| 244 | |||
| 245 | =back | ||
| 246 | |||
| 247 | =cut | ||
| 248 | |||
| 249 | sub unit_price { | ||
| 250 | |||
| 251 | my ($self) = @_; | ||
| 252 | |||
| 253 | return $self->{_properties}->{unitPrice}; | ||
| 254 | } | ||
| 255 | |||
| 256 | 1; |