NAME
WWW::Shopify - Main object representing acess to a particular Shopify store.
DISCLAIMER
WWW::Shopify is my first official CPAN module, so please bear with me as I try to sort out all the bugs, and deal with the unfamiliar CPAN infrastructure. Don't expect this to work out of the box as of yet, I'm still learning exactly how things are working. Hence some version problems I've been having.
Thanks for your understanding.
DESCRIPTION
WWW::Shopify represents a way to grab and upload data to a particular shopify store. All that's required is the access token for a particular app, its url, and the API key, or altenratively, if you have a private app, you can substitue the app password for the api key. If you want to use make a private app, use WWW::Shopify::Private. If you want to make a public app, use WWW::Shopify::Public.
EXAMPLES
In order to get a list of all products, we can do the following:
# Here we instantiate a copy of the public API object, with all the necessary fields.
my $SA = new WWW::Shopify::Public($ShopURL, $APIKey, $AccessToken);
# Here we call get_all, OO style, and specify the entity we want to get.
my @Products = $SA->get_all('Product');
In this way, we can get and modify all the different types of shopify stuffs.
If you don't want to be using a public app, and just want to make a private app, it's just as easy:
# Here we instantiate a copy of the private API object this time, which means we don't need an access token, we just need a password.
my $sa = new WWW::Shopify::Private($shop_url, $api_key, $password);
my @Products = $SA->get_all('Product');
Easy enough.
To insert a Webhook, we'd do the following.
my $webhook = new WWW::Shopify::Model::Webhook({topic => "orders/create", address => $URL, format => "json"});
$SA->create($Webhook);
And that's all there is to it. To delete all the webhooks in a store, we'd do:
my @Webhooks = $SA->get_all('Webhook');
for (@Webhooks) {
$SA->delete($_);
}
Very easy.
METHODS
new($shop_url, [$email, $pass])
Creates a new shop, without using the actual API, uses automated form submission to log in.
encode_url($url)
Basic url encoding, works the same for public apps or logged-in apps.
ua([$new_ua])
Gets/sets the user agent we're using to access shopify's api. By default we use LWP::UserAgent, with a timeout of 5 seconds.
PLEASE NOTE: At the very least, with LWP::UserAgent, at least, on my system, I had to force the SSL layer of the agent to use SSLv3, using the line
LWP::UserAgent->new( ssl_opts => { SSL_version => 'SSLv3' } );
Otherwise, Shopify does some very weird stuff, and some very weird errors are spit out. Just FYI.
shop_url([$shop_url])
Gets/sets the shop url that we're going to be making calls to.
get_all($self, $package, $filters)
Gets up to 249 * CALL_LIMIT objects (currently 124750) from Shopify at once. Goes in a loop until it's got everything. Performs a count first to see where it's at.
If you don't want this behaviour, use the limit filter.
get_shop($self)
Returns the actual shop object.
my $shop = $sa->get_shop;
get_count($self, $package, $filters)
Gets the item count from the shopify store. So if we wanted to count all our orders, we'd do:
my $order = $sa->get('Order', 142345, { status => "any" });
It's as easy as that. Keep in mind not all items are countable (who the hell knows why); a glaring exception is assets. Either check the shopify docs, or grep for the sub "countable".
get($self, $package, $id)
Gets the item from the shopify store. Returns it in local (classed up) form. In order to get an order for example:
my $order = $sa->get('Order', 142345);
It's as easy as that.
search($self, $package, $item, { query => $query })
Searches for the item from the shopify store. Not all items are searchable, check the API docs, or grep this module's source code and look for the "searchable" sub.
A popular thing to search for is customers by email, you can do so like the following:
my $customer = $sa->search("Customer", { query => "email:me@example.com" });
create($self, $item)
Creates the item on the shopify store. Not all items are creatable, check the API docs, or grep this module's source code and look for the "creatable" sub.
update($self, $item)
Updates the item from the shopify store. Not all items are updatable, check the API docs, or grep this module's source code and look for the "updatable" sub.
delete($self, $item)
Deletes the item from the shopify store. Not all items are deletable, check the API docs, or grep this module's source code and look for the "deletable" sub.
activate($self, $charge), disable($self, $discount), enable($self, $discount), open($self, $order), close($self, $order), cancel($self, $order)
Special actions that do what they say.
login_admin($self, $email, $password)
Logs you in to the shop as an admin, allowing you to create and manipulate discount codes, as well as upload files into user-space (not theme space).
Doens't get around the API call limit, unfortunately.
logged_in_admin($self)
Determines whether or not you're logged in to the Shopify store as an admin.
create_private_app()
Automates a form submission to generate a private app. Returns a WWW::Shopify::Private with the appropriate credentials. Must be logged in.
delete_private_app($private_api)
Removes a private app. Must be logged in.
upload_files($self, @image_paths)
Requires log in. Uploads an array of files/images into the shop's non-theme file/image management system by automating a form submission.
$sa->login_admin("email", "password");
$sa->upload_files("image1.jpg", "image2.jpg");
Gets around the issue that this is not actually exposed to the API.
EXPORTED FUNCTIONS
The functions below are exported as part of the package.
calc_webhook_signature($shared_secret, $request_body)
Calculates the webhook_signature based off the shared secret and request body passed in.
verify_webhook($shared_Secret, $request_body)
Shopify webhook authentication. ALMOST the same as login authentication, but, of course, because this is shopify they've got a different system. 'Cause you know, one's not good enough.
Follows this: http://wiki.shopify.com/Verifying_Webhooks.
calc_login_signature($shared_secret, $%params)
Calculates the login signature based on the shared secret and parmaeter hash passed in.
verify_login($shared_secret, $%params)
Shopify app dashboard verification (when someone clicks Login on the app dashboard).
This one was kinda random, 'cause they say it's like a webhook, but it's actually like legacy auth.
Also, they don't have a code parameter. For whatever reason.
calc_proxy_signature($shared_secret, $%params)
Based on shared secret/hash of parameters passed in, calculates the proxy signature.
verify_proxy($shared_secret, %$params)
This is SLIGHTLY different from the above two. For, as far as I can tell, no reason.
SEE ALSO
WWW::Shopify::Public, WWW::Shopify::Private, WWW::Shopify::Test, WWW::Shopify::Item, WWW::Shopify::Common::DBIx
AUTHOR
Adam Harrison (adamdharrison@gmail.com)
LICENSE
Copyright (C) 2013 Adam Harrison
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 512:
=cut found outside a pod block. Skipping to next block.