Module mercadopago.config
Module: config/init.py
Expand source code
"""
Module: config/__init__.py
"""
from mercadopago.config.config import Config
from mercadopago.config.request_options import RequestOptions
__all__ = (
'Config',
'RequestOptions',
)
Sub-modules
mercadopago.config.config-
Module: config
mercadopago.config.request_options-
Module: request_options
Classes
class Config-
General infos of your SDK
Expand source code
class Config: """ General infos of your SDK """ def __init__(self): self.__version = "2.2.0" self.__user_agent = "MercadoPago Python SDK v" + self.__version self.__product_id = "bc32bpftrpp001u8nhlg" self.__tracking_id = "platform:" + platform.python_version() self.__tracking_id += ",type:SDK" + self.__version + ",so;" __api_base_url = "https://api.mercadopago.com" __mime_json = "application/json" __mime_form = "application/x-www-form-urlencoded" @property def version(self): """ Sets the attribute value of version """ return self.__version @property def user_agent(self): """ Sets the attribute value of user agent """ return self.__user_agent @property def product_id(self): """ Sets the attribute value of product id """ return self.__product_id @property def tracking_id(self): """ Sets the attribute value of tracking id """ return self.__tracking_id @property def api_base_url(self): """ Sets the attribute value of api base url """ return self.__api_base_url @property def mime_json(self): """ Sets the attribute value of mime json """ return self.__mime_json @property def mime_form(self): """ Sets the attribute value of mime form """ return self.__mime_formInstance variables
var api_base_url-
Sets the attribute value of api base url
Expand source code
@property def api_base_url(self): """ Sets the attribute value of api base url """ return self.__api_base_url var mime_form-
Sets the attribute value of mime form
Expand source code
@property def mime_form(self): """ Sets the attribute value of mime form """ return self.__mime_form var mime_json-
Sets the attribute value of mime json
Expand source code
@property def mime_json(self): """ Sets the attribute value of mime json """ return self.__mime_json var product_id-
Sets the attribute value of product id
Expand source code
@property def product_id(self): """ Sets the attribute value of product id """ return self.__product_id var tracking_id-
Sets the attribute value of tracking id
Expand source code
@property def tracking_id(self): """ Sets the attribute value of tracking id """ return self.__tracking_id var user_agent-
Sets the attribute value of user agent
Expand source code
@property def user_agent(self): """ Sets the attribute value of user agent """ return self.__user_agent var version-
Sets the attribute value of version
Expand source code
@property def version(self): """ Sets the attribute value of version """ return self.__version
class RequestOptions (access_token=None, connection_timeout=60.0, custom_headers=None, corporation_id=None, integrator_id=None, platform_id=None, max_retries=3)-
This object hold all configurations that will be used in ur REST call.
All here u can customize as well add params in the requisition header (custom_headers)
Initialize
Args
access_token:str, optional- Your User Access Token. Defaults to None.
connection_timeout:float, optional- Time to timeout the REST call. Defaults to 60.0.
custom_headers:dict, optional- A Dict with params to be added to the requests params.
- Defaults to None.
corporation_id:str, optional- Your Corporation ID if any. Defaults to None.
integrator_id:str, optional- Your Integrator ID if any. Defaults to None.
platform_id:str, optional- Your Platform ID if any. Defaults to None.
max_retries:int, optional- How many retries must be done in case of fail.
Defaults to 3.
Raises
ValueError- Param access_token must be a String
ValueError- Param connection_timeout must be a Float
ValueError- Param custom_headers must be a Dictionary
ValueError- Param corporation_id must be a String
ValueError- Param integrator_id must be a String
ValueError- Param platform_id must be a String
ValueError- Param max_retries must be an Integer
Expand source code
class RequestOptions: # pylint: disable=too-many-instance-attributes """This object hold all configurations that will be used in ur REST call. All here u can customize as well add params in the requisition header (custom_headers) """ __access_token = None __connection_timeout = None __custom_headers = None __max_retries = None __corporation_id = None __integrator_id = None __platform_id = None def __init__( # pylint: disable=too-many-arguments self, access_token=None, connection_timeout=60.0, custom_headers=None, corporation_id=None, integrator_id=None, platform_id=None, max_retries=3, ): """Initialize Args: access_token (str, optional): Your User Access Token. Defaults to None. connection_timeout (float, optional): Time to timeout the REST call. Defaults to 60.0. custom_headers (dict, optional): A Dict with params to be added to the requests params. Defaults to None. corporation_id (str, optional): Your Corporation ID if any. Defaults to None. integrator_id (str, optional): Your Integrator ID if any. Defaults to None. platform_id (str, optional): Your Platform ID if any. Defaults to None. max_retries (int, optional): How many retries must be done in case of fail. Defaults to 3. Raises: ValueError: Param access_token must be a String ValueError: Param connection_timeout must be a Float ValueError: Param custom_headers must be a Dictionary ValueError: Param corporation_id must be a String ValueError: Param integrator_id must be a String ValueError: Param platform_id must be a String ValueError: Param max_retries must be an Integer """ if access_token is not None: self.access_token = access_token if connection_timeout is not None: self.connection_timeout = connection_timeout if custom_headers is not None: self.custom_headers = custom_headers if max_retries is not None: self.max_retries = max_retries if corporation_id is not None: self.corporation_id = corporation_id if integrator_id is not None: self.integrator_id = integrator_id if platform_id is not None: self.platform_id = platform_id self.__config = Config() def get_headers(self): """ Sets the attribute values of headers """ headers = {"Authorization": "Bearer " + self.__access_token, "x-product-id": self.__config.product_id, "x-tracking-id": self.__config.tracking_id, "x-idempotency-key": str(uuid.uuid4().int), "User-Agent": self.__config.user_agent, "Accept": self.__config.mime_json} if self.__corporation_id is not None: headers["x-corporation-id"] = self.__corporation_id if self.__integrator_id is not None: headers["x-integrator-id"] = self.__integrator_id if self.__platform_id is not None: headers["x-platform-id"] = self.__platform_id if self.__custom_headers is not None: headers.update(self.__custom_headers) return headers @property def access_token(self): """ Sets the attribute value and validates access_token """ return self.__access_token @access_token.setter def access_token(self, value): if not isinstance(value, str): raise ValueError("Param access_token must be a String") self.__access_token = value @property def connection_timeout(self): """ Sets the attribute value and validates connection timeout """ return self.__connection_timeout @connection_timeout.setter def connection_timeout(self, value): if not isinstance(value, float): raise ValueError("Param connection_timeout must be a Float") self.__connection_timeout = value @property def corporation_id(self): """ Sets the attribute value and validates corporation id """ return self.__corporation_id @corporation_id.setter def corporation_id(self, value): if not isinstance(value, str): raise ValueError("Param corporation_id must be a String") self.__corporation_id = value @property def custom_headers(self): """ Sets the attribute value and validates custom headers """ return self.__custom_headers @custom_headers.setter def custom_headers(self, value): if not isinstance(value, dict): raise ValueError("Param custom_headers must be a Dictionary") self.__custom_headers = value @property def integrator_id(self): """ Sets the attribute value and validates integrator id """ return self.__integrator_id @integrator_id.setter def integrator_id(self, value): if not isinstance(value, str): raise ValueError("Param integrator_id must be a String") self.__integrator_id = value @property def max_retries(self): """ Sets the attribute value and validates max retries """ return self.__max_retries @max_retries.setter def max_retries(self, value): if not isinstance(value, int): raise ValueError("Param max_retries must be an Integer") self.__max_retries = value @property def platform_id(self): """ Sets the attribute value and validates platform id """ return self.__platform_id @platform_id.setter def platform_id(self, value): if not isinstance(value, str): raise ValueError("Param platform_id must be a String") self.__platform_id = valueInstance variables
var access_token-
Sets the attribute value and validates access_token
Expand source code
@property def access_token(self): """ Sets the attribute value and validates access_token """ return self.__access_token var connection_timeout-
Sets the attribute value and validates connection timeout
Expand source code
@property def connection_timeout(self): """ Sets the attribute value and validates connection timeout """ return self.__connection_timeout var corporation_id-
Sets the attribute value and validates corporation id
Expand source code
@property def corporation_id(self): """ Sets the attribute value and validates corporation id """ return self.__corporation_id var custom_headers-
Sets the attribute value and validates custom headers
Expand source code
@property def custom_headers(self): """ Sets the attribute value and validates custom headers """ return self.__custom_headers var integrator_id-
Sets the attribute value and validates integrator id
Expand source code
@property def integrator_id(self): """ Sets the attribute value and validates integrator id """ return self.__integrator_id var max_retries-
Sets the attribute value and validates max retries
Expand source code
@property def max_retries(self): """ Sets the attribute value and validates max retries """ return self.__max_retries var platform_id-
Sets the attribute value and validates platform id
Expand source code
@property def platform_id(self): """ Sets the attribute value and validates platform id """ return self.__platform_id
Methods
def get_headers(self)-
Sets the attribute values of headers
Expand source code
def get_headers(self): """ Sets the attribute values of headers """ headers = {"Authorization": "Bearer " + self.__access_token, "x-product-id": self.__config.product_id, "x-tracking-id": self.__config.tracking_id, "x-idempotency-key": str(uuid.uuid4().int), "User-Agent": self.__config.user_agent, "Accept": self.__config.mime_json} if self.__corporation_id is not None: headers["x-corporation-id"] = self.__corporation_id if self.__integrator_id is not None: headers["x-integrator-id"] = self.__integrator_id if self.__platform_id is not None: headers["x-platform-id"] = self.__platform_id if self.__custom_headers is not None: headers.update(self.__custom_headers) return headers