PrePAN

Sign in to PrePAN

WebServices::Zazzle Zazzle REST API Order Integration

Author
troby@github
Date
URL
https://github.com/troby/zazzle
Status
In Review
Good

Synopsis

          All methods except for new() return a hash reference formatted by
       XML::Simple.  Nested elements are converted by ForceArray, and probably
       use GroupTags as well to eliminate extraneous layers of indirection.

       use WebServices::Zazzle
       my $zaz = WebServices::Zazzle->new($id, $key)
           Initialize new object with VendorID, and Secret Key.

       $zaz->list_new_orders()
           Requests ListNewOrders method from Zazzle. All requests currently
           die if the returned data fails validation.

       $zaz->get_shipping_label($orderid, $weight, $format)
           Request a shipping label with specified orderid and weight. Format
           must be one of: PDF, ZPL or PNG. PDF is used as the default, but a
           warning will be produced if an invalid string is specified.

       $zaz->ack_order_new_accept($orderid)
       $zaz->ack_order_update_accept($orderid)
       $zaz->ack_order_message_accept($orderid)
           Acknowledge receipt of new orders, updates and messages from
           Zazzle.

       $zaz->ack_order_new_reject($orderid)
       $zaz->ack_order_update_reject($orderid)
       $zaz->ack_order_message_reject($orderid)
           Zazzle documentation states that the 'reject' methods will probably
           never be used, but if there is such a need, here they are.

       $zaz->list_updated_orders()
           Return updated order information from Zazzle customer support. This
           should be called regularly, and before labels are printed for
           shipment.  Use ack_order_update_accept() or
           ack_order_update_reject() to answer these updates.

       $zaz->list_order_messages()
           Fetch outstanding messages. Zazzle says these messages are rarely
           used, but this is how their customer support delivers handling
           instructions.  This should probably be checked whenever
           listupdateorders() is called.  Use ack_order_messages_accept() or
           ack_order_messages_reject() to answer these updates.

       $zaz->add_order_activity($orderid, $activity)
           Submit a message to Zazzle concerning this order. This message will
           be available to their customer support staff when they lookup an
           order.

       $zaz=>get_order($orderid)
           Fetch order data for the specified orderID.

Description

Module for integration with Zazzle.com REST API.

These methods allow for interfacing with the REST API provided by Zazzle.com for their customers. It is designed as the back-end piece to a web-based Order Management System. The construction of these methods as well as the suggested error handling followed came from the document provided by: 'Zazzle Vendor API Documentation v1.12.pdf'.

Comments

anonymouse
Anonymous
https://pause.perl.org/pause/query?ACTION=pause_namingmodules#Avoid_API_Interface_and_the_like

WebService::Zazzle is a more appropriate name.

Using the curl binary to communicate with the api is not the most portable solution, nor an obvious one. LWP::UserAgent OR HTTP::Tiny make more sense.

Populating the data and href object fields instead of returning a response object seems very unperlish. This makes more sense:

my $response = $zaz->somefunction();
my $data = $response->data;

There are plenty of WebService modules on CPAN. Take a look at some of them to get a better idea of the common and accepted practices.
anonymouse
Anonymous
Fully "snake-casing" the method names would be far more readable, just lower-casing them is a confusing halfway step.

ListNewOrders -> list_new_orders
Namespace has been changed to the suggested layout of WebServices::Zazzle.

Please give feedback on WebServices::Zazzle::DB

I will be making some of the other changes suggested as well.
Zapped WebServices::Zazzle::DB completely.

It is not within the functionality of this Module to decide how information should be stored.

Also, method names have been translated to snake-casing.
This module no longer stores in its object a list version of xml data returned from zazzle.com or the hash ref variant. Instead, response data is converted to hash reference by XML::Simple, and then returned to the calling script/project. It is then up to the user of the Module to parse this data and store it in whatever format they choose.
Major bump to revision 1.49. Zapped external binary dependency. Instead of calling curl with Open2, we now use LWP::UserAgent. Returned header is checked for 'client-warning' and dies if it exists. Otherwise, _content is parsed for valid data including existence of SUCCESS code. _content is then translated by internal method to a hash reference using XML::Simple. This hash ref is returned to the caller.

Please sign up to post a review.