Exemple #1
0
    def execute(self, context: 'Context') -> None:
        gcs_hook = GCSHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        ga_hook = GoogleAnalyticsHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            api_version=self.api_version,
            impersonation_chain=self.impersonation_chain,
        )

        with NamedTemporaryFile("w+") as tmp_file:
            self.log.info(
                "Downloading file from GCS: %s/%s ",
                self.storage_bucket,
                self.storage_name_object,
            )
            gcs_hook.download(
                bucket_name=self.storage_bucket,
                object_name=self.storage_name_object,
                filename=tmp_file.name,
            )

            ga_hook.upload_data(
                tmp_file.name,
                self.account_id,
                self.web_property_id,
                self.custom_data_source_id,
                self.resumable_upload,
            )
Exemple #2
0
 def test_init(self, mock_base_init):
     hook = GoogleAnalyticsHook(
         API_VERSION, GCP_CONN_ID, delegate_to=DELEGATE_TO, impersonation_chain=IMPERSONATION_CHAIN,
     )
     mock_base_init.assert_called_once_with(
         GCP_CONN_ID, delegate_to=DELEGATE_TO, impersonation_chain=IMPERSONATION_CHAIN,
     )
     self.assertEqual(hook.api_version, API_VERSION)
Exemple #3
0
 def execute(self, context: 'Context') -> List[Dict[str, Any]]:
     hook = GoogleAnalyticsHook(
         api_version=self.api_version,
         gcp_conn_id=self.gcp_conn_id,
         impersonation_chain=self.impersonation_chain,
     )
     result = hook.list_accounts()
     return result
Exemple #4
0
 def execute(self, context):
     hook = GoogleAnalyticsHook(
         api_version=self.api_version,
         gcp_conn_id=self.gcp_conn_id,
         impersonation_chain=self.impersonation_chain,
     )
     result = hook.list_ad_words_links(account_id=self.account_id, web_property_id=self.web_property_id,)
     return result
Exemple #5
0
 def execute(self, context):
     hook = GoogleAnalyticsHook(api_version=self.api_version,
                                gcp_conn_id=self.gcp_conn_id)
     result = hook.get_ad_words_link(
         account_id=self.account_id,
         web_property_id=self.web_property_id,
         web_property_ad_words_link_id=self.web_property_ad_words_link_id,
     )
     return result
Exemple #6
0
 def execute(self, context: 'Context') -> Dict[str, Any]:
     hook = GoogleAnalyticsHook(
         api_version=self.api_version,
         gcp_conn_id=self.gcp_conn_id,
         impersonation_chain=self.impersonation_chain,
     )
     result = hook.get_ad_words_link(
         account_id=self.account_id,
         web_property_id=self.web_property_id,
         web_property_ad_words_link_id=self.web_property_ad_words_link_id,
     )
     return result
Exemple #7
0
    def execute(self, context):
        ga_hook = GoogleAnalyticsHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            api_version=self.api_version,
            impersonation_chain=self.impersonation_chain,
        )

        uploads = ga_hook.list_uploads(
            account_id=self.account_id,
            web_property_id=self.web_property_id,
            custom_data_source_id=self.custom_data_source_id,
        )

        cids = [upload["id"] for upload in uploads]
        delete_request_body = {"customDataImportUids": cids}

        ga_hook.delete_upload_data(
            self.account_id, self.web_property_id, self.custom_data_source_id, delete_request_body,
        )
Exemple #8
0
 def setUp(self):
     with mock.patch(
         "airflow.providers.google.common.hooks.base_google.GoogleBaseHook.__init__",
         new=mock_base_gcp_hook_default_project_id,
     ):
         self.hook = GoogleAnalyticsHook(API_VERSION, GCP_CONN_ID)
Exemple #9
0
 def execute(self, context):
     hook = GoogleAnalyticsHook(api_version=self.api_version,
                                gcp_connection_id=self.gcp_connection_id)
     result = hook.list_accounts()
     return result