Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pyc
tags
/build
*.swp
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
== Version 0.1.0

* ported ShopifyAPI from ruby to python
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 "JadedPixel inc."

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.
Empty file removed README
Empty file.
105 changes: 105 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
= Shopify API

The ShopifyAPI library allows Python developers to programmatically
access the admin section of stores.

The API is accessed using pyactiveresource in order to provide an
interface similar to the ruby Shopify API gem. The data itself is
sent as XML over HTTP to communicate with Shopify, which provides
a web service that follows the REST principles as much as possible.

== Usage

=== Requirements

All API usage happens through Shopify applications, created by
either shop owners for their own shops, or by Shopify Partners for
use by other shop owners:

* Shop owners can create applications for themselves through their
own admin (under the Apps > Manage Apps).
* Shopify Partners create applications through their admin:
http://app.shopify.com/services/partners

For more information and detailed documentation about the API visit
http://api.shopify.com

=== Installation

First install the pre-requisites:

easy_install pyactiveresource PyYAML

Then use the setup script in the root of this source tree.

python setup.py install

=== Getting Started

ShopifyAPI uses pyactiveresource to communicate with the REST web
service. pyactiveresource has to be configured with a fully authorized
URL of a particular store first. To obtain that URL you can follow
these steps:

1. First create a new application in either the partners admin or
your store admin and write down your API_KEY and SHARED_SECRET.

2. You will need to supply two parameters to the Session class
before you instantiate it:

shopify.Session.setup(api_key=API_KEY, secret=SHARED_SECRET)

3. For application to access a shop via the API, they first need a
"token" specific to the shop, which is obtained from Shopify after
the owner has granted the application access to the shop. This can
be done by redirecting the shop owner to permission URL obtained
as follows:

shop_url = "yourshopname.myshopify.com"
permission_url = shopify.Session.create_permission_url(shop_url)

4. After visiting this URL, the shop redirects the owner to a custom
URL of your application where the "token" gets sent to (it's param
name is just "t"). Use that token to instantiate the session
that is ready to make calls to that particular shop.

token = params['t']
session = shopify.Session.new(shop_url, token)

5. Now you can finally get the fully authorized URL for that shop.
Use that URL to configure ActiveResource and you're set:

shopify.ShopifyResource.Base.site = session.site

6. Get data from that shop (returns ActiveResource instances):

shop = shopify.Shop.current()
latest_orders = shopify.Order.find()

=== Console

This package also includes the shopify_api.py script to make it easy to
open up an interactive console to use the API with a shop.

1. Go to https://yourshopname.myshopify.com/admin/api to generate a private
application and obtain your API key and password to use with your shop.

2. Use the shopify_api.py script to save the credentials for the
shop to quickly login. The script uses PyYAML to save and load
connection configurations in the same format as the ruby shopify_api.

shopify_api.py add yourshopname

Follow the prompts for the shop domain, API key and password.

3. Start the console for the connection.

shopify_api.py console

4. Enter the following for the full list of the commands.

shopify_api.py help

== Copyright

Copyright (c) 2011 "JadedPixel inc.". See LICENSE for details.
2 changes: 2 additions & 0 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from shopify.session import Session
from shopify.resources import *
22 changes: 22 additions & 0 deletions lib/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Countable(object):
@classmethod
def count(cls, options={}):
return int(cls.get("count", **options))


class Metafields(object):
def metafields(self):
return Metafield.find(resource=self.__class__.plural, resource_id=self.id)

def add_metafield(self, metafield):
if self.is_new():
raise ValueError("You can only add metafields to a resource that has been saved")

metafield._prefix_options = dict(resource=self.__class__.plural, resource_id=self.id)
metafield.save()
return metafield


class Events(object):
def events(self):
return Event.find(resource=self.__class__.plural, resource_id=self.id)
Loading