-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added paging functionality to the user_api (get_user_transactions, ge…
…t_user_friends_list, and others). fixed a bug with to_json method
- Loading branch information
Showing
14 changed files
with
97 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
class BaseModel(object): | ||
def __init__(self): | ||
self.__json = None | ||
self._json = None | ||
|
||
def __str__(self): | ||
return f"{type(self).__name__}:" \ | ||
f" ({', '.join('%s=%s' % item for item in vars(self).items() if not item[0].startswith('_'))})" | ||
|
||
def to_json(self): | ||
if self.__json: | ||
return self.__json | ||
def to_json(self, original=True): | ||
if self._json and original: | ||
return self._json | ||
|
||
return dict(filter(lambda x: not x[0].startswith('_'), vars(self).items())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
class JSONSchema: | ||
|
||
@staticmethod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Page(list): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.method = None | ||
self.kwargs = {} | ||
self.current_offset = -1 | ||
|
||
def set_method(self, method, kwargs, current_offset=-1): | ||
""" | ||
set the method and kwargs for paging. current_offset is provided for routes that require offset. | ||
:param method: | ||
:param kwargs: | ||
:param current_offset: | ||
:return: | ||
""" | ||
self.method = method | ||
self.kwargs = kwargs | ||
self.current_offset = current_offset | ||
return self | ||
|
||
def get_next_page(self): | ||
""" | ||
Get the next page of data. Returns empty Page if none exists | ||
:return: | ||
""" | ||
if not self.kwargs or not self.method or len(self) == 0: | ||
return self.__init__() | ||
|
||
# use offset or before_id for paging, depending on the route | ||
if self.current_offset > -1: | ||
self.kwargs['offset'] = self.current_offset + len(self) | ||
else: | ||
self.kwargs['before_id'] = self[-1].id | ||
|
||
return self.method(**self.kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.