| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | WWW::Shopify::Private - Main object representing private app access to a particular Shopify store. | ||
| 7 | |||
| 8 | =cut | ||
| 9 | |||
| 10 | =head1 DESCRIPTION | ||
| 11 | |||
| 12 | Inherits all methods from L<WWW::Shopify>, provides additional mechanisms to modify the used password, user-agent and url handler. | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | |||
| 19 | package WWW::Shopify::Private; | ||
| 20 | use parent 'WWW::Shopify'; | ||
| 21 | |||
| 22 | =head1 METHODS | ||
| 23 | |||
| 24 | =head2 new(url, api_key, password) | ||
| 25 | |||
| 26 | Creates a new WWW::Shopify::Private object, which allows you to make calls via the shopify private app interface.s | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | sub new { | ||
| 31 | my $package = shift; | ||
| 32 | my ($shop_url, $api_key, $password, $api_version) = @_; | ||
| 33 | my $self = $package->SUPER::new($shop_url,undef,undef,$api_version); | ||
| 34 | $self->api_key($api_key); | ||
| 35 | $self->password($password); | ||
| 36 | return $self; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub url_handler { $_[0]->{_url_handler} = $_[1] if defined $_[1]; return $_[0]->{_url_handler}; } | ||
| 40 | |||
| 41 | =head2 encode_url($url) | ||
| 42 | |||
| 43 | Modifies the requested url by prepending the api key and the password, as well as the shop's url, before sending the request off to the user agent. | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub encode_url { | ||
| 48 | my ($self, $url) = @_; | ||
| 49 | return "https://" . $self->api_key . ":" . $self->password . "@" . $self->shop_url . $url; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | =head2 api_key([$api_key]) | ||
| 54 | |||
| 55 | Gets/sets the app's access token. | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub api_key { $_[0]->{_api_key} = $_[1] if defined $_[1]; return $_[0]->{_api_key}; } | ||
| 60 | |||
| 61 | |||
| 62 | =head2 password([$new_password]) | ||
| 63 | |||
| 64 | Gets/sets the app's private password. | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub password { $_[0]->{_password} = $_[1] if defined $_[1]; return $_[0]->{_password}; } | ||
| 69 | |||
| 70 | =head1 SEE ALSO | ||
| 71 | |||
| 72 | L<WWW::Shopify::Item>, L<WWW::Shopify> | ||
| 73 | |||
| 74 | =head1 AUTHOR | ||
| 75 | |||
| 76 | Adam Harrison (adamdharrison@gmail.com) | ||
| 77 | |||
| 78 | =head1 LICENSE | ||
| 79 | |||
| 80 | See LICENSE in the main directory. | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | |||
| 85 | 1; |