| 1 | package plenigo::OffersManager; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | plenigo::OffersManager - Handles plenigo managed offers. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use plenigo::OffersManager; | ||
| 10 | |||
| 11 | # Prepare configuration | ||
| 12 | |||
| 13 | my $use_stage = 0; # set if stage system should be used | ||
| 14 | my $configuration = plenigo::Configuration->new(access_token => 'ACCESS_TOKEN', use_stage => $use_stage); | ||
| 15 | |||
| 16 | # Get all plenigo offers for the current company. | ||
| 17 | |||
| 18 | my $offers_manager = plenigo::OffersManager->new(configuration => $configuration); | ||
| 19 | my %offer_list = $offers_manager->getAllOffers(0, 10); | ||
| 20 | |||
| 21 | # Get a specific plenigo managed offer. | ||
| 22 | |||
| 23 | my %offer = $offers_manager->getOfferDetail('OFFER_ID'); | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | plenigo::OffersManager offers functionality for handling plenigo managed offers. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | use Moo; | ||
| 32 | use Carp qw(confess); | ||
| 33 | use plenigo::Ex; | ||
| 34 | use plenigo::RestClient; | ||
| 35 | |||
| 36 | our $VERSION = '3.0002'; | ||
| 37 | |||
| 38 | has configuration => ( | ||
| 39 | is => 'ro', | ||
| 40 | required => 1 | ||
| 41 | ); | ||
| 42 | |||
| 43 | =head2 getOfferDetail($offer_id) | ||
| 44 | |||
| 45 | Get a plenigo managed offers specified by the offer id. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub getOfferDetail { | ||
| 50 | my ($self, $offer_id) = @_; | ||
| 51 | |||
| 52 | my $rest_client = plenigo::RestClient->new(configuration => $self->configuration); | ||
| 53 | my %result = $rest_client->get('products/offers/' . $offer_id); | ||
| 54 | if ($result{'response_code'} == 404) { | ||
| 55 | plenigo::Ex->throw({ code => 404, message => 'There is no offer for the offer id passed.' }); | ||
| 56 | } | ||
| 57 | else { | ||
| 58 | return %{$result{'response_content'}}; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | =head2 getAllOffers() | ||
| 63 | |||
| 64 | Get all plenigo managed offers | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub getAllOffers { | ||
| 69 | my ($self, $startingAfter, $size) = @_; | ||
| 70 | $size //= 10; | ||
| 71 | |||
| 72 | my $rest_client = plenigo::RestClient->new(configuration => $self->configuration); | ||
| 73 | my %result = $rest_client->get('products/offers', { size => $size, startingAfter => $startingAfter }); | ||
| 74 | return %{$result{'response_content'}}; | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; |