diff --git a/CHANGELOG.md b/CHANGELOG.md index 953448d..80d224c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Current Version - +2.5.0 December 5, 2017 + - Add links resource + 2.4.0 July 19, 2017 - Add customers resource diff --git a/README.rst b/README.rst index 84484f4..4f34b71 100644 --- a/README.rst +++ b/README.rst @@ -93,6 +93,7 @@ We currently expose the following resources to manage: * `Merchants`_ * `Orders`_ * `Customers`_ +* `Links`_ Accounts ~~~~~~~~ @@ -236,6 +237,45 @@ Delete print(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) + # + +Get Info +''' + +.. code:: python + + from pybutton import Client + + client = Client('sk-XXX') + + response = client.links.get_info({ + "url": "https://www.jet.com", + }) + + print(response) + # + Customers ~~~~~~~~~ diff --git a/pybutton/client.py b/pybutton/client.py index 813398a..476df32 100644 --- a/pybutton/client.py +++ b/pybutton/client.py @@ -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 @@ -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): diff --git a/pybutton/resources/__init__.py b/pybutton/resources/__init__.py index db3b057..3d2b0e9 100644 --- a/pybutton/resources/__init__.py +++ b/pybutton/resources/__init__.py @@ -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 ] diff --git a/pybutton/resources/links.py b/pybutton/resources/links.py new file mode 100644 index 0000000..205addb --- /dev/null +++ b/pybutton/resources/links.py @@ -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) diff --git a/pybutton/test/resources/links_test.py b/pybutton/test/resources/links_test.py new file mode 100644 index 0000000..d98f1f1 --- /dev/null +++ b/pybutton/test/resources/links_test.py @@ -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) diff --git a/pybutton/version.py b/pybutton/version.py index 6259394..8af1c58 100644 --- a/pybutton/version.py +++ b/pybutton/version.py @@ -1 +1 @@ -VERSION = '2.4.0' +VERSION = '2.5.0'