U
    ä«Fc¸  ã                   @   s   d dl Z G dd„ deƒZdS )é    Nc                   @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
ÚBaseInterfacec                 C   sL   ddl m} || _|| _|| _|| _d | j¡| _tj	| j| j
dd�| _dS )a  
        Construct the Twilio SendGrid v3 API object.
        Note that the underlying client is being set up during initialization,
        therefore changing attributes in runtime will not affect HTTP client
        behaviour.

        :param auth: the authorization header
        :type auth: string
        :param impersonate_subuser: the subuser to impersonate. Will be passed
                                    by "On-Behalf-Of" header by underlying
                                    client. See
                                    https://sendgrid.com/docs/User_Guide/Settings/subusers.html
                                    for more details
        :type impersonate_subuser: string
        :param host: base URL for API calls
        :type host: string
        é   )Ú__version__zsendgrid/{};pythoné   )ÚhostÚrequest_headersÚversionN)Ú r   Úauthr   Úimpersonate_subuserr   ÚformatÚ	useragentÚpython_http_clientZClientÚ_default_headersÚclient)Úselfr
   r   r   r   © r   ú;/tmp/pip-unpacked-wheel-7j3043uk/sendgrid/base_interface.pyÚ__init__   s    ýzBaseInterface.__init__c                 C   s$   | j | jddœ}| jr | j|d< |S )z8Set the default header for a Twilio SendGrid v3 API callzapplication/json)ÚAuthorizationz
User-AgentÚAcceptzOn-Behalf-Of)r
   r   r   )r   Úheadersr   r   r   r   #   s    ý
zBaseInterface._default_headersc                 C   s   | j | j_d S )N)r   r   r   )r   r   r   r   Úreset_request_headers0   s    z#BaseInterface.reset_request_headersc                 C   s$   t |tƒs| ¡ }| jjjj|d�S )zþMake a Twilio SendGrid v3 API request with the request body generated by
           the Mail object

        :param message: The Twilio SendGrid v3 API request body generated by the Mail
                        object
        :type message: Mail
        )Úrequest_body)Ú
isinstanceÚdictÚgetr   ÚmailÚsendÚpost)r   Úmessager   r   r   r   3   s    
zBaseInterface.sendN)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r   r   r   r   r      s
   
r   )r   Úobjectr   r   r   r   r   Ú<module>   s   