def _test_single_endpoint(self): """ Tests a single Facebook Ads endpoint, params are set as class attrs in order to play nice with caliendo :param FacebookModel model: The model returned by this endpoint :param str connection: The name of the connection, if we are testing one. """ model_name = None this_model_ids = [] pyfb = PyFacebook(app_id=self.app_id, app_secret=self.app_secret, token_text=self.test_token_text) test_method = getattr(pyfb, self.HTTP_METHOD.lower()) results = test_method(model=self.MODEL, id=self.ID, connection=self.CONNECTION, return_json=self.RETURN_JSON, **self.KWARGS) if self.RETURN_JSON and not isinstance(results['data'][0], dict): results['data'] = json_to_objects(results['data'], self.MODEL) first_obj = first_item(results['data']) if first_obj and hasattr(first_obj, 'id'): first_obj.validate() model_name = type(first_obj).__name__ this_model_ids = [first_obj.id] results = first_obj if hasattr(results, 'to_json'): results = results.to_json(return_dict=True) return results, (model_name, this_model_ids)
def __call_endpoint(self, model, id, connection, http_method, params, return_json): """ Creates a properly-formatted Facebook Graph API endpoint from id and connection parameters. Performs an endpoint call and returns the result. :param tinymodel.TinyModel model: The class associated with the objects we're getting. :param str id: The id of the parent object :param str connection: The name of connection to call :param str http_method: The type of call to make :param dict params: The params to send in the call :param bool return_json: If True, the call returns a dict instead of TinyModel objects """ endpoint = str(id or model.endpoint or model.__name__.lower()) if connection: endpoint += ('/' + connection) fb_response = self.call_graph_api(endpoint=endpoint, http_method=http_method, params=params) if not return_json: fb_response['data'] = json_to_objects(fb_response['data'], model) return fb_response