Skip to content

Commit ed6ebf1

Browse files
committed
Add activate_session and clear_session methods to ShopifyResource.
These methods can be used instead of setting ShopifyResource.site directly for forward comptiblity with the coming OAuth2 changes.
1 parent 8fc5fc3 commit ed6ebf1

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

CHANGELOG

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
== Version 0.4.0
2+
3+
* Using setup.py no longer requires all dependancies
4+
* More compatiblity fixes for using the latest pyactiveresource
5+
* ShopifyResource.activate_session is not recommended over setting site
6+
directly for forward compatibility with coming OAuth2 changes.
7+
18
== Version 0.3.1
29

310
* Compatiblity fixes for using latest (unreleased) pyactiveresource

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include LICENSE
22
include CHANGELOG
3-
include README.rdoc
3+
include README.md
44
include bin/shopify_api.py

README.md

+31-15
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,53 @@ these steps:
6464
```
6565

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

7272
```python
7373
shop_url = "yourshopname.myshopify.com"
7474
permission_url = shopify.Session.create_permission_url(shop_url)
7575
```
7676

7777
4. After visiting this URL, the shop redirects the owner to a custom
78-
URL of your application where the `token` gets sent to (it's param
79-
name is just `t`) along with other parameters to ensure it was sent
80-
by Shopify. That token is used to instantiate the session so that it
81-
is ready to make calls to that particular shop.
78+
URL of your application where the encoded access token gets sent
79+
as the `t` param. The following code will validate taht the request
80+
came from Shopify, then decode the permanent access token which
81+
can be used to make API requests for this shop.
8282

8383
```python
8484
session = shopify.Session(shop_url, params)
8585
```
8686

87-
5. Now you can finally get the fully authorized URL for that shop.
88-
Use that URL to configure ActiveResource and you're set:
87+
5. Activate the session to use the access token for following API
88+
requests for the shop it was authorized for.
8989

9090
```python
91-
shopify.ShopifyResource.site = session.site
91+
shopify.ShopifyResource.activate_session(session)
9292
```
9393

94-
6. Get data from that shop (returns ActiveResource instances):
94+
6. Start making authorized API requests for that shop. Data is returned as
95+
ActiveResource instances:
9596

9697
```python
97-
shop = shopify.Shop.current()
98-
latest_orders = shopify.Order.find()
98+
# Get a list of products
99+
products = shopify.Product.find()
100+
101+
# Get a specific product
102+
product = shopify.Product.find(632910)
103+
104+
# Create a new product
105+
new_product = shopify.Product()
106+
new_product.title = "Burton Custom Freestlye 151"
107+
new_product.product_type = "Snowboard"
108+
new_product.vendor = "Burton"
109+
new_product.save()
110+
111+
# Update a product
112+
product.handle = "burton-snowboard"
113+
product.save()
99114
```
100115

101116
### Console
@@ -148,8 +163,9 @@ easy_install dist/ShopifyAPI-*.tar.gz
148163

149164
## Limitations
150165

151-
Currently there is not support for:
166+
Currently there is no support for:
152167

168+
* OAuth2
153169
* python 3
154170
* asynchronous requests
155171
* persistent connections

RELEASING

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Releasing shopify_python_api
22

33
1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4-
2. Updates version in shopify/__init__.py
4+
2. Update version in shopify/version.py
55
3. Update CHANGELOG entry for the release.
66
4. Commit the changes
77
git commit -m "Release vX.Y.Z"

shopify/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,13 @@ def __set_id(self, value):
149149
def save(self):
150150
self.errors.clear() # Bug in pyactiveresource v1.0.1, but fixed in trunk at revision 96
151151
return super(ShopifyResource, self).save()
152+
153+
@classmethod
154+
def activate_session(cls, session):
155+
cls.site = session.site
156+
157+
@classmethod
158+
def clear_session(cls):
159+
cls.site = None
160+
cls.user = None
161+
cls.password = None

shopify/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.3.1'
1+
VERSION = '0.4.0'

0 commit comments

Comments
 (0)