|
1 | 1 | """This module contains the basic configuration object that is used to communicate with the MapRoulette API.""" |
2 | 2 |
|
3 | | -DEFAULT_URL = 'maproulette.org' |
| 3 | +from typing import Union |
| 4 | + |
| 5 | +DEFAULT_HOSTNAME = 'maproulette.org' |
4 | 6 | DEFAULT_PROTOCOL = 'https' |
5 | 7 | DEFAULT_API_VERSION = '/api/v2' |
6 | 8 |
|
7 | 9 |
|
8 | 10 | class Configuration: |
9 | 11 | """Class for storing the configuration of the MapRoulette server""" |
10 | | - def __init__(self, url=DEFAULT_URL, protocol=DEFAULT_PROTOCOL, api_version=DEFAULT_API_VERSION, api_key=None): |
11 | | - self.url = f"{protocol}://{url}{api_version}" |
12 | | - self.base_url = f"{protocol}://{url}" |
| 12 | + def __init__(self, hostname=DEFAULT_HOSTNAME, protocol=DEFAULT_PROTOCOL, api_version=DEFAULT_API_VERSION, |
| 13 | + api_key=None, certs=None, verify=True): |
| 14 | + """Create a new configuration object to connect to the MapRoulette server. |
| 15 | +
|
| 16 | + :param hostname: Optional parameter to specify the hostname of the MapRoulette instance being addressed. Do |
| 17 | + not include the protocol (https, http). Default value is 'maproulette.org'. |
| 18 | + :type hostname: str, optional |
| 19 | + :param protocol: Optional parameter to specify the protocol to use for the connection to the MapRoulette |
| 20 | + instance being addressed such as https or http. Default value is 'https'. |
| 21 | + :type protocol: str, optional |
| 22 | + :param api_version: Optional parameter to specify the API version to use. The default is '/api/v2'. |
| 23 | + :type api_version: str, optional |
| 24 | + :param api_key: Optional parameter to pass the user-specific API key. This key is necessary for some actions. |
| 25 | + :type api_key: str, optional |
| 26 | + :param certs: Optional parameter to pass the client-side certificate and key if necessary to make |
| 27 | + connection with the MapRoulette instance being addressed. Can be either a tuple containing the cert and key |
| 28 | + file paths (in that order) or a string representing the filepath to both the cert and key stored in a single |
| 29 | + file. |
| 30 | + :type certs: str or tuple, optional |
| 31 | + :param verify: Optional parameter to specify whether to verify SSL certificates for HTTPS requests. Default |
| 32 | + is True. |
| 33 | + :type verify: bool, optional |
| 34 | + """ |
| 35 | + self.api_url = f"{protocol}://{hostname}{api_version}" |
| 36 | + self.base_url = f"{protocol}://{hostname}" |
| 37 | + self.protocol = protocol |
13 | 38 | self.headers = dict() |
14 | 39 | self.headers['apikey'] = api_key |
15 | | - self.protocol = protocol |
| 40 | + self.certs = certs |
| 41 | + self.verify = verify |
0 commit comments