U
    W+dR                     @   sP   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 G dd deZ
dS )	    )json)JSONResponseError)AWSAuthConnection)
RegionInfo)
exceptionsc                	       s   e Zd ZdZdZdZdZeZe	j
e	je	je	je	je	je	je	jdZ fddZdd	 Zd
d Zdd Zdd Zdd Zdd Zd(ddZd)ddZd*ddZdd Zd+ddZdd  Zd!d" Z d,d#d$Z!d-d&d'Z"  Z#S ).CognitoSyncConnectiona  
    Amazon Cognito Sync
    Amazon Cognito Sync provides an AWS service and client library
    that enable cross-device syncing of application-related user data.
    High-level client libraries are available for both iOS and
    Android. You can use these libraries to persist data locally so
    that it's available even if the device is offline. Developer
    credentials don't need to be stored on the mobile device to access
    the service. You can use Amazon Cognito to obtain a normalized
    user ID and credentials. User data is persisted in a dataset that
    can store up to 1 MB of key-value pairs, and you can have up to 20
    datasets per user identity.

    With Amazon Cognito Sync, the data stored for each identity is
    accessible only to credentials assigned to that identity. In order
    to use the Cognito Sync service, you need to make API calls using
    credentials retrieved with `Amazon Cognito Identity service`_.
    z
2014-06-30z	us-east-1z$cognito-sync.us-east-1.amazonaws.com)LimitExceededExceptionResourceConflictExceptionInvalidConfigurationExceptionTooManyRequestsExceptionInvalidParameterExceptionResourceNotFoundExceptionInternalErrorExceptionNotAuthorizedExceptionc                    sL   | d}|s t| | j| j}n|d= |j|d< tt| jf | || _d S )Nregionhost)	getr   DefaultRegionNameDefaultRegionEndpointZendpointsuperr   __init__r   )selfkwargsr   	__class__ </tmp/pip-unpacked-wheel-dlxw5sjy/boto/cognito/sync/layer1.pyr   A   s    

zCognitoSyncConnection.__init__c                 C   s   dgS )Nzhmac-v4r   )r   r   r   r   _required_auth_capabilityL   s    z/CognitoSyncConnection._required_auth_capabilityc                 C   s   d |||}| jd|ddS )a  
        Deletes the specific dataset. The dataset will be deleted
        permanently, and the action can't be undone. Datasets that
        this dataset was merged with will no longer report the merge.
        Any consequent operation on this dataset will result in a
        ResourceNotFoundException.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type dataset_name: string
        :param dataset_name: A string of up to 128 characters. Allowed
            characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.'
            (dot).

        ./identitypools/{0}/identities/{1}/datasets/{2}DELETE   expected_statusformatmake_requestr   identity_pool_ididentity_iddataset_nameurir   r   r   delete_datasetO   s      z$CognitoSyncConnection.delete_datasetc                 C   s   d |||}| jd|ddS )a6  
        Gets metadata about a dataset by identity and dataset name.
        The credentials used to make this API call need to have access
        to the identity data. With Amazon Cognito Sync, each identity
        has access only to its own data. You should use Amazon Cognito
        Identity service to retrieve the credentials necessary to make
        this API call.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type dataset_name: string
        :param dataset_name: A string of up to 128 characters. Allowed
            characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.'
            (dot).

        r   GETr    r!   r#   r&   r   r   r   describe_datasetl   s      z&CognitoSyncConnection.describe_datasetc                 C   s   d |}| jd|ddS )ad  
        Gets usage details (for example, data storage) about a
        particular identity pool.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        z/identitypools/{0}r,   r    r!   r#   r   r'   r*   r   r   r   describe_identity_pool_usage   s    
z2CognitoSyncConnection.describe_identity_pool_usagec                 C   s   d ||}| jd|ddS )aW  
        Gets usage information for an identity, including number of
        datasets and data usage.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        z!/identitypools/{0}/identities/{1}r,   r    r!   r#   )r   r'   r(   r*   r   r   r   describe_identity_usage   s
     z-CognitoSyncConnection.describe_identity_usagec                 C   s   d |}| jd|ddS )aa  
        Gets the configuration settings of an identity pool.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. This is the ID of the pool for which to return a
            configuration.

         /identitypools/{0}/configurationr,   r    r!   r#   r.   r   r   r   get_identity_pool_configuration   s    
z5CognitoSyncConnection.get_identity_pool_configurationNc           	      C   sT   d ||}i }i }i }|dk	r(||d< |dk	r8||d< | jd|dt|||dS )a6  
        Lists datasets for an identity. The credentials used to make
        this API call need to have access to the identity data. With
        Amazon Cognito Sync, each identity has access only to its own
        data. You should use Amazon Cognito Identity service to
        retrieve the credentials necessary to make this API call.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type next_token: string
        :param next_token: A pagination token for obtaining the next page of
            results.

        :type max_results: integer
        :param max_results: The maximum number of results to be returned.

        z*/identitypools/{0}/identities/{1}/datasetsN	nextToken
maxResultsr,   r    r"   dataheadersparamsr$   r%   r   dumps)	r   r'   r(   
next_tokenmax_resultsr*   r8   r7   query_paramsr   r   r   list_datasets   s      
 z#CognitoSyncConnection.list_datasetsc                 C   sL   d}i }i }i }|dk	r ||d< |dk	r0||d< | j d|dt|||dS )a;  
        Gets a list of identity pools registered with Cognito.

        :type next_token: string
        :param next_token: A pagination token for obtaining the next page of
            results.

        :type max_results: integer
        :param max_results: The maximum number of results to be returned.

        z/identitypoolsNr3   r4   r,   r    r5   )r%   r   r:   )r   r;   r<   r*   r8   r7   r=   r   r   r   list_identity_pool_usage   s    
 z.CognitoSyncConnection.list_identity_pool_usagec                 C   sv   d |||}i }	i }
i }|dk	r*||d< |dk	r:||d< |dk	rJ||d< |dk	rZ||d< | jd|dt|	|
|d	S )
aY  
        Gets paginated records, optionally changed after a particular
        sync count for a dataset and identity. The credentials used to
        make this API call need to have access to the identity data.
        With Amazon Cognito Sync, each identity has access only to its
        own data. You should use Amazon Cognito Identity service to
        retrieve the credentials necessary to make this API call.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type dataset_name: string
        :param dataset_name: A string of up to 128 characters. Allowed
            characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.'
            (dot).

        :type last_sync_count: long
        :param last_sync_count: The last server sync count for this record.

        :type next_token: string
        :param next_token: A pagination token for obtaining the next page of
            results.

        :type max_results: integer
        :param max_results: The maximum number of results to be returned.

        :type sync_session_token: string
        :param sync_session_token: A token containing a session ID, identity
            ID, and expiration.

        z6/identitypools/{0}/identities/{1}/datasets/{2}/recordsNZlastSyncCountr3   r4   ZsyncSessionTokenr,   r    r5   r9   )r   r'   r(   r)   Zlast_sync_countr;   r<   sync_session_tokenr*   r8   r7   r=   r   r   r   list_records   s*    *  
 z"CognitoSyncConnection.list_recordsc           	      C   s:   d ||}||d}i }i }| jd|dt|||dS )aq  
        Registers a device to receive push sync notifications.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. Here, the ID of the pool that the identity belongs to.

        :type identity_id: string
        :param identity_id: The unique ID for this identity.

        :type platform: string
        :param platform: The SNS platform type (e.g. GCM, SDM, APNS,
            APNS_SANDBOX).

        :type token: string
        :param token: The push token.

        z&/identitypools/{0}/identity/{1}/device)PlatformTokenPOSTr    r5   r9   )	r   r'   r(   platformtokenr*   r8   r7   r=   r   r   r   register_device:  s     

 z%CognitoSyncConnection.register_devicec                 C   sB   d |}i }i }i }|dk	r&||d< | jd|dt|||dS )a  
        Sets the necessary configuration for push sync.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. This is the ID of the pool to modify.

        :type push_sync: dict
        :param push_sync: Configuration options to be applied to the identity
            pool.

        r1   NZPushSyncrD   r    r5   r9   )r   r'   Z	push_syncr*   r8   r7   r=   r   r   r   set_identity_pool_configurationX  s    

 z5CognitoSyncConnection.set_identity_pool_configurationc                 C   s    d ||||}| jd|ddS )a  
        Subscribes to receive notifications when a dataset is modified
        by another device.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. The ID of the pool to which the identity belongs.

        :type identity_id: string
        :param identity_id: Unique ID for this identity.

        :type dataset_name: string
        :param dataset_name: The name of the dataset to subcribe to.

        :type device_id: string
        :param device_id: The unique ID generated for this device by Cognito.

        @/identitypools/{0}/identities/{1}/datasets/{2}/subscriptions/{3}rD   r    r!   r#   r   r'   r(   r)   	device_idr*   r   r   r   subscribe_to_datasetr  s       z*CognitoSyncConnection.subscribe_to_datasetc                 C   s    d ||||}| jd|ddS )a  
        Unsubscribe from receiving notifications when a dataset is
        modified by another device.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. The ID of the pool to which this identity belongs.

        :type identity_id: string
        :param identity_id: Unique ID for this identity.

        :type dataset_name: string
        :param dataset_name: The name of the dataset from which to unsubcribe.

        :type device_id: string
        :param device_id: The unique ID generated for this device by Cognito.

        rI   r   r    r!   r#   rJ   r   r   r   unsubscribe_from_dataset  s       z.CognitoSyncConnection.unsubscribe_from_datasetc                 C   sz   d |||}d|i}	i }
i }|dk	r.||	d< |dk	r>||	d< |dk	rN||
d< |dk	r^||
d< | jd|dt|	|
|d	S )
a  
        Posts updates to records and add and delete records for a
        dataset and user. The credentials used to make this API call
        need to have access to the identity data. With Amazon Cognito
        Sync, each identity has access only to its own data. You
        should use Amazon Cognito Identity service to retrieve the
        credentials necessary to make this API call.

        :type identity_pool_id: string
        :param identity_pool_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type identity_id: string
        :param identity_id: A name-spaced GUID (for example, us-
            east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon
            Cognito. GUID generation is unique within a region.

        :type dataset_name: string
        :param dataset_name: A string of up to 128 characters. Allowed
            characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.'
            (dot).

        :type device_id: string
        :param device_id: The unique ID generated for this device by Cognito.

        :type record_patches: list
        :param record_patches: A list of patch operations.

        :type sync_session_token: string
        :param sync_session_token: The SyncSessionToken returned by a previous
            call to ListRecords for this dataset and identity.

        :type client_context: string
        :param client_context: Intended to supply a device ID that will
            populate the `lastModifiedBy` field referenced in other methods.
            The `ClientContext` field is not yet implemented.

        r   ZSyncSessionTokenNZDeviceIdZRecordPatcheszx-amz-Client-ContextrD   r    r5   r9   )r   r'   r(   r)   r@   rK   Zrecord_patchesZclient_contextr*   r8   r7   r=   r   r   r   update_records  s*    +  
 z$CognitoSyncConnection.update_records c                 C   s|   |d kri }t j| |||||d}t| d}|j|krD|S |ddd }	| j	
|	| j}
|
|j|j|d S )N)r7   r6   r8   zutf-8zx-amzn-ErrorType:r   )r   r%   r   loadsreaddecodestatus	getheadersplit_faultsr   ResponseErrorreason)r   Zverbresourcer7   r6   r"   r8   responsebodyZ
error_typeZerror_classr   r   r   r%     s          
z"CognitoSyncConnection.make_request)NN)NN)NNNN)N)NNN)NrO   NN)$__name__
__module____qualname____doc__Z
APIVersionr   r   r   rX   r   r   r	   r
   r   r   r   r   r   rW   r   r   r+   r-   r/   r0   r2   r>   r?   rA   rG   rH   rL   rM   rN   r%   __classcell__r   r   r   r   r      sV     
)
      
; 
    
<    r   N)Zboto.compatr   Zboto.exceptionr   Zboto.connectionr   Zboto.regioninfor   Zboto.cognito.syncr   r   r   r   r   r   <module>   s
   