Class Specifications¶
This section is generated with the Sphinx autodoc extension.
PolrApi¶
This file defines the main component of the Mypolr package: the PolrApi
class.
-
class
mypolr.polr_api.
PolrApi
(api_server, api_key, api_root='/api/v2/')[source]¶ Url shorter instance that stores server and API key
Parameters: - api_server (str) – The url to your server with Polr Project installed.
- api_key (str) – The API key associated with a user on the server.
- api_root (str) – API root endpoint.
-
lookup
(lookup_url, url_key=None)[source]¶ Looks up the url_ending to obtain information about the short url.
If it exists, the API will return a dictionary with information, including the long_url that is the destination of the given short url URL.
The lookup object looks like something like this:
{ 'clicks': 42, 'created_at': { 'date': '2017-12-03 00:40:45.000000', 'timezone': 'UTC', 'timezone_type': 3 }, 'long_url': 'https://stackoverflow.com/questions/tagged/python', 'updated_at': { 'date': '2017-12-24 13:37:00.000000', 'timezone': 'UTC', 'timezone_type': 3 } }
Parameters: - lookup_url (str) – An url ending or full short url address
- url_key (str or None) – optional URL ending key for lookups against secret URLs
Returns: Lookup dictionary containing, among others things, the long url; or None if not existing
Return type: dict or None
-
lookup_no_raise
(*args, **kwargs)[source]¶ Calls PolrApi.lookup(*args, **kwargs) but returns None instead of raising module errors.
Exceptions¶
All Mypolr exceptions are inherited from MypolrError
and are defined in this file.
-
exception
mypolr.exceptions.
BadApiRequest
[source]¶ Raised when a request is malformed or otherwise is not understandable by server.
-
exception
mypolr.exceptions.
BadApiResponse
(msg='Cannot interpret API response: invalid JSON.')[source]¶ Raised when a response is malformed and cannot be interpreted as valid JSON.
Raised when a custom ending is in use and therefore cannot be created.
Parameters: custom_ending (str) – the custom ending that was unavailable
-
exception
mypolr.exceptions.
QuotaExceededError
[source]¶ Admins may assign quotas to users, and this is raised when it’s exceeded and service stopped.
-
exception
mypolr.exceptions.
ServerOrConnectionError
(caused=None)[source]¶ Raised when there is a timeout, internal server error, or any other connection error.
Raised when an invalid key has been used in a request.
This refers either to: the API_KEY used in all endpoints, or the URL_KEY optionally used at the lookup endpoint.
Parameters: msg –