Skip to content

Commit

Permalink
docstring syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Mar 27, 2018
1 parent c5be68f commit d947914
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 57 deletions.
16 changes: 8 additions & 8 deletions isogeo_pysdk/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@

class IsogeoChecker(object):
"""Complementary set of tools to make some checks on requests
to Isogeo API.
to Isogeo API.
"""

def __init__(self):
super(IsogeoChecker, self).__init__()

def check_internet_connection(self, remote_server="www.isogeo.com"):
"""Test if an internet connection is operational.
Src: http://stackoverflow.com/a/20913928/2556577.
Src: http://stackoverflow.com/a/20913928/2556577.
:param str remote_server: remote server used to check
"""
Expand All @@ -119,11 +119,11 @@ def check_bearer_validity(self, token, connect_mtd):
"""Check API Bearer token validity.
Isogeo ID delivers authentication bearers which are valid during
a certain time. So this method checks the validity of the token
with a 30 mn anticipation limit, and renews it if necessary.
See: http://tools.ietf.org/html/rfc6750#section-2
a certain time. So this method checks the validity of the token
with a 30 mn anticipation limit, and renews it if necessary.
See: http://tools.ietf.org/html/rfc6750#section-2
FI: 24h = 86400 seconds, 30 mn = 1800, 5 mn = 300
FI: 24h = 86400 seconds, 30 mn = 1800, 5 mn = 300
:param tuple token: auth bearer to check.
Structure: (bearer, expiration_date)
Expand Down Expand Up @@ -287,8 +287,8 @@ def check_is_uuid(self, uuid_str):
return False

def check_edit_tab(self, tab, md_type):
"""Check if asked tab is part of Isogeo web form.
Can also apply a strict mode to filter depending on metadata type.
"""Check if asked tab is part of Isogeo web form and reliable
with metadata type.
:param str tab: tab to check. Must be one one of EDIT_TABS attribute
:param str md_type: metadata type. Must be one one of FILTER_TYPES
Expand Down
17 changes: 9 additions & 8 deletions isogeo_pysdk/isogeo_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,18 @@ def search(self,
Available values:
* '_created': metadata creation date [DEFAULT if not relevance]
* '_modified': metadata last update
* 'title': metadata title
* 'created': data creation date (possibly None)
* 'modified': data last update date
* 'relevance': relevance score calculated by API [DEFAULT].
* '_created': metadata creation date [DEFAULT if not relevance]
* '_modified': metadata last update
* 'title': metadata title
* 'created': data creation date (possibly None)
* 'modified': data last update date
* 'relevance': relevance score calculated by API [DEFAULT].
:param str order_dir: sorting direction.
Available values:
* 'desc': descending
* 'asc': ascending
* 'desc': descending
* 'asc': ascending
:param str page_size: limits the number of results.
Useful to paginate results display. Default value: 100.
Expand Down Expand Up @@ -653,6 +653,7 @@ def keywords(self,
:param str token: API auth token
:param str specific_tag: keyword to request
:param list sub_resources: list of subresources
:param str prot: https [DEFAULT] or http
(use it only for dev and tracking needs).
"""
Expand Down
19 changes: 9 additions & 10 deletions isogeo_pysdk/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@


class IsogeoTranslator(object):
"""
Makes easier the translation of Isogeo API specific strings.
"""Makes easier the translation of Isogeo API specific strings.
:param str lang: language code to apply. EN or FR.
"""

def __init__(self, lang="FR"):
"""
Instanciate IsogeoTranslator depending on required language.
"""Instanciate IsogeoTranslator depending on required language.
:param str lang: language code to apply. EN or FR.
:param str lang: language code to apply. EN or FR.
"""
if lang == "FR":
self.translations = dict_md_fields_fr
Expand All @@ -211,12 +211,11 @@ def __init__(self, lang="FR"):
super(IsogeoTranslator, self).__init__()

def tr(self, subdomain=None, string_to_translate=""):
"""
Returns translation of string passed.
"""Returns translation of string passed.
:param str subdomain: subpart of strings dictionary.
Must be one of self.translations.keys() i.e. 'restrictions'
:param str string_to_translate: string you want to translate
:param str subdomain: subpart of strings dictionary.
Must be one of self.translations.keys() i.e. 'restrictions'
:param str string_to_translate: string you want to translate
"""
if subdomain:
# check subdomain
Expand Down
63 changes: 32 additions & 31 deletions isogeo_pysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,33 @@


class IsogeoUtils(object):
"""
Complementary set of utilitary methods and functions to make it easier
using Isogeo API.
"""Complementary set of utilitary methods and functions to make it easier
using Isogeo API.
"""
API_URLS = {"prod": "api",
"qa": "api.qa",
# "int": "api.int.hq.isogeo.fr"
}

def __init__(self, proxies=dict()):
"""
Instanciate IsogeoUtils module.
"""Instanciate IsogeoUtils module.
:param dict proxies: dictionary of proxy settings as described in
requests
(http://docs.python-requests.org/en/master/user/advanced/#proxies)
:param dict proxies: dictionary of proxy settings as described in
requests. See: http://docs.python-requests.org/en/master/user/advanced/#proxies
"""
self.platform, self.base_url = self.set_base_url()
self.proxies = proxies
super(IsogeoUtils, self).__init__()

def convert_uuid(self, in_uuid=str, mode=0):
"""
Convert a metadata UUID to its URI equivalent. And conversely.
"""Convert a metadata UUID to its URI equivalent. And conversely.
:param str in_uuid: UUID or URI to convert
:param int mode: options:
* 0 to HEX
* 1 to URN (RFC4122)\
* 2 to URN (Isogeo specific style)
:param str in_uuid: UUID or URI to convert
:param int mode: 0 to HEX
1 to URN (RFC4122)\
2 to URN (Isogeo specific style)
"""
# quick parameters check
if not isinstance(in_uuid, string_types):
Expand Down Expand Up @@ -100,11 +98,14 @@ def convert_uuid(self, in_uuid=str, mode=0):
pass

def get_isogeo_version(self, component="api", prot="https"):
"""
Get Isogeo components versions.
Authentication is no required.
"""Get Isogeo components versions.
Authentication is no required.
:param str component: options:
* api [default]
* db
* app
:param str component: one of api [default] | db | app
"""
# which component
if component == "api":
Expand Down Expand Up @@ -146,10 +147,12 @@ def get_isogeo_version(self, component="api", prot="https"):
return version_req.json().get("version")

def set_base_url(self, platform="prod"):
"""
Set API base URLs according to platform.
"""Set API base URLs according to platform.
:param str platform: one of prod | qa | int
:param str platform: options:
* prod [DEFAULT]
* qa
* int
"""
platform = platform.lower()
self.platform = platform
Expand All @@ -169,12 +172,11 @@ def set_base_url(self, platform="prod"):

# -- URLs builders -------------------------------------------------------
def get_edit_url(self, md_id=str, md_type=str, owner_id=str, tab="identification"):
"""
Constructs the edition URL of a metadata.
"""Constructs the edition URL of a metadata.
:param str md_id: metadata/resource UUID
:param str owner_id: owner UUID
:param str tab: target tab in the web form
:param str md_id: metadata/resource UUID
:param str owner_id: owner UUID
:param str tab: target tab in the web form
"""
# checks inputs
if not checker.check_is_uuid(md_id)\
Expand All @@ -192,12 +194,11 @@ def get_edit_url(self, md_id=str, md_type=str, owner_id=str, tab="identification

# -- API AUTH ------------------------------------------------------------
def credentials_loader(self, f_json, f_ini, e_vars):
"""
Loads API credentials from a file or environment variables.
"""Loads API credentials from a file or environment variables.
:param str f_json: path to the credentials JSON file:
:param str f_ini: path to the credentials INI file
:param dict e_vars: dict of environment variables names
:param str f_json: path to the credentials JSON file:
:param str f_ini: path to the credentials INI file
:param dict e_vars: dict of environment variables names
"""
if f_ini:
with open('client_secrets.json', "r") as j:
Expand Down

0 comments on commit d947914

Please sign in to comment.