U
    Ê¼µb  ã                   @   s8   d dl mZ d dlmZ d dlmZ dd„ Zdd„ ZdS )	é    )ÚCountryCode)ÚInvalidCountryCode)ÚServiceResponsec                 C   s8   t | tƒstdƒ‚t|ƒdkr4| | j¡s4| j| }|S )a›  Prefix country code to phone number
    Args:
        country_code: the country code to prefix of type CountryCode
        number (str): the mobile number
    Raises:
        InvalidCountryCode when supplied country code is not type of CountryCode
    Returns:
        number (str): mobile number with country code prefixed. if country_code
        is already prefixed, then the same is returned unaltered.
    z.The country code should be of type CountryCodeé
   )Ú
isinstancer   r   ÚlenÚ
startswithÚvalue)Zcountry_codeÚnumber© r   ú3/tmp/pip-unpacked-wheel-c1x4am86/msg91_otp/utils.pyÚprefix_country_code   s
    

r   c                 K   s\   |   ¡  d¡dkr&|   ¡  d¡}d}n$|   ¡  d¡dkrJ|   ¡  d¡}d}t||f|Ž}|S )a  Convert requests package response obj to our internal Response
    Args:
        response_obj: the response object returned by requests package
        kwargs : any other optional keyword parameters
    Returns:
        our internal ServiceResponse object
    ÚtypeÚerrorÚmessagei�  ÚsuccesséÈ   )ÚjsonÚgetr   )Zresponse_objÚkwargsr   Ústatus_codeÚ	_responser   r   r   Úconvert_response   s    r   N)Zmsg91_otp.country_coder   Zmsg91_otp.exceptionsr   Zmsg91_otp.responser   r   r   r   r   r   r   Ú<module>   s   