o
    Zh                     @   s   d dl Z d dlZd dlm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ddddddddZG dd deZdS )    N)	b64encode)ListOptional)Document)get_from_envstringify_value)
BaseLoaderz1https://app.moderntreasury.com/api/payment_ordersz4https://app.moderntreasury.com/api/expected_paymentsz*https://app.moderntreasury.com/api/returnsz;https://app.moderntreasury.com/api/incoming_payment_detailsz1https://app.moderntreasury.com/api/counterpartiesz4https://app.moderntreasury.com/api/internal_accountsz4https://app.moderntreasury.com/api/external_accountsz/https://app.moderntreasury.com/api/transactionsz*https://app.moderntreasury.com/api/ledgersz2https://app.moderntreasury.com/api/ledger_accountsz6https://app.moderntreasury.com/api/ledger_transactionsz)https://app.moderntreasury.com/api/eventsz+https://app.moderntreasury.com/api/invoices)Zpayment_ordersZexpected_paymentsreturnsZincoming_payment_detailsZcounterpartiesZinternal_accountsZexternal_accountsZtransactionsZledgersZledger_accountsZledger_transactionseventsZinvoicesc                	   @   sr   e Zd ZdZ		ddede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 )ModernTreasuryLoaderzLoad from `Modern Treasury`.Nresourceorganization_idapi_keyreturnc                 C   sX   || _ |p	tdd}|ptdd}| d| d}t|d}dd| i| _d	S )
a  

        Args:
            resource: The Modern Treasury resource to load.
            organization_id: The Modern Treasury organization ID. It can also be
               specified via the environment variable
               "MODERN_TREASURY_ORGANIZATION_ID".
            api_key: The Modern Treasury API key. It can also be specified via
               the environment variable "MODERN_TREASURY_API_KEY".
        r   ZMODERN_TREASURY_ORGANIZATION_IDr   ZMODERN_TREASURY_API_KEY:zutf-8AuthorizationzBasic N)r   r   encoder   decodeheaders)selfr   r   r   credentialsZbasic_auth_token r   k/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/modern_treasury.py__init__    s   zModernTreasuryLoader.__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readr   r   r   )r   r   r   responseZ	json_datatextr   r   r   r   _make_request9   s   $z"ModernTreasuryLoader._make_requestc                 C   s"   t | j}|d u rg S | |S N)MODERN_TREASURY_ENDPOINTSgetr   r&   )r   Zendpointr   r   r   _get_resourceB   s   
z"ModernTreasuryLoader._get_resourcec                 C   s   |   S r'   )r*   )r   r   r   r   loadH   s   zModernTreasuryLoader.load)NN)__name__
__module____qualname____doc__strr   r   r   r   r&   r*   r+   r   r   r   r   r      s     
	r   )r!   urllib.requestr   base64r   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,    