Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
add api_key method to retrieve information about the current API key (#…
Browse files Browse the repository at this point in the history
…127)

Lets you retrieve information about the API key that was used to
make the request, e.g. to which user it belongs to.
  • Loading branch information
anneFly authored and amureki committed Jun 22, 2018
1 parent 7297d26 commit b164c36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions closeio/closeio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def _api(self):

return self._api_cache

# undocumented, hidden API - use with care
@parse_response
@handle_errors
def api_key(self):
return self._api.api_key.get()

@parse_response
@handle_errors
def me(self):
Expand Down
13 changes: 13 additions & 0 deletions closeio/contrib/testing_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,16 @@ def create_lead_export(self, query='*', format='json', fields=(),
export['id'] = len(exports) + 1
exports.append(export)
return self.get_export(export['id'])

@parse_response
def api_key(self):
return Item({
'has_more': False,
'data': [{
'date_updated': datetime.now(timezone.utc),
'date_created': datetime.now(timezone.utc),
'user_id': self.get_user(0)['id'],
'organization_id': 'xx',
'key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}],
})
3 changes: 3 additions & 0 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,6 @@ def test_create_lead_export(self, client, random_string):

def test_get_export(self, client, export):
assert client.get_export(export['id'])

def test_api_key(self, client):
assert client.api_key()

0 comments on commit b164c36

Please sign in to comment.