U
    k7g                     @   s   d dl Z d dlZd dlmZmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ edZG d	d
 d
eZdS )    N)DictOptionalTuple)RequestSessionhooks)HTTPAdapter)
HttpClient)r   )Responseztwilio.http_clientc                       s   e Zd ZdZdddeddfeeeee	f  ee
 ejeeeef  ee d fddZdeeeeee	f  eeee	f  eeeef  eeeef  ee
 eed	d	d
Z  ZS )TwilioHttpClientzI
    General purpose HTTP Client for interacting with the Twilio API
    TN)pool_connectionsrequest_hookstimeoutloggerproxymax_retriesc                    s   t  |d| |rt nd| _| jrB|dk	rB| jdt|d | jdk	rn| jdttdt d d |pxt	
 | _|r|ni | _dS )a  
        Constructor for the TwilioHttpClient
        :param pool_connections
        :param request_hooks
        :param timeout: Timeout for the requests.
                    Timeout should never be zero (0) or less
        :param logger
        :param proxy: Http proxy for the requests session
        :param max_retries: Maximum number of retries each request should attempt
        FNzhttps://)r          )pool_maxsize)super__init__r   sessionmountr   minos	cpu_countr   default_hooksr   r   )selfr   r   r   r   r   r   	__class__ ;/tmp/pip-unpacked-wheel-qtbjxrb6/twilio/http/http_client.pyr      s    
 zTwilioHttpClient.__init__F)	methodurlparamsdataheadersauthr   allow_redirectsreturnc	                 C   s   |dkr| j }n|dkr t|| ||||| jd}	|rT|ddkrT||	d< n||	d< | |	 d| _| jpvt }
t	f |	}t
f |	| _|
|}|
|j| jddd}|
j|f||d|}| |j| tt|j|j|j| _| jS )	aj  
        Make an HTTP Request with parameters provided.

        :param method: The HTTP method to use
        :param url: The URL to request
        :param params: Query parameters to append to the URL
        :param data: Parameters to go in the body of the HTTP request
        :param headers: HTTP Headers to send with the request
        :param auth: Basic Auth arguments
        :param timeout: Socket/Read timeout for the request
        :param allow_redirects: Whether to allow redirects
        See the requests documentation for explanation of all these parameters

        :return: An HTTP response
        Nr   )r"   r#   r$   r&   r'   r   zContent-Typezapplication/jsonjsonr%   )r(   r   )r   
ValueErrorupperr   getZlog_requestZ_test_only_last_responser   r   r   TwilioRequestZ_test_only_last_requestprepare_requestmerge_environment_settingsr#   r   sendZlog_responsestatus_coder
   inttextr&   )r   r"   r#   r$   r%   r&   r'   r   r(   kwargsr   requestZprepped_requestsettingsresponser    r    r!   r6   2   sT    



      zTwilioHttpClient.request)NNNNNF)__name__
__module____qualname____doc___loggerboolr   r   strobjectfloatloggingLoggerr3   r   r   r
   r6   __classcell__r    r    r   r!   r      s@   "      r   )r   rB   typingr   r   r   requestsr   r   r   Zrequests.adaptersr   Ztwilio.httpr	   Ztwilio.http.requestr.   Ztwilio.http.responser
   	getLoggerr=   r   r    r    r    r!   <module>   s   
