Skip to content

Commit 269dfec

Browse files
author
Will Myers
committed
Initial build
1 parent 278d0e9 commit 269dfec

22 files changed

+1254
-2
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: python
2+
python:
3+
- "2.6"
4+
- "2.7"
5+
- "3.2"
6+
- "3.3"
7+
- "3.4"
8+
- "3.5"
9+
script: python setup.py test

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.0.0 August X, 2016
2+
- Initial Release

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include LICENSE README.md

README.md

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,126 @@
1-
# button-client-python
2-
python client for the Button Order API
1+
# button-client-python [![Build Status](https://travis-ci.org/button/button-client-python.svg?branch=master)](https://travis-ci.com/button/button-client-python)
2+
3+
This module is a thin client for interacting with Button's API.
4+
5+
Please see the full [API Docs](https://www.usebutton.com/developers/api-reference) for more information. For help, check out our [Support](https://www.usebutton.com/support) page or [get in touch](https://www.usebutton.com/contact).
6+
7+
#### Supported runtimes
8+
9+
* cPython `2.6`, `2.7`, `3.2`, `3.3`, `3.4`, `3.5`
10+
11+
#### Dependencies
12+
13+
* None
14+
15+
## Usage
16+
17+
```bash
18+
pip install pybutton
19+
```
20+
21+
To create a client capable of making network requests, instantiate a `pybutton.Client` with your [API key](https://app.usebutton.com/settings/organization).
22+
23+
```python
24+
from pybutton import Client
25+
26+
client = Client('sk-XXX')
27+
```
28+
29+
The client will always attempt to raise a `pybutton.ButtonClientError` in an error condition.
30+
31+
All API requests will return a `pybutton.response.Response` instance, which supports accessing data properties from the API response as attributes. To access the raw response dict, use `#to_dict`. For instance:
32+
33+
```python
34+
from pybutton import Client
35+
from pybutton import ButtonClientError
36+
37+
client = Client("sk-XXX")
38+
39+
try:
40+
response = client.orders.get("btnorder-XXX")
41+
except ButtonClientError as e:
42+
print(e)
43+
44+
print(response)
45+
# <class pybutton.Response status: open, btn_ref: None, line_items: [], ...>
46+
47+
print(response.status)
48+
# 'open'
49+
50+
print(response.to_dict())
51+
# {'status': open, 'btn_ref': None, 'line_items': [], ...}
52+
```
53+
54+
## Resources
55+
56+
We currently expose only one resource to manage, `Orders`.
57+
58+
### Orders
59+
60+
**n.b: all currency values should be reported in the smallest possible unit of that denomination, i.e. $1.00 should be reported as `100` (i.e. 100 pennies)**
61+
62+
##### Create
63+
64+
```python
65+
from pybutton import Client
66+
67+
client = Client('sk-XXX')
68+
69+
response = client.orders.create({
70+
'total': 50,
71+
'currency': 'USD',
72+
'order_id': '2007',
73+
'finalization_date': '2017-08-02T19:26:08Z',
74+
})
75+
76+
print(response)
77+
# <class pybutton.Response total: 50, currency: 'USD', ...>
78+
```
79+
80+
##### Get
81+
82+
```python
83+
from pybutton import Client
84+
85+
client = Client('sk-XXX')
86+
87+
response = client.orders.get('btnorder-XXX')
88+
89+
print(response)
90+
# <class pybutton.Response total: 50, currency: 'USD', ...>
91+
```
92+
93+
##### Update
94+
95+
```python
96+
from pybutton import Client
97+
98+
client = Client('sk-XXX')
99+
100+
response = client.orders.update('btnorder-XXX', {
101+
'total': 60,
102+
})
103+
104+
print(response)
105+
# <class pybutton.Response total: 60, currency: 'USD', ...>
106+
```
107+
108+
##### Delete
109+
110+
```python
111+
from pybutton import Client
112+
113+
client = Client('sk-XXX')
114+
115+
response = client.orders.delete('btnorder-XXX')
116+
117+
print(response)
118+
# <class pybutton.Response >
119+
```
120+
121+
## Contributing
122+
123+
* Building the egg: `python setup.py bdist_egg`
124+
* Installing locally: `python setup.py install`
125+
* Running tests: `python setup.py test`
126+
* Running lint: `flake8`

README.rst

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
button-client-python |Build Status|
2+
===================================
3+
4+
This module is a thin client for interacting with Button's API.
5+
6+
Please see the full `API
7+
Docs <https://www.usebutton.com/developers/api-reference>`__ for more
8+
information. For help, check out our
9+
`Support <https://www.usebutton.com/support>`__ page or `get in
10+
touch <https://www.usebutton.com/contact>`__.
11+
12+
Supported runtimes
13+
^^^^^^^^^^^^^^^^^^
14+
15+
- cPython ``2.6``, ``2.7``, ``3.2``, ``3.3``, ``3.4``, ``3.5``
16+
17+
Dependencies
18+
^^^^^^^^^^^^
19+
20+
- None
21+
22+
Usage
23+
-----
24+
25+
.. code:: bash
26+
27+
pip install pybutton
28+
29+
To create a client capable of making network requests, instantiate a
30+
``pybutton.Client`` with your `API
31+
key <https://app.usebutton.com/settings/organization>`__.
32+
33+
.. code:: python
34+
35+
from pybutton import Client
36+
37+
client = Client('sk-XXX')
38+
39+
The client will always attempt to raise a ``pybutton.ButtonClientError``
40+
in an error condition.
41+
42+
All API requests will return a ``pybutton.response.Response`` instance,
43+
which supports accessing data properties from the API response as
44+
attributes. To access the raw response dict, use ``#to_dict``. For
45+
instance:
46+
47+
.. code:: python
48+
49+
from pybutton import Client
50+
from pybutton import ButtonClientError
51+
52+
client = Client("sk-XXX")
53+
54+
try:
55+
response = client.orders.get("btnorder-XXX")
56+
except ButtonClientError as e:
57+
print(e)
58+
59+
print(response)
60+
# <class pybutton.Response status: open, btn_ref: None, line_items: [], ...>
61+
62+
print(response.status)
63+
# 'open'
64+
65+
print(response.to_dict())
66+
# {'status': open, 'btn_ref': None, 'line_items': [], ...}
67+
68+
Resources
69+
---------
70+
71+
We currently expose only one resource to manage, ``Orders``.
72+
73+
Orders
74+
~~~~~~
75+
76+
**n.b: all currency values should be reported in the smallest possible
77+
unit of that denomination, i.e. $1.00 should be reported as ``100``
78+
(i.e. 100 pennies)**
79+
80+
Create
81+
''''''
82+
83+
.. code:: python
84+
85+
from pybutton import Client
86+
87+
client = Client('sk-XXX')
88+
89+
response = client.orders.create({
90+
'total': 50,
91+
'currency': 'USD',
92+
'order_id': '2007',
93+
'finalization_date': '2017-08-02T19:26:08Z',
94+
})
95+
96+
print(response)
97+
# <class pybutton.Response total: 50, currency: 'USD', ...>
98+
99+
Get
100+
'''
101+
102+
.. code:: python
103+
104+
from pybutton import Client
105+
106+
client = Client('sk-XXX')
107+
108+
response = client.orders.get('btnorder-XXX')
109+
110+
print(response)
111+
# <class pybutton.Response total: 50, currency: 'USD', ...>
112+
113+
Update
114+
''''''
115+
116+
.. code:: python
117+
118+
from pybutton import Client
119+
120+
client = Client('sk-XXX')
121+
122+
response = client.orders.update('btnorder-XXX', {
123+
'total': 60,
124+
})
125+
126+
print(response)
127+
# <class pybutton.Response total: 60, currency: 'USD', ...>
128+
129+
Delete
130+
''''''
131+
132+
.. code:: python
133+
134+
from pybutton import Client
135+
136+
client = Client('sk-XXX')
137+
138+
response = client.orders.delete('btnorder-XXX')
139+
140+
print(response)
141+
# <class pybutton.Response >
142+
143+
Contributing
144+
------------
145+
146+
- Building the egg: ``python setup.py bdist_egg``
147+
- Installing locally: ``python setup.py install``
148+
- Running tests: ``python setup.py test``
149+
- Running lint: ``flake8``
150+
151+
.. |Build Status| image:: https://travis-ci.org/button/button-client-python.svg?branch=master
152+
:target: https://travis-ci.com/button/button-client-python

pybutton/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
5+
6+
from .client import Client
7+
from .error import ButtonClientError
8+
from .version import VERSION
9+
10+
__all__ = [Client, ButtonClientError, VERSION]

pybutton/client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
5+
6+
from .resources import Orders
7+
from .error import ButtonClientError
8+
9+
10+
class Client(object):
11+
'''Top-level interface for making requests to the Button API.
12+
13+
All resources implemented in this client will be exposed as attributes of a
14+
pybutton.Client instance.
15+
16+
Args:
17+
api_key (string): Your organization's API key. Do find yours at
18+
https://app.usebutton.com/settings/organization.
19+
20+
Attributes:
21+
orders (pybutton.Resource): Resource for managing Button Orders.
22+
23+
Raises:
24+
pybutton.ButtonClientError
25+
26+
'''
27+
28+
def __init__(self, api_key):
29+
30+
if not api_key:
31+
raise ButtonClientError((
32+
'Must provide a Button API key. Find yours at'
33+
' https://app.usebutton.com/settings/organization'
34+
))
35+
36+
self.orders = Orders(api_key)

pybutton/error.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
5+
6+
7+
class ButtonClientError(Exception):
8+
'''An Exception class for all pybutton understood errors.
9+
'''

0 commit comments

Comments
 (0)