U
    ä«Fcì  ã                   @   sˆ   d Z ddlZddlZddlmZ zddlmZ W n  ek
rP   ddlmZ Y nX ddl	m
Z
 G dd„ deƒZdd	„ Zed
kr„eƒ  dS )zoA module for sending test SendGrid Inbound Parse messages.
Usage: ./send.py [path to file containing test data]é    N)Úopen)ÚConfig)ÚClientc                   @   s(   e Zd Zdd„ Zdd„ Zedd„ ƒZdS )ÚSendc                 C   s
   || _ dS )z'Create a Send object with target `url`.N©Ú_url)ÚselfÚurl© r
   úA/tmp/pip-unpacked-wheel-7j3043uk/sendgrid/helpers/inbound/send.pyÚ__init__   s    zSend.__init__c                 C   s:   dddœ}t | j|d�}t|ddd�}| ¡ }|j|d�S )	z’Send a test payload.

        Load a payload from payload_filepath, apply headers, and POST self.url.
        Return the response object.
        zSendGrid-Testz#multipart/form-data; boundary=xYzZY)z
User-AgentzContent-Type)ÚhostZrequest_headersÚrzutf-8)Úencoding)Úrequest_body)r   r	   r   ÚreadÚpost)r   Zpayload_filepathÚheadersÚclientÚfÚdatar
   r
   r   Útest_payload   s    þzSend.test_payloadc                 C   s   | j S )zURL to send to.r   )r   r
   r
   r   r	   #   s    zSend.urlN)Ú__name__Ú
__module__Ú__qualname__r   r   Úpropertyr	   r
   r
   r
   r   r      s   r   c                  C   s|   t ƒ } tjdd�}|jdtdd� |jdtd| jdd	� | ¡ }t|jƒ}| t	j
d
 ¡}t|jƒ t|jƒ t|jƒ d S )NzTest data and optional host.)Údescriptionr   zpath to the sample data)ÚtypeÚhelpz-hostz'name of host to send the sample data toF)r   r   ÚdefaultÚrequiredé   )r   ÚargparseÚArgumentParserÚadd_argumentÚstrr   Ú
parse_argsr   r   ÚsysÚargvÚprintÚstatus_coder   Úbody)ÚconfigÚparserÚargsÚsendÚresponser
   r
   r   Úmain)   s(    ÿþ ý


r1   Ú__main__)Ú__doc__r"   r'   Úior   r,   r   ÚImportErrorZsendgrid.helpers.inbound.configZpython_http_clientr   Úobjectr   r1   r   r
   r
   r
   r   Ú<module>   s   