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 2019/09/23 13:25:38 UTC

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #6169: [AIRFLOW-4970][Don't merge] Add Google Campaign Manager integration

nuclearpinguin commented on a change in pull request #6169: [AIRFLOW-4970][Don't merge] Add Google Campaign Manager integration
URL: https://github.com/apache/airflow/pull/6169#discussion_r327112039
 
 

 ##########
 File path: airflow/gcp/hooks/campaign_manager.py
 ##########
 @@ -0,0 +1,244 @@
+# -*- coding: utf-8 -*-
+#
+# 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 Google Campaign Manager hook.
+"""
+from typing import Any, Dict, Optional
+
+from googleapiclient.discovery import build, Resource
+from googleapiclient import http
+
+from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
+
+
+class GoogleCampaignManagerHook(GoogleCloudBaseHook):
+    """
+    Hook for Google Campaign Manager.
+    """
+
+    _conn = None  # type: Optional[Resource]
+
+    def __init__(
+        self,
+        api_version: str = "v3.2",
+        gcp_conn_id: str = "google_cloud_default",
+        delegate_to: Optional[str] = None,
+    ) -> None:
+        super().__init__(gcp_conn_id, delegate_to)
+        self.api_version = api_version
+
+    def get_conn(self) -> Resource:
+        """
+        Retrieves connection to Campaign Manager.
+        """
+        if not self._conn:
+            http_authorized = self._authorize()
+            self._conn = build(
+                "dfareporting",
+                self.api_version,
+                http=http_authorized,
+                cache_discovery=False,
+            )
+        return self._conn
+
+    def delete(self, profile_id: str, report_id: str) -> Any:
+        """
+        Deletes a report by its ID.
+
+        :param profile_id: The DFA user profile ID.
+        :type profile_id: str
+        :param report_id: The ID of the report.
+        :type report_id: str
+        """
+        response = (
+            self.get_conn()  # pylint: disable=no-member
+            .reports()
+            .delete(profileId=profile_id, reportId=report_id)
+            .execute(num_retries=self.num_retries)
+        )
+        return response
+
+    def insert(self, profile_id: str, report: Dict[str, Any]) -> Any:
+        """
+        Creates a report.
+
+        :param profile_id: The DFA user profile ID.
+        :type profile_id: str
+        :param report: The report resource to be inserted.
+        :type report: Dict[str, Any]
+        """
+        response = (
+            self.get_conn()  # pylint: disable=no-member
+            .reports()
+            .insert(profileId=profile_id, body=report)
+            .execute(num_retries=self.num_retries)
+        )
+        return response
+
+    def list(
+        self,
+        profile_id: str,
+        max_results: Optional[int] = None,
+        scope: Optional[str] = None,
+        sort_field: Optional[str] = None,
+        sort_order: Optional[str] = None,
+    ) -> list:
+        """
+        Retrieves list of reports.
+
+        :param profile_id: The DFA user profile ID.
+        :type profile_id: str
+        :param max_results: Maximum number of results to return.
+        :type max_results: Optional[int]
+        :param scope: The scope that defines which results are returned.
+        :type scope: Optional[str]
+        :param sort_field: The field by which to sort the list.
+        :type sort_field: Optional[str]
+        :param sort_order: Order of sorted results.
+        :type sort_order: Optional[str]
+        """
+        response = (
+            self.get_conn()  # pylint: disable=no-member
+            .reports()
+            .list(
+                profileId=profile_id,
+                maxResults=max_results,
+                scope=scope,
+                sortField=sort_field,
+                sortOrder=sort_order,
+            )
+            .execute(num_retries=self.num_retries)
+        )
+        reports = [r for r in response.get('items', [])]
+        next_token = response.get('nextPageToken')
 
 Review comment:
   No information in API. 

----------------------------------------------------------------
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