8000 Merge pull request #27 from button/ty/DLC-4557 · button/button-client-python@cd75fcb · GitHub
[go: up one dir, main page]

Skip to content

Commit cd75fcb

Browse files
author
Tyler Nappy
authored
Merge pull request #27 from button/ty/DLC-4557
Ty/dlc 4557
2 parents b8770cd + 739cc8a commit cd75fcb

File tree

7 files changed

+155
-1
lines changed

7 files changed

+155
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Current Version
22
-
33

4+
2.5.0 December 5, 2017
5+
- Add links resource
6+
47
2.4.0 July 19, 2017
58
- Add customers resource
69

README.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ We currently expose the following resources to manage:
9393
* `Merchants`_
9494
* `Orders`_
9595
* `Customers`_
96+
* `Links`_
9697

9798
Accounts
9899
~~~~~~~~
@@ -236,6 +237,45 @@ Delete
236237
print(response)
237238
# <class pybutton.Response >
238239
240+
Links
241+
~~~~~~
242+
243+
Create
244+
''''''
245+
246+
.. code:: python
247+
248+
from pybutton import Client
249+
250+
client = Client('sk-XXX')
251+
252+
response = client.links.create({
253+
'url': 'https://www.jet.com',
254+
"experience": {
255+
'btn_pub_ref': 'my-pub-ref',
256+
'btn_pub_user': 'user-id',
257+
},
258+
})
259+
260+
print(response)
261+
# <class pybutton.Response merchant_id: org-XXXXXXXXXXXXXXX, ...>
262+
263+
Get Info
264+
'''
265+
266+
.. code:: python
267+
268+
from pybutton import Client
269+
270+
client = Client('sk-XXX')
271+
272+
response = client.links.get_info({
273+
"url": "https://www.jet.com",
274+
})
275+
276+
print(response)
277+
# <class pybutton.Response merchant_id: org-XXXXXXXXXXXXXXX, ...>
278+
239279
Customers
240280
~~~~~~~~~
241281

pybutton/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pybutton.resources import Customers
88
from pybutton.resources import Merchants
99
from pybutton.resources import Orders
10+
from pybutton.resources import Links
1011
from pybutton.error import ButtonClientError
1112

1213

@@ -55,6 +56,7 @@ def __init__(self, api_key, config=None):
5556
self.accounts = Accounts(api_key, config)
5657
self.merchants = Merchants(api_key, config)
5758
self.customers = Customers(api_key, config)
59+
self.links = Links(api_key, config)
5860

5961

6062
def config_with_defaults(config):

pybutton/resources/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
from pybutton.resources.accounts import Accounts
77
from pybutton.resources.customers import Customers
8+
from pybutton.resources.links import Links
89
from pybutton.resources.merchants import Merchants
910
from pybutton.resources.orders import Orders
1011

1112
__all__ = [
1213
Accounts,
1314
Customers,
15+
Links,
1416
Merchants,
1517
Orders
1618
]

pybutton/resources/links.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 pybutton.resources.resource import Resource
7+
8+
9+
class Links(Resource):
10+
'''Manages interacting with Button Links via the Button API
11+
12+
See Resource for class docstring.
13+
14+
'''
15+
16+
def _path(self):
17+
'''Format a url path
18+
19+
Args:
20+
link (dict): A dict representing the attributes of a link
21+
22+
Returns:
23+
(str): The formatted path
24+
25+
'''
26+
27+
return '/v1/links'
28+
29+
def create(self, link):
30+
'''Create a link
31+
32+
Args:
33+
link (dict): A dict representing the attributes of a link
34+
35+
Raises:
36+
pybutton.ButtonClientError
37+
38+
Returns:
39+
(pybutton.Response) The API response
40+
41+
'''
42+
43+
return self.api_post(self._path(), link)
44+
45+
def get_info(self, link):
46+
'''Get info on a link
47+
48+
Args:
49+
link (dict): A dict representing the attributes of a link for info
50+
51+
Raises:
52+
pybutton.ButtonClientError
53+
54+
Returns:
55+
(pybutton.Response) The API response
56+
57+
'''
58+
59+
return self.api_post(self._path() + '/info', link)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 unittest import TestCase
7+
from mock import Mock
8+
from mock import patch
9+
10+
from pybutton.resources import Links
11+
12+
config = {
13+
'hostname': 'api.usebutton.com',
14+
'secure': True,
15+
'port': 443,
16+
'timeout': None,
17+
}
18+
19+
20+
class LinksTestCase(TestCase):
21+
22+
def test_create(self):
23+
link = Links('https://test.com', config)
24+
link_payload = {'b': 2}
25+
link_response = {'a': 1}
26+
27+
api_post = Mock()
28+
api_post.return_value = link_response
29+
30+
with patch.object(link, 'api_post', api_post):
31+
response = link.create(link_payload)
32+
33+
self.assertEqual(response, link_response)
34+
api_post.assert_called_with('/v1/links', link_payload)
35+
36+
def test_get_info(self):
37+
link = Links('https://test.com', config)
38+
link_payload = {'b': 2}
39+
link_response = {'a': 1}
40+
41+
api_post = Mock()
42+
api_post.return_value = link_response
43+
44+
with patch.object(link, 'api_post', api_post):
45+
response = link.get_info(link_payload)
46+
47+
self.assertEqual(response, link_response)
48+
api_post.assert_called_with('/v1/links/info', link_payload)

pybutton/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.4.0'
1+
VERSION = '2.5.0'

0 commit comments

Comments
 (0)
0