-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
74 lines (57 loc) · 2.5 KB
/
client.py
File metadata and controls
74 lines (57 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from pybutton.resources import Accounts
from pybutton.resources import Customers
from pybutton.resources import Merchants
from pybutton.resources import Orders
from pybutton.resources import Links
from pybutton.resources import Transactions
from pybutton.error import ButtonClientError
class Client(object):
"""Top-level interface for making requests to the Button API.
All resources implemented in this client will be exposed as attributes of a
pybutton.Client instance.
Args:
api_key (string): Your organization's API key. Do find yours at
https://app.usebutton.com/settings/organization.
config (dict): Configuration options for the client. Options include:
hostname: Defaults to api.usebutton.com.
port: Defaults to 443 if config.secure, else defaults to 80.
secure: Whether or not to use HTTPS. Defaults to True.
timeout: The time in seconds for network requests to abort.
Defaults to None.
(N.B: Button's API is only exposed through HTTPS. This option is
provided purely as a convenience for testing and development.)
api_version: A specific API version label to use for the request
Attributes:
orders (pybutton.Resource): Resource for managing Button Orders.
Raises:
pybutton.ButtonClientError
"""
def __init__(self, api_key, config=None):
if not api_key:
raise ButtonClientError((
'Must provide a Button API key. Find yours at'
' https://app.usebutton.com/settings/organization'
))
if config is None:
config = {}
config = config_with_defaults(config)
self.orders = Orders(api_key, config)
self.accounts = Accounts(api_key, config)
self.merchants = Merchants(api_key, config)
self.customers = Customers(api_key, config)
self.links = Links(api_key, config)
self.transactions = Transactions(api_key, config)
def config_with_defaults(config):
secure = config.get('secure', True)
defaultPort = 443 if secure else 80
return {
'secure': secure,
'timeout': config.get('timeout'),
'hostname': config.get('hostname', 'api.usebutton.com'),
'port': config.get('port', defaultPort),
'api_version': config.get('api_version'),
}