Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0d92719
Version Bump
Aug 21, 2015
92d6620
Add promotion parsers
Aug 21, 2015
7f627b2
Add promotion object to product.
Aug 21, 2015
8b589ac
Update readme with elementtree information
freak3dot Aug 21, 2015
72f6aa8
Formatting updates for code in readme
freak3dot Aug 21, 2015
c26454c
Merge branch 'master' of github.com:smartfile/sharpy into add-promotions
Aug 21, 2015
02b7295
Add readme for testing
freak3dot Aug 21, 2015
ded5aed
Needs line break for code to show
freak3dot Aug 21, 2015
acfc60c
Add code formatting to install line.
freak3dot Aug 21, 2015
6c05b9a
Merge branch 'master' of github.com:smartfile/sharpy into add-promotions
Aug 21, 2015
7ffa8a2
Update readme with cheddargetter unittest setup.
freak3dot Aug 24, 2015
018c6da
CheddarGetter setup will probably happen before config.
freak3dot Aug 24, 2015
35fa3cc
Update readme.rst
freak3dot Aug 24, 2015
6926b4f
Update readme.rst
freak3dot Aug 24, 2015
4d0fd82
Try to be more clean on plans.
freak3dot Aug 24, 2015
fbed197
Update readme.rst
freak3dot Aug 24, 2015
ed573e1
Update readme.rst
freak3dot Aug 24, 2015
f8f0500
Remove the debug code.
Aug 24, 2015
12d08b3
Don't request response twice. Verify response is return before trying…
Aug 24, 2015
daad8f1
Merge branch 'master' of github.com:smartfile/sharpy into add-promotions
Aug 24, 2015
6072a77
Add unit test for new methods. Skipping failing tests due to issues o…
Aug 24, 2015
3a25cdf
Update readme.rst
freak3dot Aug 27, 2015
cb4ffb8
Merge branch 'master' of github.com:smartfile/sharpy into add-promotions
Aug 27, 2015
1824bcf
parse_promotions is not needed because it is not used.
Aug 27, 2015
8408830
The convention used in the other classes is to include a __repr__. In…
Aug 27, 2015
721cd38
Also consider clearing customers a failure if success is not in the r…
Aug 27, 2015
6e22417
Remove skipped decorator from tests.
Aug 27, 2015
77af8cc
Add unittests for __repr__ and __unicode__ on the Promotion object. R…
Aug 27, 2015
696f8ac
Merge pull request #1 from smartfile/add-promotions
freak3dot Aug 27, 2015
038ea9a
I hate to be that guy but OCD. PEP8 fixes.
Aug 27, 2015
a803247
Tried to add a return and failed due to the PEP8 on the unused respon…
Aug 27, 2015
b18e794
Add docstrings to the tests. Also add a sleep for a test that fails s…
Aug 27, 2015
e527613
Merge pull request #2 from smartfile/pep8
freak3dot Aug 27, 2015
043620f
Add coupon_code to customer create and update methods. With Testing.
Aug 28, 2015
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
15 changes: 14 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Getting Started
To get started with Sharpy, simply install it like you would any other python
package

.. code::

pip install sharpy

Optionally, you can also install `lxml <http://codespeak.net/lxml/>`_ on your
Expand All @@ -50,8 +52,19 @@ Code
You can checkout and download Sharpy's latest code at `Github
<https://github.com/saaspire/sharpy>`_.

Installing elementtree for Development and Unit Testing
=======================================================
When trying to install elementtree, pip may report that there is no such package. If this happens to you, you can work around by downloading and installing it manually.

.. code::

wget http://effbot.org/media/downloads/elementtree-1.2.6-20050316.zip
unzip elementtree-1.2.6-20050316.zip
cd elementtree-1.2.6-20050316/
pip install .

TODOs
=====

* Flesh out the documentation to cover the full API.
* Add support for the various filtering options in the `get_customers` call.
* Add support for the various filtering options in the `get_customers` call.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
try:
from setuptools import setup
from setuptools import setup
except ImportError, err:
from distutils.core import setup

Expand Down
2 changes: 1 addition & 1 deletion sharpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = (0, 8)
VERSION = (0, 9)
28 changes: 18 additions & 10 deletions sharpy/client.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import base64
import logging
from urllib import urlencode
from decimal import getcontext
from dateutil.tz import tzutc
import httplib2

from sharpy.exceptions import CheddarError, AccessDenied, BadRequest, NotFound, PreconditionFailed, CheddarFailure, NaughtyGateway, UnprocessableEntity
from sharpy.exceptions import AccessDenied
from sharpy.exceptions import BadRequest
from sharpy.exceptions import CheddarError
from sharpy.exceptions import CheddarFailure
from sharpy.exceptions import NaughtyGateway
from sharpy.exceptions import NotFound
from sharpy.exceptions import PreconditionFailed
from sharpy.exceptions import UnprocessableEntity

client_log = logging.getLogger('SharpyClient')


class Client(object):
default_endpoint = 'https://cheddargetter.com/xml'
def __init__(self, username, password, product_code, cache=None, timeout=None, endpoint=None):

def __init__(self, username, password, product_code, cache=None,
timeout=None, endpoint=None):
'''
username - Your cheddargetter username (probably an email address)
password - Your cheddargetter password
Expand Down Expand Up @@ -83,7 +92,8 @@ def make_request(self, path, params=None, data=None, method=None):
method = 'POST'
body = urlencode(data)
headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'content-type':
'application/x-www-form-urlencoded; charset=UTF-8',
}

client_log.debug('Request Method: %s' % method)
Expand All @@ -92,10 +102,10 @@ def make_request(self, path, params=None, data=None, method=None):

# Setup http client
h = httplib2.Http(cache=self.cache, timeout=self.timeout)
#h.add_credentials(self.username, self.password)
# Skip the normal http client behavior and send auth headers immediately
# to save an http request.
headers['Authorization'] = "Basic %s" % base64.standard_b64encode(self.username + ':' + self.password).strip()
# Skip the normal http client behavior and send auth headers
# immediately to save an http request.
headers['Authorization'] = "Basic %s" % base64.standard_b64encode(
self.username + ':' + self.password).strip()

# Make request
response, content = h.request(url, method, body=body, headers=headers)
Expand Down Expand Up @@ -123,5 +133,3 @@ def make_request(self, path, params=None, data=None, method=None):

response.content = content
return response


28 changes: 18 additions & 10 deletions sharpy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

class CheddarError(Exception):
"Base class for exceptions returned by cheddar"

def __init__(self, response, content, *args, **kwargs):
# Importing in method to break circular dependecy
from sharpy.parsers import parse_error

super(CheddarError, self).__init__(*args, **kwargs)
error_info = parse_error(content)
self.response = response
self.error_info = error_info

def __str__(self):
return '%s (%s) %s - %s' % (
self.response.status,
Expand All @@ -20,42 +20,50 @@ def __str__(self):
self.error_info['message'],
)


class AccessDenied(CheddarError):
"A request to cheddar returned a status code of 401"
pass



class BadRequest(CheddarError):
"A request to cheddar was invalid in some way"
pass


class NotFound(CheddarError):
"A request to chedder was made for a resource which doesn't exist"
pass



class CheddarFailure(CheddarError):
"A request to cheddar encountered an unexpected error on the cheddar side"
pass



class PreconditionFailed(CheddarError):
"A request to cheddar was made but failed CG's validation in some way."
pass



class NaughtyGateway(CheddarError):
"""
Cheddar either couldn't contact the gateway or the gateway did something
very unexpected.
"""
pass



class UnprocessableEntity(CheddarError):
"""
An error occurred during processing. Please fix the error and try again.
"""
pass



class ParseError(Exception):
"""
Sharpy recieved unknown output from cheddar and doesn't know what
to do with it.
"""
pass
pass
Loading