|
| 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 |
0 commit comments