def change_plan(self, entity_id: int, plan_id: int, **kwargs): log.info(f"[PLAN] Change plan for application ({entity_id}) to {plan_id} {kwargs}") params = dict(plan_id=plan_id) url = self._entity_url(entity_id=entity_id) + '/change_plan' response = self.rest.put(url=url, json=params, **kwargs) instance = utils.extract_response(response=response) return instance
def decustomize_plan(self, entity_id: int, **kwargs): log.info( f"[PLAN] Decustomize plan for application ({entity_id}) {kwargs}") url = self._entity_url(entity_id=entity_id) + '/decustomize_plan' response = self.rest.put(url=url, **kwargs) instance = utils.extract_response(response=response) return instance
def create_token(self, entity_id: int, params, **kwargs): log.info( self._log_message("[TOKEN] Create token", entity_id=entity_id, body=params, **kwargs)) url = self._entity_url(entity_id=entity_id) + '/access_tokens' response = self.rest.put(url, json=params) return utils.extract_response(response=response)
def fetch(self, entity_id: int = None, **kwargs) -> dict: """Fetch the entity dictionary Args: entity_id(int): Entity id **kwargs: Optional args Returns(dict): Resource dict from the 3scale """ log.debug(self._log_message("[FETCH] Fetch ", entity_id=entity_id, args=kwargs)) url = self._entity_url(entity_id=entity_id) response = self.rest.get(url=url, **kwargs) return utils.extract_response(response=response, entity=self._entity_name)
def _list_by_resource(self, resource_id: int, resource_type, metric_name: str = 'hits', since=None, period: str = 'year', **kwargs): log.info(f"List analytics by {resource_type} ({resource_id}) f" f"or metric (#{metric_name})") params = dict( metric_name=metric_name, since=since, period=period, **kwargs ) url = self.threescale_client.url + f"/stats/{resource_type}/{resource_id}/usage" response = self.rest.get(url, json=params) return utils.extract_response(response=response)
def send_message(self, entity_id: int, body: str, **kwargs) -> Dict: """Send message to a developer account Args: entity_id(int): Entity id body(str): Message body **kwargs: Optional args Returns(Dict): Response """ log.info(f"[MSG] Send message to account ({entity_id}): {body} {kwargs}") params = dict(body=body) url = self._entity_url(entity_id=entity_id) + '/messages' response = self.rest.post(url=url, json=params, **kwargs) instance = utils.extract_response(response=response) return instance
def _extract_resource(self, response, collection) -> Union[List, Dict]: extract_params = dict(response=response, entity=self._entity_name) if collection: extract_params['collection'] = self._entity_collection extracted = utils.extract_response(**extract_params) return extracted