def call_update_api(self, url, data):
     url = self.base_url + url
     header = {
         "Authorization": self.access_token
     }
     response = requests.put(url, headers=header, json=data)
     result = ApiResponse(response)
     return result
예제 #2
0
 def call_post_api(self, url, params):
     url = self.base_url + url
     header = {"Authorization": self.access_token}
     self.response = requests.post(url,
                                   headers=header,
                                   data=list(params.keys())[-1])
     result = ApiResponse(self.response)
     return result
 def call_get_api(self, url, params):
     url = self.base_url + url
     header = {
         "Authorization": self.access_token
     }
     payload = {name: params[name] for name in params if params[name] is not None}
     response = requests.get(url, headers=header, params=payload)
     result = ApiResponse(response)
     return result
예제 #4
0
    def current_user_details(self):
        """
        Makes a POST request to the current_user API
        Returns current user details using Access token

        Returns
        -------
        Current user details response
        """
        url = self.base_url + '/v2/core/current_user'
        header = {"Authorization": self.access_token}
        response = requests.post(url, headers=header)
        result = ApiResponse(response)
        return result
예제 #5
0
    def get_all_account_id_and_name(self):
        """
        Makes a GET request to the Account ID and Name API
        Gets all the accounts from the organization

        Returns
        -------
        All account id with name
        """
        url = self.base_url + '/v2/core/accounts'
        header = {"Authorization": self.access_token}
        logger.info("Initialising API Call")
        response = requests.get(url, headers=header)
        data = json.loads(response.text)
        account_id = []
        if data.get('data') is not None:
            for account in data.get('data'):
                result = dict(itertools.islice(account.items(), 5))
                account_id.append(result)
            result = ApiResponse(response)
            return result
        else:
            result = ApiResponse(response)
            return result
예제 #6
0
    def activate_tier(self, **kwargs):
        """
        Makes a PUT request to the activate_tier API
        To activate given tier and its associates

        Other Parameters
        ----------
        tier_id : integer, mandatory
            ID of the tier

        Returns
        -------
        Tier activate response
        """
        if 'tier_id' in kwargs:
            tier_id = kwargs['tier_id']
            url = f'/v2/core/tiers/{tier_id}/activate'
            logger.info("Initialising API Call")
            url = self.base_url + url
            header = {"Authorization": self.access_token}
            response = requests.put(url, headers=header)
            result = ApiResponse(response)
            return result
        return error_response
예제 #7
0
    def delete_tier(self, **kwargs):
        """
        Makes a DELETE request to the delete_tier API
        To destroy a tier based on the given ID

        Other Parameters
        ----------
        tier_id : integer, mandatory
            ID of the tier

        Returns
        -------
        Tier delete response
        """
        if 'tier_id' in kwargs:
            tier_id = kwargs['tier_id']
            url = f'/v2/core/tiers/{tier_id}'
            logger.info("Initialising API Call")
            url = self.base_url + url
            header = {"Authorization": self.access_token}
            response = requests.delete(url, headers=header)
            result = ApiResponse(response)
            return result
        return error_response
예제 #8
0
 def call_get_api(self, url):
     url = self.base_url + url
     header = {"Authorization": self.access_token}
     self.response = requests.get(url, headers=header)
     result = ApiResponse(self.response)
     return result