ó
º9—^c           @   sD   d  Z  d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d S(   sí  
This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via
Python.

For more information on this library, see the README on GitHub.
    http://github.com/sendgrid/sendgrid-python
For more information on the Twilio SendGrid v3 API, see the v3 docs:
    http://sendgrid.com/docs/API_Reference/api_v3.html
For the user guide, code examples, and more, visit the main docs page:
    http://sendgrid.com/docs/index.html

This file provides the Twilio SendGrid API Client.
iÿÿÿÿNt   SendGridAPIClientc           B   sA   e  Z d  Z d d d d „ Z e d „  ƒ Z d „  Z d „  Z RS(   s¦  The Twilio SendGrid API Client.

    Use this object to interact with the v3 API.  For example:
        sg = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
        ...
        mail = Mail(from_email, subject, to_email, content)
        response = sg.client.mail.send.post(request_body=mail.get())

    For examples and detailed use instructions, see
        https://github.com/sendgrid/sendgrid-python
    s   https://api.sendgrid.comc         C   s†   d d l  m } | p% t j j d ƒ |  _ | |  _ | |  _ | |  _ d j	 |  j ƒ |  _
 t j d |  j d |  j d d ƒ |  _ d	 S(
   s{  
        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 api_key: Twilio SendGrid API key to use. If not provided, key will be
                        read from environment variable "SENDGRID_API_KEY"
        :type api_key: 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
        i   (   t   __version__t   SENDGRID_API_KEYs   sendgrid/{};pythont   hostt   request_headerst   versioni   N(   t    R   t   ost   environt   gett   api_keyt   impersonate_subuserR   R   t   formatt	   useragentt   python_http_clientt   Clientt   _default_headerst   client(   t   selfR
   R   R   R   (    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyt   __init__#   s    						c         C   sG   i d j  |  j ƒ d 6|  j d 6d d 6} |  j rC |  j | d <n  | S(   s8   Set the default header for a Twilio SendGrid v3 API calls	   Bearer {}t   Authorizations
   User-agents   application/jsont   Accepts   On-Behalf-Of(   R   R
   R   R   (   R   t   headers(    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyR   F   s    

	c         C   s   |  j  |  j _ d  S(   N(   R   R   R   (   R   (    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyt   reset_request_headersS   s    c         C   sR   t  | t ƒ r- |  j j j j d | ƒ } n! |  j j j j d | j ƒ  ƒ } | S(   sþ   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
        t   request_body(   t
   isinstancet   dictR   t   mailt   sendt   postR	   (   R   t   messaget   response(    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyR   W   s    !N(	   t   __name__t
   __module__t   __doc__t   NoneR   t   propertyR   R   R   (    (    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyR       s   	(   R"   R   t   warningsR   t   objectR    (    (    (    s3   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/sendgrid.pyt   <module>   s   