コード例 #1
0
    def __init__(self, http_response, obj=None):
        """

        :param http_response: requests.Response
            The raw response from the server
        :param obj: object
            An object encapsulating the data (json) in the response

        :raises DNSimpleException
            When the server responds with an error code
        """
        if int(http_response.status_code) in range(400, 504):
            message = http_response.json().get('message')
            errors = None
            if http_response.json().get('errors'):
                errors = http_response.json().get('errors')
            raise DNSimpleException(message=message, errors=errors)

        self.__class__.http_response = http_response
        self.__class__.headers = self.__class__.http_response.headers
        self.__class__.rate_limit = int(
            self.__class__.headers['X-RateLimit-Limit'])
        self.__class__.rate_limit_remaining = int(
            self.__class__.headers['X-RateLimit-Remaining'])
        self.__class__.rate_limit_reset = int(
            self.__class__.headers['X-RateLimit-Reset'])

        self.add_data(obj, http_response)

        if http_response.status_code != '204':
            self.__class__.pagination = None if http_response.json().get(
                'pagination') is None else Pagination(
                    http_response.json().get('pagination'))
コード例 #2
0
ファイル: dnsimple.py プロジェクト: mator/community.general
 def dnsimple_client(self):
     """creates a dnsimple client object"""
     if self.account_email and self.account_api_token:
         client = Client(sandbox=self.sandbox, email=self.account_email, access_token=self.account_api_token)
     else:
         msg = "Option account_email or account_api_token not provided. " \
               "Dnsimple authentiction with a .dnsimple config file is not " \
               "supported with dnsimple-python>=2.0.0"
         raise DNSimpleException(msg)
     client.identity.whoami()
     self.client = client
コード例 #3
0
 def dnsimple_account(self):
     """select a dnsimple account. If a user token is used for authentication,
     this user must only have access to a single account"""
     account = self.client.identity.whoami().data.account
     # user supplied a user token instead of account api token
     if not account:
         accounts = Accounts(self.client).list_accounts().data
         if len(accounts) != 1:
             msg = "The provided dnsimple token is a user token with multiple accounts." \
                 "Use an account token or a user token with access to a single account." \
                 "See https://support.dnsimple.com/articles/api-access-token/"
             raise DNSimpleException(msg)
         account = accounts[0]
     self.account = account