8000 Add Accounts resource by oritheorca · Pull Request #6 · button/button-client-python · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@oritheorca
Copy link
Contributor
@oritheorca oritheorca commented Sep 30, 2016

Accounts resource methods:

  • accounts.all
  • accounts.transactions

@oritheorca oritheorca changed the base branch from master to grace/options September 30, 2016 20:34
@oritheorca oritheorca changed the base branch from grace/options to master October 10, 2016 19:43
Copy link
Contributor
@griffinmyers griffinmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor thoughts. Let's discuss and then get this moved out!

response = client.accounts.transactions('acc-123',
start='2016-07-15T00:00:00.000Z',
end='2016-09-30T00:00:00.000Z'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing commas

README.rst Outdated
print(response)
# <class pybutton.Response [100 elements]>
cursor = response.next()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#next is somewhat of a special method name in python 2.x. It's a part of the iteration protocol that we should try to avoid colliding with. #nextCursor?

HTTPError,
request,
request_url,
urlparse,
Copy link
Contributor
@griffinmyers griffinmyers Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of exporting these functions, you could consider exporting a handy function that encapsulates the behavior you want to expose, which is converting a full URL into a query dict, I imagine.



class Accounts(Resource):
'''Manages interacting with Button Orders with the Button API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring needs update


return self.api_get('/v1/affiliation/accounts')

def transactions(self, account_id, cursor=None, start=None, end=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth spelling out in the docs what arguments are required and what are optional.


def _format_cursor(self, cursor_url):
if cursor_url:
query_string = urlparse(cursor_url)[4]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add more sanity checks around these list look-ups? I'd like to make sure the API can start returning botched URLs and this client quietly falls back to retuning None

if isinstance(self.response_data, dict):
for k, v in self.response_data.items():
values = values + ['{0}: {1}'.format(k, v)]
return '<class pybutton.Response {0}>'.format(', '.join(values))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: factor out <class pybutton.Response

response = Response({}, response_data)
self.assertEqual(response.data(), response_data)

def test_next(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests with botched next/prev commands would be 👍

print(response)
# <class pybutton.Response >
Accounts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A section in the readme talking about the nature of our pybutton.Response class is worthwhile at this point, I think!

@oritheorca
Copy link
Contributor Author

FYI, this is ready for another look!

Copy link
Contributor
@griffinmyers griffinmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm! just another round of cosmetic suggestions. Let me know when addressed and we'll get 2.0.0 out da door.

README.rst Outdated
Methods
~~~~~~~

Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because these are methods, let's leave them lowercased. A little weird, but the sections above are conceptually "Create", not meaning to refer to the method name.

README.rst Outdated
start='2016-07-15T00:00:00.000Z',
end='2016-09-30T00:00:00.000Z'
)
The format of the ``pybutton.Response`` class varies depending on whether it contains
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear what you mean by "format". The interface is always the same, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the printed output from __repr__, but you're right, this is unclear. It doesn't add much anyway, so I'll remove this part!

README.rst Outdated
NextCursor
'& A3DB #39;''''''''

For any paged resource, ``nextCursor()`` will return a cursor to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally borked my recommendation for nextCursor, we should snake_case :-/

README.rst Outdated
''''''''''

For any paged resource, ``nextCursor()`` will return a cursor to
supply for the next page of results.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If next_cursor returns None, there are no more results.

cursor = response.nextCursor()
# loop through and print all transactions
while cursor:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a cool method we can add later to the Response class... all_pages or something, where it returns a generator that yields all pages.

return urlunsplit((scheme, netloc, path, query, ''))

__all__ = [Request, urlopen, HTTPError, request, request_url]
def query_dict(url):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: docstring

It exposes all keys in the underlying response as attributes on the
instance.
It exposes the response data via the `data` method and cursors for
pagination via the `next`/`prev` methods.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update method names

Args:
attrs (dict): The underlying response value from an API call
meta (dict): The metadata from an API call
data (dict or array<dict>): The response elements from an API call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response_data

'hostname': 'api.usebutton.com',
'secure': True,
'port': 443,
'timeout': None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing comma

CHANGELOG.md Outdated
@@ -1,3 +1,5 @@
2.0.0 October 10, 2016
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to include here a point about the breaking changes to pybutton.Response

Copy link
Contributor
@griffinmyers griffinmyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@griffinmyers
Copy link
Contributor

@oritheorca oritheorca merged commit 82a7485 into master Oct 13, 2016
@oritheorca oritheorca deleted the grace/accounts branch October 13, 2016 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0