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($shop_url, $api_key, $access_token);

        # 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:

        $sa->delete($_) for ($sa->get_all('Webhook'));

Very easy.

If we want to do something like update an existing product, without getting it, you can simply create a wrapper object to pass to the sub. Let's update a product's title, if all we have is the product ID.

        $sa->update(WWW::Shopify::Model::Product->new({ id => $product_id, title => "My New Title!" }));

That'll update the product title.

Now, for another example. Let's say we want to get all products that have the letter "A" in their title, and double the weight of all their variants (randomly). This is also very easy.

        my @products = $sa->get_all("Product");
        for my $variant (map { $_->variants } grep { $_->title =~ m/A/ } @products) {
                $variant->weight($variant->weight*2);
                $sa->update($variant);
        }

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 TLSv12, using the line

        LWP::UserAgent->new( ssl_opts => { SSL_version => 'TLSv12' } );

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.

        @products = $sa->get_all("Product")

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_timestamp($self)

Uses a call to Shopify to determine the DateTime on the shopify server. This can be used to synchronize things without worrying about the local clock being out of sync with Shopify.

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_count('Order', { 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. If we don't retrieve anything, we return undef.

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.

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 MD5 login signature based on the shared secret and parmaeter hash passed in. This is deprecated.

calc_hmac_login_signature($shared_secret, $%params)

Calculates the SHA256 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) 2016 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 618:

=cut found outside a pod block. Skipping to next block.