-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added linters to travis * Revert "added linters to travis" This reverts commit 257b79f. * added pylint and pydocstyle to CI yml * added default pylint config * PEP328: use absolute imports * added missing DOCstrings * PEP8 attribute names must be lower case and separated by underscore * PEP8 attribute names must be lower case and separated by underscore * Revert "PEP8 attribute names must be lower case and separated by underscore" This reverts commit 2d01bb4. * Revert "Revert "PEP8 attribute names must be lower case and separated by underscore"" This reverts commit e96ef7e. revert revert! What a hoot. * PEP8 Attr names must be lower case * removed unnecessary import of object * added docstrings, converted method to static * PEP238 - use absolute import; module docstring added * added pep8 spacing * PEP8: spacing, added missing docstrings * Added docstrings, removes builtins import * Added missing docstring * reverted change to deserialize * pydocstyle linter fixes * added staticmethod back to validate_sort_input * added alt-import for mock if unavailable * removed staticmethod decorator; see comment
- Loading branch information
Showing
10 changed files
with
615 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
"""Python-based API client for DevRant.""" | ||
from __future__ import absolute_import, division, print_function | ||
from .app import DevRant | ||
from pirant.app import DevRant |
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,34 +1,77 @@ | ||
"""DevRant class providing API methods.""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
from builtins import object | ||
from .handlers import RequestHandler, ResponseHandler | ||
from pirant.handlers import RequestHandler, ResponseHandler | ||
|
||
|
||
class DevRant(object): | ||
"""API Class providing interface methods.""" | ||
|
||
def __init__(self): | ||
self.RequestHandler = RequestHandler() | ||
self.ResponseHandler = ResponseHandler() | ||
"""Initialize the class instance.""" | ||
self.request_handler = RequestHandler() | ||
self.response_handler = ResponseHandler() | ||
|
||
def get_rants(self, sort, limit, skip): | ||
response = self.RequestHandler.get_rants(sort, limit, skip) | ||
return self.ResponseHandler.get_rants_build_response(response) | ||
""" | ||
Fetch rants from API. | ||
:param sort: | ||
:param limit: | ||
:param skip: | ||
:return: | ||
""" | ||
response = self.request_handler.get_rants(sort, limit, skip) | ||
return self.response_handler.get_rants_build_response(response) | ||
|
||
def get_rant_by_id(self, rant_id): | ||
response = self.RequestHandler.get_rant_by_id(rant_id) | ||
return self.ResponseHandler.get_rant_by_id_build_response(response) | ||
""" | ||
Feth a rant by its rant ID. | ||
:param rant_id: | ||
:return: | ||
""" | ||
response = self.request_handler.get_rant_by_id(rant_id) | ||
return self.response_handler.get_rant_by_id_build_response(response) | ||
|
||
def get_weekly_rants(self, sort, skip): | ||
response = self.RequestHandler.get_weekly_rants(sort, skip) | ||
return self.ResponseHandler.get_rants_build_response(response) | ||
""" | ||
Fetch the weekly rants. | ||
:param sort: | ||
:param skip: | ||
:return: | ||
""" | ||
response = self.request_handler.get_weekly_rants(sort, skip) | ||
return self.response_handler.get_rants_build_response(response) | ||
|
||
def search_rants_by_keyword(self, keyword): | ||
response = self.RequestHandler.search_rants_by_keyword(keyword) | ||
return self.ResponseHandler.search_rants_by_keyword_build_response(response) | ||
""" | ||
Search rants by given keyword. | ||
:param keyword: | ||
:return: | ||
""" | ||
response = self.request_handler.search_rants_by_keyword(keyword) | ||
return self.response_handler.search_rants_by_keyword_build_response(response) | ||
|
||
def get_collabs(self, skip, limit): | ||
response = self.RequestHandler.get_collabs(skip, limit) | ||
return self.ResponseHandler.get_collabs_build_response(response) | ||
""" | ||
Fetch collabs from the API. | ||
:param skip: | ||
:param limit: | ||
:return: | ||
""" | ||
response = self.request_handler.get_collabs(skip, limit) | ||
return self.response_handler.get_collabs_build_response(response) | ||
|
||
def get_collab_by_id(self, collab_id): | ||
response = self.RequestHandler.get_rant_by_id(collab_id) | ||
return self.ResponseHandler.get_rant_by_id_build_response(response) | ||
""" | ||
Fetch a collab by its collab ID. | ||
:param collab_id: | ||
:return: | ||
""" | ||
response = self.request_handler.get_rant_by_id(collab_id) | ||
return self.response_handler.get_rant_by_id_build_response(response) |
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,61 +1,78 @@ | ||
"""Request and Response handlers for interfacing with the DevRant API.""" | ||
from __future__ import absolute_import, division, print_function | ||
import json | ||
import requests | ||
from builtins import object | ||
from .models import RantsResponse, RantResponse, SearchResponse | ||
from .urlbuilder import URLBuilder | ||
from pirant.models import RantsResponse, RantResponse, SearchResponse | ||
from pirant.urlbuilder import URLBuilder | ||
|
||
|
||
class ResponseHandler(object): | ||
"""Handles deserialization of API responses to pirant Response Objects.""" | ||
|
||
def __init__(self): | ||
self.RantsResponse = RantsResponse() | ||
self.RantResponse = RantResponse() | ||
self.SearchResponse = SearchResponse() | ||
"""Initialize the instance.""" | ||
self.rants_response = RantsResponse() | ||
self.rant_response = RantResponse() | ||
self.search_response = SearchResponse() | ||
|
||
def build_response(self, model, response): | ||
@staticmethod | ||
def build_response(model, response): | ||
"""Build a response for the given Response Object and model.""" | ||
json_string = json.loads(response.content) | ||
deserialized = model.deserialize(json_string) | ||
return deserialized | ||
|
||
def get_rants_build_response(self, response): | ||
return self.build_response(self.RantsResponse, response) | ||
"""Deserialize the given Rants to RantsResponse object.""" | ||
return self.build_response(self.rants_response, response) | ||
|
||
def get_rant_by_id_build_response(self, response): | ||
return self.build_response(self.RantResponse, response) | ||
"""Deserialize the given Rant to RantsResponse object.""" | ||
return self.build_response(self.rant_response, response) | ||
|
||
# pylint: disable=invalid-name | ||
def search_rants_by_keyword_build_response(self, response): | ||
return self.build_response(self.SearchResponse, response) | ||
"""Deserialize the given Search to SerachResponse object.""" | ||
return self.build_response(self.search_response, response) | ||
|
||
def get_collabs_build_response(self, response): | ||
return self.build_response(self.RantsResponse, response) | ||
"""Deserialize the given Collabs to RantsResponse object.""" | ||
return self.build_response(self.rants_response, response) | ||
|
||
|
||
class RequestHandler(object): | ||
"""Handles generating a request URL for pirant Requests.""" | ||
|
||
def __init__(self): | ||
self.UrlBuilder = URLBuilder() | ||
"""Initialize the instance.""" | ||
self.url_builder = URLBuilder() | ||
|
||
def get_rants(self, sort, limit, skip): | ||
url = self.UrlBuilder.get_rants_url(sort, limit, skip) | ||
"""Build a request to get rants, send it and return its repsonse.""" | ||
url = self.url_builder.get_rants_url(sort, limit, skip) | ||
response = requests.get(url) | ||
return response | ||
|
||
def get_rant_by_id(self, rant_id): | ||
url = self.UrlBuilder.get_rant_by_id_url(rant_id) | ||
"""Build the request to get a rant by id, send it and return its repsonse.""" | ||
url = self.url_builder.get_rant_by_id_url(rant_id) | ||
response = requests.get(url) | ||
return response | ||
|
||
def get_weekly_rants(self, sort, skip): | ||
url = self.UrlBuilder.get_weekly_rant_url(sort, skip) | ||
"""Build the request to get the weekly rants, send it and return its repsonse.""" | ||
url = self.url_builder.get_weekly_rant_url(sort, skip) | ||
response = requests.get(url) | ||
return response | ||
|
||
def search_rants_by_keyword(self, keyword): | ||
url = self.UrlBuilder.search_rants_by_keywords(keyword) | ||
"""Build the request to search for rants by keyword, send it and return its repsonse.""" | ||
url = self.url_builder.search_rants_by_keywords(keyword) | ||
response = requests.get(url) | ||
return response | ||
|
||
def get_collabs(self, skip, sort): | ||
url = self.UrlBuilder.get_collabs_url(skip, sort) | ||
"""Build the request to get all collabs, send it and return its repsonse.""" | ||
url = self.url_builder.get_collabs_url(skip, sort) | ||
response = requests.get(url) | ||
return response |
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.