10000 Ty/dlc 4557 by tylerjnap · Pull Request #27 · button/button-client-python · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Current Version
-

2.5.0 December 5, 2017
- Add links resource

2.4.0 July 19, 2017
- Add customers resource

Expand Down
40 changes: 40 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ We currently expose the following resources to manage:
* `Merchants`_
* `Orders`_
* `Customers`_
* `Links`_

Accounts
~~~~~~~~
Expand Down Expand Up @@ -236,6 +237,45 @@ Delete
print(response)
# <class pybutton.Response >

Links
~~~~~~

Create
''''''

.. code:: python

from pybutton import Client

client = Client('sk-XXX')

response = client.links.create({
'url': 'https://www.jet.com',
"experience": {
'btn_pub_ref': 'my-pub-ref',
'btn_pub_user': 'user-id',
},
})

print(response)
# <class pybutton.Response merchant_id: org-XXXXXXXXXXXXXXX, ...>

Get Info
'''

.. code:: python

from pybutton import Client

client = Client('sk-XXX')

response = client.links.get_info({
"url": "https://www.jet.com",
})

print(response)
# <class pybutton.Response merchant_id: org-XXXXXXXXXXXXXXX, ...>

Customers
~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions pybutton/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pybutton.resources import Customers
from pybutton.resources import Merchants
from pybutton.resources import Orders
from pybutton.resources import Links
from pybutton.error import ButtonClientError


Expand Down Expand Up @@ -55,6 +56,7 @@ def __init__(self, api_key, config=None):
self.accounts = Accounts(api_key, config)
self.merchants = Merchants(api_key, config)
self.customers = Customers(api_key, config)
self.links = Links(api_key, config)


def config_with_defaults(config):
Expand Down
2 changes: 2 additions & 0 deletions pybutton/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

from pybutton.resources.accounts import Accounts
from pybutton.resources.customers import Customers
from pybutton.resources.links import Links
from pybutton.resources.merchants import Merchants
from pybutton.resources.orders import Orders

__all__ = [
Accounts,
Customers,
Links,
Merchants,
Orders
]
59 changes: 59 additions & 0 deletions pybutton/resources/links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from pybutton.resources.resource import Resource


class Links(Resource):
'''Manages interacting with Button Links via the Button API

See Resource for class docstring.

'''

def _path(self):
'''Format a url path

Args:
link (dict): A dict representing the attributes of a link

Returns:
(str): The formatted path

'''

return '/v1/links'

def create(self, link):
'''Create a link

Args:
link (dict): A dict representing the attributes of a link

Raises:
pybutton.ButtonClientError

Returns:
(pybutton.Response) The API response

'''

return self.api_post(self._path(), link)

def get_info(self, link):
'''Get info on a link

Args:
link (dict): A dict representing the attributes of a link for info

Raises:
pybutton.ButtonClientError

Returns:
(pybutton.Response) The API response

'''

return self.api_post(self._path() + '/info', link)
48 changes: 48 additions & 0 deletions pybutton/test/resources/links_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from unittest import TestCase
from mock import Mock
from mock import patch

from pybutton.resources import Links

config = {
'hostname': 'api.usebutton.com',
'secure': True,
'port': 443,
'timeout': None,
}


class LinksTestCase(TestCase):

def test_create(self):
link = Links('https://test.com', config)
link_payload = {'b': 2}
link_response = {'a': 1}

api_post = Mock()
api_post.return_value = link_response

with patch.object(link, 'api_post', api_post):
response = link.create(link_payload)

self.assertEqual(response, link_response)
api_post.assert_called_with('/v1/links', link_payload)

def test_get_info(self):
link = Links('https://test.com', config)
link_payload = {'b': 2}
link_response = {'a': 1}

api_post = Mock()
api_post.return_value = link_response

with patch.object(link, 'api_post', api_post):
response = link.get_info(link_payload)

self.assertEqual(response, link_response)
api_post.assert_called_with('/v1/links/info', link_payload)
2 changes: 1 addition & 1 deletion pybutton/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.4.0'
VERSION = '2.5.0'
0