Skip to content

Add Accounts resource - #6

Merged
oritheorca merged 11 commits into
masterfrom
grace/accounts
Oct 13, 2016
Merged

Add Accounts resource#6
oritheorca merged 11 commits into
masterfrom
grace/accounts

Conversation

@oritheorca

@oritheorca oritheorca commented Sep 30, 2016

Copy link
Copy Markdown
Contributor

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

@griffinmyers griffinmyers left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread README.rst

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: trailing commas

Comment thread README.rst Outdated
print(response)
# <class pybutton.Response [100 elements]>

cursor = response.next()

Copy link
Copy Markdown
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?

Comment thread pybutton/request.py Outdated
HTTPError,
request,
request_url,
urlparse,

@griffinmyers griffinmyers Oct 10, 2016

Copy link
Copy Markdown
Contributor

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.

Comment thread pybutton/resources/accounts.py Outdated


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

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread pybutton/response.py Outdated

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

Copy link
Copy Markdown
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

Comment thread pybutton/response.py Outdated
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
Copy Markdown
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

Comment thread test/response_test.py Outdated
response = Response({}, response_data)
self.assertEqual(response.data(), response_data)

def test_next(self):

Copy link
Copy Markdown
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 👍

Comment thread README.rst
print(response)
# <class pybutton.Response >

Accounts

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

FYI, this is ready for another look!

@griffinmyers griffinmyers left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread README.rst Outdated
Methods
~~~~~~~

Data

Copy link
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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!

Comment thread README.rst Outdated
NextCursor
''''''''''

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

Copy link
Copy Markdown
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 :-/

Comment thread README.rst Outdated
''''''''''

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

Copy link
Copy Markdown
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.

Comment thread README.rst
cursor = response.nextCursor()

# loop through and print all transactions
while cursor:

Copy link
Copy Markdown
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.

Comment thread pybutton/request.py
return urlunsplit((scheme, netloc, path, query, ''))

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: docstring

Comment thread pybutton/response.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

update method names

Comment thread pybutton/response.py Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

response_data

Comment thread test/resources/accounts_test.py Outdated
'hostname': 'api.usebutton.com',
'secure': True,
'port': 443,
'timeout': None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: trailing comma

Comment thread CHANGELOG.md Outdated
@@ -1,3 +1,5 @@
2.0.0 October 10, 2016

Copy link
Copy Markdown
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

@griffinmyers griffinmyers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@griffinmyers

Copy link
Copy Markdown
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.

2 participants