You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/31 20:29:28 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #8008: Custom Facebook Ads Operator

mik-laj commented on a change in pull request #8008: Custom Facebook Ads Operator
URL: https://github.com/apache/airflow/pull/8008#discussion_r401195142
 
 

 ##########
 File path: airflow/providers/facebook/ads/hooks/ads.py
 ##########
 @@ -0,0 +1,150 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+This module contains Facebook Ads Reporting hooks
+"""
+import time
+from typing import Any, Dict, List, Optional
+
+from facebook_business.adobjects.adaccount import AdAccount
+from facebook_business.adobjects.adreportrun import AdReportRun
+from facebook_business.adobjects.adsinsights import AdsInsights
+from facebook_business.api import Cursor, FacebookAdsApi
+from facebook_business.exceptions import FacebookRequestError
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+JOB_COMPLETED = 'Job Completed'
+
+
+class FacebookAdsReportingHook(BaseHook):
+    """
+    Hook for the Facebook Ads API
+
+    .. seealso::
+        For more information on the Facebook Ads API, take a look at the API docs:
+        https://developers.facebook.com/docs/marketing-apis/
+
+    :param facebook_ads_conn_id: Airflow Facebook Ads connection ID
+    :type facebook_ads_conn_id: str
+    :param api_version: The version of Facebook API. Default to v6.0
+    :type api_version: str
+
+    :return: list of Facebook Ads AdsInsights object(s)
+    :rtype: list[AdsInsights]
+    """
+
+    def __init__(
+        self,
+        facebook_ads_conn_id: str = "facebook_ads_default",
+        api_version: str = "v6.0",
+    ) -> None:
+        super().__init__()
+        self.facebook_ads_conn_id = facebook_ads_conn_id
+        self.facebook_ads_config: Dict[str, Any] = {}
+        self.api_version = api_version
+        self.ad_account_id: str = ""
+        self.app_id: str = ""
+        self.app_secret: str = ""
+        self.access_token: str = ""
+        self.default_params = {
+            'level': 'ad',
+            'date_preset': 'yesterday',
+        }
+
+    def _get_service(self) -> FacebookAdsApi:
+        """ Returns Facebook Ads Client using a service account"""
+        self._get_config()
+        for key, val in self.facebook_ads_config.items():
 
 Review comment:
   It doesn't seem safe. Can you explicitly set attributes here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services