o
    Zh                     @   sl   d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ dddd	d
dZG dd deZdS )    N)ListOptional)Document)get_from_envstringify_dict)
BaseLoaderz https://api.iugu.com/v1/invoicesz!https://api.iugu.com/v1/customerszhttps://api.iugu.com/v1/chargesz%https://api.iugu.com/v1/subscriptionszhttps://api.iugu.com/v1/plans)ZinvoicesZ	customersZchargesZsubscriptionsZplansc                   @   sf   e Zd ZdZddedee ddfddZdedee fd	d
Z	dee fddZ
dee fddZdS )
IuguLoaderzLoad from `IUGU`.Nresource	api_tokenreturnc                 C   s(   || _ |p	tdd}dd| i| _dS )zInitialize the IUGU resource.

        Args:
            resource: The name of the resource to fetch.
            api_token: The IUGU API token to use.
        r
   ZIUGU_API_TOKENAuthorizationzBearer N)r	   r   headers)selfr	   r
    r   `/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/iugu.py__init__   s   zIuguLoader.__init__urlc                 C   sr   t jj|| jd}t j| }t|  }t	|}d|i}t
||dgW  d    S 1 s2w   Y  d S )N)r   source)Zpage_contentmetadata)urllibrequestRequestr   urlopenjsonloadsreaddecoder   r   )r   r   r   responseZ	json_datatextr   r   r   r   _make_request!   s   $zIuguLoader._make_requestc                 C   s"   t | j}|d u rg S | |S N)IUGU_ENDPOINTSgetr	   r   )r   Zendpointr   r   r   _get_resource*   s   
zIuguLoader._get_resourcec                 C   s   |   S r    )r#   )r   r   r   r   load0   s   zIuguLoader.loadr    )__name__
__module____qualname____doc__strr   r   r   r   r   r#   r$   r   r   r   r   r      s    	r   )r   urllib.requestr   typingr   r   Zlangchain_core.documentsr   Zlangchain_core.utilsr   r   Z)langchain_community.document_loaders.baser   r!   r   r   r   r   r   <module>   s    	