From fef29f4e4ff63306962a75a41ce8d24b9a88d37a Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 5 Jul 2023 17:22:12 +0200 Subject: [PATCH 1/6] chore(deps): update dependency pytest to v7.4.0 (#358) Co-authored-by: Anthonios Partheniou --- samples/snippets/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 5662849..70613be 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==7.3.2 +pytest==7.4.0 From ab647782fc94d75bce01084743c38008d535228d Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 5 Jul 2023 17:41:17 +0200 Subject: [PATCH 2/6] chore(deps): update dependency google-analytics-data to v0.16.3 (#364) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 286b4cb..cac9d0e 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-analytics-data==0.16.2 +google-analytics-data==0.16.3 google-auth-oauthlib==1.0.0 \ No newline at end of file From 4e7e3f59b5884385fe115a32b6454d94f2c40bf7 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 08:43:52 -0400 Subject: [PATCH 3/6] chore: Update gapic-generator-python to v1.11.2 (#365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Update gapic-generator-python to v1.11.2 PiperOrigin-RevId: 546510849 Source-Link: https://github.com/googleapis/googleapis/commit/736073ad9a9763a170eceaaa54519bcc0ea55a5e Source-Link: https://github.com/googleapis/googleapis-gen/commit/deb64e8ec19d141e31089fe932b3a997ad541c4d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZGViNjRlOGVjMTlkMTQxZTMxMDg5ZmU5MzJiM2E5OTdhZDU0MWM0ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- google/analytics/data/__init__.py | 2 +- google/analytics/data_v1alpha/__init__.py | 2 +- google/analytics/data_v1alpha/services/__init__.py | 2 +- .../data_v1alpha/services/alpha_analytics_data/__init__.py | 2 +- .../data_v1alpha/services/alpha_analytics_data/async_client.py | 2 +- .../data_v1alpha/services/alpha_analytics_data/client.py | 2 +- .../services/alpha_analytics_data/transports/__init__.py | 2 +- .../services/alpha_analytics_data/transports/base.py | 2 +- .../services/alpha_analytics_data/transports/grpc.py | 2 +- .../services/alpha_analytics_data/transports/grpc_asyncio.py | 2 +- .../services/alpha_analytics_data/transports/rest.py | 2 +- google/analytics/data_v1alpha/types/__init__.py | 2 +- google/analytics/data_v1alpha/types/analytics_data_api.py | 2 +- google/analytics/data_v1alpha/types/data.py | 2 +- google/analytics/data_v1beta/__init__.py | 2 +- google/analytics/data_v1beta/services/__init__.py | 2 +- .../data_v1beta/services/beta_analytics_data/__init__.py | 2 +- .../data_v1beta/services/beta_analytics_data/async_client.py | 2 +- .../data_v1beta/services/beta_analytics_data/client.py | 2 +- .../services/beta_analytics_data/transports/__init__.py | 2 +- .../data_v1beta/services/beta_analytics_data/transports/base.py | 2 +- .../data_v1beta/services/beta_analytics_data/transports/grpc.py | 2 +- .../services/beta_analytics_data/transports/grpc_asyncio.py | 2 +- .../data_v1beta/services/beta_analytics_data/transports/rest.py | 2 +- google/analytics/data_v1beta/types/__init__.py | 2 +- google/analytics/data_v1beta/types/analytics_data_api.py | 2 +- google/analytics/data_v1beta/types/data.py | 2 +- ...ha_generated_alpha_analytics_data_run_funnel_report_async.py | 2 +- ...pha_generated_alpha_analytics_data_run_funnel_report_sync.py | 2 +- ...nerated_beta_analytics_data_batch_run_pivot_reports_async.py | 2 +- ...enerated_beta_analytics_data_batch_run_pivot_reports_sync.py | 2 +- ...eta_generated_beta_analytics_data_batch_run_reports_async.py | 2 +- ...beta_generated_beta_analytics_data_batch_run_reports_sync.py | 2 +- ...a_generated_beta_analytics_data_check_compatibility_async.py | 2 +- ...ta_generated_beta_analytics_data_check_compatibility_sync.py | 2 +- ...a_v1beta_generated_beta_analytics_data_get_metadata_async.py | 2 +- ...ta_v1beta_generated_beta_analytics_data_get_metadata_sync.py | 2 +- ...beta_generated_beta_analytics_data_run_pivot_report_async.py | 2 +- ...1beta_generated_beta_analytics_data_run_pivot_report_sync.py | 2 +- ...a_generated_beta_analytics_data_run_realtime_report_async.py | 2 +- ...ta_generated_beta_analytics_data_run_realtime_report_sync.py | 2 +- ...ata_v1beta_generated_beta_analytics_data_run_report_async.py | 2 +- ...data_v1beta_generated_beta_analytics_data_run_report_sync.py | 2 +- .../snippet_metadata_google.analytics.data.v1alpha.json | 2 +- .../snippet_metadata_google.analytics.data.v1beta.json | 2 +- scripts/fixup_data_v1alpha_keywords.py | 2 +- scripts/fixup_data_v1beta_keywords.py | 2 +- setup.py | 2 +- tests/__init__.py | 2 +- tests/unit/__init__.py | 2 +- tests/unit/gapic/__init__.py | 2 +- tests/unit/gapic/data_v1alpha/__init__.py | 2 +- tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py | 2 +- tests/unit/gapic/data_v1beta/__init__.py | 2 +- tests/unit/gapic/data_v1beta/test_beta_analytics_data.py | 2 +- 55 files changed, 55 insertions(+), 55 deletions(-) diff --git a/google/analytics/data/__init__.py b/google/analytics/data/__init__.py index 737f0af..f86a037 100644 --- a/google/analytics/data/__init__.py +++ b/google/analytics/data/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/__init__.py b/google/analytics/data_v1alpha/__init__.py index 75f6ffe..9aec725 100644 --- a/google/analytics/data_v1alpha/__init__.py +++ b/google/analytics/data_v1alpha/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/__init__.py b/google/analytics/data_v1alpha/services/__init__.py index e8e1c38..89a37dc 100644 --- a/google/analytics/data_v1alpha/services/__init__.py +++ b/google/analytics/data_v1alpha/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py index 582f51b..bd5b265 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py index fe7176c..f55e33f 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py index 83383c6..501671c 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py index 04d99db..c573583 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py index 6406f88..0df851f 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py index 665e570..1ad499d 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py index ae23871..ca7ce09 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py index ce93771..501816d 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/types/__init__.py b/google/analytics/data_v1alpha/types/__init__.py index 09a02f0..20a3094 100644 --- a/google/analytics/data_v1alpha/types/__init__.py +++ b/google/analytics/data_v1alpha/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/types/analytics_data_api.py b/google/analytics/data_v1alpha/types/analytics_data_api.py index e44fb41..009e6dd 100644 --- a/google/analytics/data_v1alpha/types/analytics_data_api.py +++ b/google/analytics/data_v1alpha/types/analytics_data_api.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1alpha/types/data.py b/google/analytics/data_v1alpha/types/data.py index be088cb..648af4f 100644 --- a/google/analytics/data_v1alpha/types/data.py +++ b/google/analytics/data_v1alpha/types/data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/__init__.py b/google/analytics/data_v1beta/__init__.py index f32b5c0..8ace2e9 100644 --- a/google/analytics/data_v1beta/__init__.py +++ b/google/analytics/data_v1beta/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/__init__.py b/google/analytics/data_v1beta/services/__init__.py index e8e1c38..89a37dc 100644 --- a/google/analytics/data_v1beta/services/__init__.py +++ b/google/analytics/data_v1beta/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/__init__.py b/google/analytics/data_v1beta/services/beta_analytics_data/__init__.py index 708d647..8c29d57 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/__init__.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py index e4ef941..4b66871 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/client.py b/google/analytics/data_v1beta/services/beta_analytics_data/client.py index 012677a..5d2f610 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py index 7597d70..191e78e 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py index 5575de8..7a50afa 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py index 7fba825..8602882 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py index 6bc7689..c3bdbbc 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py index 729adcb..89b5378 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/rest.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/types/__init__.py b/google/analytics/data_v1beta/types/__init__.py index b29494a..f2eea48 100644 --- a/google/analytics/data_v1beta/types/__init__.py +++ b/google/analytics/data_v1beta/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/types/analytics_data_api.py b/google/analytics/data_v1beta/types/analytics_data_api.py index 54c108d..d2bdb84 100644 --- a/google/analytics/data_v1beta/types/analytics_data_api.py +++ b/google/analytics/data_v1beta/types/analytics_data_api.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/analytics/data_v1beta/types/data.py b/google/analytics/data_v1beta/types/data.py index 0a055e1..786411d 100644 --- a/google/analytics/data_v1beta/types/data.py +++ b/google/analytics/data_v1beta/types/data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_async.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_async.py index aa67490..de74e30 100644 --- a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_async.py +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_sync.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_sync.py index d65d5da..823eb00 100644 --- a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_sync.py +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_run_funnel_report_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_async.py index 7478f56..486c76c 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_sync.py index e41ff39..4eccc74 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_pivot_reports_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_async.py index 4d3970d..1c6ec9b 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_sync.py index dd30901..beec504 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_batch_run_reports_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_async.py index 13ca3bf..18dbf6f 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_sync.py index b1a62c0..240c982 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_check_compatibility_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_async.py index f450aed..e66b656 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_sync.py index a331017..9c329f9 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_get_metadata_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_async.py index 895037a..e2192c0 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_sync.py index 20a0574..14a3f62 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_pivot_report_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_async.py index ac1f54d..6a086d9 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_sync.py index 5985bb1..28def01 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_realtime_report_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_async.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_async.py index df56098..1a5a4c5 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_async.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_async.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_sync.py b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_sync.py index 4dbf6eb..dbe3120 100644 --- a/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_sync.py +++ b/samples/generated_samples/analyticsdata_v1beta_generated_beta_analytics_data_run_report_sync.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json index 1ccd11f..037832d 100644 --- a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json +++ b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-analytics-data", - "version": "0.16.3" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json b/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json index a6c4eb8..b945bac 100644 --- a/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json +++ b/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-analytics-data", - "version": "0.16.3" + "version": "0.1.0" }, "snippets": [ { diff --git a/scripts/fixup_data_v1alpha_keywords.py b/scripts/fixup_data_v1alpha_keywords.py index 8a3ca04..48d6350 100644 --- a/scripts/fixup_data_v1alpha_keywords.py +++ b/scripts/fixup_data_v1alpha_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/scripts/fixup_data_v1beta_keywords.py b/scripts/fixup_data_v1beta_keywords.py index 3f3b1da..7057fd5 100644 --- a/scripts/fixup_data_v1beta_keywords.py +++ b/scripts/fixup_data_v1beta_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index ffa2d5f..e9b3529 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/__init__.py b/tests/__init__.py index e8e1c38..89a37dc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index e8e1c38..89a37dc 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index e8e1c38..89a37dc 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/data_v1alpha/__init__.py b/tests/unit/gapic/data_v1alpha/__init__.py index e8e1c38..89a37dc 100644 --- a/tests/unit/gapic/data_v1alpha/__init__.py +++ b/tests/unit/gapic/data_v1alpha/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py index f409764..41597b2 100644 --- a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py +++ b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/data_v1beta/__init__.py b/tests/unit/gapic/data_v1beta/__init__.py index e8e1c38..89a37dc 100644 --- a/tests/unit/gapic/data_v1beta/__init__.py +++ b/tests/unit/gapic/data_v1beta/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py index 30a3ab5..3cd302a 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 561255486bfc0ebfc03d45b40bfe789c2c5594b1 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:34:17 -0400 Subject: [PATCH 4/6] chore: Update gapic-generator-python to v1.11.3 (#366) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Update gapic-generator-python to v1.11.3 PiperOrigin-RevId: 546899192 Source-Link: https://github.com/googleapis/googleapis/commit/e6b16918b98fe1a35f725b56537354f22b6cdc48 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0b3917c421cbda7fcb67092e16c33f3ea46f4bc7 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMGIzOTE3YzQyMWNiZGE3ZmNiNjcwOTJlMTZjMzNmM2VhNDZmNGJjNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- google/analytics/data_v1alpha/types/data.py | 3 ++- google/analytics/data_v1beta/types/data.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/google/analytics/data_v1alpha/types/data.py b/google/analytics/data_v1alpha/types/data.py index 648af4f..3af86b9 100644 --- a/google/analytics/data_v1alpha/types/data.py +++ b/google/analytics/data_v1alpha/types/data.py @@ -262,7 +262,8 @@ class MetricType(proto.Enum): class DateRange(proto.Message): r"""A contiguous set of days: startDate, startDate + 1, ..., - endDate. Requests are allowed up to 4 date ranges. + endDate. Requests + are allowed up to 4 date ranges. Attributes: start_date (str): diff --git a/google/analytics/data_v1beta/types/data.py b/google/analytics/data_v1beta/types/data.py index 786411d..5e899bf 100644 --- a/google/analytics/data_v1beta/types/data.py +++ b/google/analytics/data_v1beta/types/data.py @@ -176,7 +176,8 @@ class Compatibility(proto.Enum): class DateRange(proto.Message): r"""A contiguous set of days: startDate, startDate + 1, ..., - endDate. Requests are allowed up to 4 date ranges. + endDate. Requests + are allowed up to 4 date ranges. Attributes: start_date (str): @@ -215,8 +216,8 @@ class DateRange(proto.Message): class MinuteRange(proto.Message): r"""A contiguous set of minutes: startMinutesAgo, startMinutesAgo - + 1, ..., endMinutesAgo. Requests are allowed up to 2 minute - ranges. + + 1, ..., + endMinutesAgo. Requests are allowed up to 2 minute ranges. .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields From 538cf4586eb8883b0b4133a7fbdeb43bbdf97a81 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 09:28:27 -0400 Subject: [PATCH 5/6] feat: add `CreateAudienceList`, `QueryAudienceList`,`GetAudienceList`,`ListAudienceLists` methods to the Data API v1 alpha (#367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add `CreateAudienceList`, `QueryAudienceList`,`GetAudienceList`,`ListAudienceLists` methods to the Data API v1 alpha feat: add `AudienceList`, `AudienceRow`, `AudienceDimensionValue` types feat: add the `tokens_per_project_per_hour` field to the `PropertyQuota` type PiperOrigin-RevId: 547007393 Source-Link: https://github.com/googleapis/googleapis/commit/f2b3eb62825377999a24bd7303396f68cad4b43b Source-Link: https://github.com/googleapis/googleapis-gen/commit/52c83f985d3fe2c248378988aee6fda6606f9ef3 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTJjODNmOTg1ZDNmZTJjMjQ4Mzc4OTg4YWVlNmZkYTY2MDZmOWVmMyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- docs/data_v1alpha/alpha_analytics_data.rst | 4 + google/analytics/data_v1alpha/__init__.py | 27 +- .../data_v1alpha/gapic_metadata.json | 60 + .../alpha_analytics_data/async_client.py | 505 +++ .../services/alpha_analytics_data/client.py | 521 ++++ .../services/alpha_analytics_data/pagers.py | 157 + .../alpha_analytics_data/transports/base.py | 72 +- .../alpha_analytics_data/transports/grpc.py | 168 +- .../transports/grpc_asyncio.py | 172 +- .../alpha_analytics_data/transports/rest.py | 575 +++- .../analytics/data_v1alpha/types/__init__.py | 27 +- .../data_v1alpha/types/analytics_data_api.py | 384 ++- google/analytics/data_v1alpha/types/data.py | 35 +- ...alytics_data_create_audience_list_async.py | 60 + ...nalytics_data_create_audience_list_sync.py | 60 + ..._analytics_data_get_audience_list_async.py | 52 + ...a_analytics_data_get_audience_list_sync.py | 52 + ...nalytics_data_list_audience_lists_async.py | 53 + ...analytics_data_list_audience_lists_sync.py | 53 + ...nalytics_data_query_audience_list_async.py | 51 + ...analytics_data_query_audience_list_sync.py | 51 + ...etadata_google.analytics.data.v1alpha.json | 652 ++++ scripts/fixup_data_v1alpha_keywords.py | 4 + .../data_v1alpha/test_alpha_analytics_data.py | 2716 ++++++++++++++++- 24 files changed, 6332 insertions(+), 179 deletions(-) create mode 100644 google/analytics/data_v1alpha/services/alpha_analytics_data/pagers.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py create mode 100644 samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py diff --git a/docs/data_v1alpha/alpha_analytics_data.rst b/docs/data_v1alpha/alpha_analytics_data.rst index a59186b..76209b2 100644 --- a/docs/data_v1alpha/alpha_analytics_data.rst +++ b/docs/data_v1alpha/alpha_analytics_data.rst @@ -4,3 +4,7 @@ AlphaAnalyticsData .. automodule:: google.analytics.data_v1alpha.services.alpha_analytics_data :members: :inherited-members: + +.. automodule:: google.analytics.data_v1alpha.services.alpha_analytics_data.pagers + :members: + :inherited-members: diff --git a/google/analytics/data_v1alpha/__init__.py b/google/analytics/data_v1alpha/__init__.py index 9aec725..8f21d14 100644 --- a/google/analytics/data_v1alpha/__init__.py +++ b/google/analytics/data_v1alpha/__init__.py @@ -22,7 +22,21 @@ AlphaAnalyticsDataAsyncClient, AlphaAnalyticsDataClient, ) -from .types.analytics_data_api import RunFunnelReportRequest, RunFunnelReportResponse +from .types.analytics_data_api import ( + AudienceDimension, + AudienceDimensionValue, + AudienceList, + AudienceListMetadata, + AudienceRow, + CreateAudienceListRequest, + GetAudienceListRequest, + ListAudienceListsRequest, + ListAudienceListsResponse, + QueryAudienceListRequest, + QueryAudienceListResponse, + RunFunnelReportRequest, + RunFunnelReportResponse, +) from .types.data import ( BetweenFilter, DateRange, @@ -92,7 +106,13 @@ __all__ = ( "AlphaAnalyticsDataAsyncClient", "AlphaAnalyticsDataClient", + "AudienceDimension", + "AudienceDimensionValue", + "AudienceList", + "AudienceListMetadata", + "AudienceRow", "BetweenFilter", + "CreateAudienceListRequest", "DateRange", "Dimension", "DimensionExpression", @@ -120,13 +140,18 @@ "FunnelResponseMetadata", "FunnelStep", "FunnelSubReport", + "GetAudienceListRequest", "InListFilter", + "ListAudienceListsRequest", + "ListAudienceListsResponse", "MetricHeader", "MetricType", "MetricValue", "NumericFilter", "NumericValue", "PropertyQuota", + "QueryAudienceListRequest", + "QueryAudienceListResponse", "QuotaStatus", "Row", "RunFunnelReportRequest", diff --git a/google/analytics/data_v1alpha/gapic_metadata.json b/google/analytics/data_v1alpha/gapic_metadata.json index f8812c5..64bddf3 100644 --- a/google/analytics/data_v1alpha/gapic_metadata.json +++ b/google/analytics/data_v1alpha/gapic_metadata.json @@ -10,6 +10,26 @@ "grpc": { "libraryClient": "AlphaAnalyticsDataClient", "rpcs": { + "CreateAudienceList": { + "methods": [ + "create_audience_list" + ] + }, + "GetAudienceList": { + "methods": [ + "get_audience_list" + ] + }, + "ListAudienceLists": { + "methods": [ + "list_audience_lists" + ] + }, + "QueryAudienceList": { + "methods": [ + "query_audience_list" + ] + }, "RunFunnelReport": { "methods": [ "run_funnel_report" @@ -20,6 +40,26 @@ "grpc-async": { "libraryClient": "AlphaAnalyticsDataAsyncClient", "rpcs": { + "CreateAudienceList": { + "methods": [ + "create_audience_list" + ] + }, + "GetAudienceList": { + "methods": [ + "get_audience_list" + ] + }, + "ListAudienceLists": { + "methods": [ + "list_audience_lists" + ] + }, + "QueryAudienceList": { + "methods": [ + "query_audience_list" + ] + }, "RunFunnelReport": { "methods": [ "run_funnel_report" @@ -30,6 +70,26 @@ "rest": { "libraryClient": "AlphaAnalyticsDataClient", "rpcs": { + "CreateAudienceList": { + "methods": [ + "create_audience_list" + ] + }, + "GetAudienceList": { + "methods": [ + "get_audience_list" + ] + }, + "ListAudienceLists": { + "methods": [ + "list_audience_lists" + ] + }, + "QueryAudienceList": { + "methods": [ + "query_audience_list" + ] + }, "RunFunnelReport": { "methods": [ "run_funnel_report" diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py index f55e33f..c618d11 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py @@ -42,6 +42,11 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object] # type: ignore +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + +from google.analytics.data_v1alpha.services.alpha_analytics_data import pagers from google.analytics.data_v1alpha.types import analytics_data_api, data from .client import AlphaAnalyticsDataClient @@ -57,6 +62,10 @@ class AlphaAnalyticsDataAsyncClient: DEFAULT_ENDPOINT = AlphaAnalyticsDataClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AlphaAnalyticsDataClient.DEFAULT_MTLS_ENDPOINT + audience_list_path = staticmethod(AlphaAnalyticsDataClient.audience_list_path) + parse_audience_list_path = staticmethod( + AlphaAnalyticsDataClient.parse_audience_list_path + ) common_billing_account_path = staticmethod( AlphaAnalyticsDataClient.common_billing_account_path ) @@ -235,6 +244,12 @@ async def run_funnel_report( `GA4 Funnel Explorations `__. + This method is introduced at alpha stability with the intention + of gathering feedback on syntax and capabilities before entering + beta. To give your feedback on this API, complete the `Google + Analytics Data API Funnel Reporting + Feedback `__. + .. code-block:: python # This snippet has been automatically generated and should be regarded as a @@ -305,6 +320,496 @@ async def sample_run_funnel_report(): # Done; return the response. return response + async def create_audience_list( + self, + request: Optional[ + Union[analytics_data_api.CreateAudienceListRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + audience_list: Optional[analytics_data_api.AudienceList] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an audience list for later retrieval. This method + quickly returns the audience list's resource name and initiates + a long running asynchronous request to form an audience list. To + list the users in an audience list, first create the audience + list through this method and then send the audience resource + name to the ``QueryAudienceList`` method. + + An audience list is a snapshot of the users currently in the + audience at the time of audience list creation. Creating + audience lists for one audience on different days will return + different results as users enter and exit the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + Audience lists contain the users in each audience. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + async def sample_create_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + audience_list = data_v1alpha.AudienceList() + audience_list.audience = "audience_value" + + request = data_v1alpha.CreateAudienceListRequest( + parent="parent_value", + audience_list=audience_list, + ) + + # Make the request + operation = client.create_audience_list(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.analytics.data_v1alpha.types.CreateAudienceListRequest, dict]]): + The request object. A request to create a new audience + list. + parent (:class:`str`): + Required. The parent resource where this audience list + will be created. Format: ``properties/{propertyId}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + audience_list (:class:`google.analytics.data_v1alpha.types.AudienceList`): + Required. The audience list to + create. + + This corresponds to the ``audience_list`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.analytics.data_v1alpha.types.AudienceList` An audience list is a list of users in an audience at the time of the list's + creation. One audience may have multiple audience + lists created for different days. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, audience_list]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = analytics_data_api.CreateAudienceListRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if audience_list is not None: + request.audience_list = audience_list + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_audience_list, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + analytics_data_api.AudienceList, + metadata_type=analytics_data_api.AudienceListMetadata, + ) + + # Done; return the response. + return response + + async def query_audience_list( + self, + request: Optional[ + Union[analytics_data_api.QueryAudienceListRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.QueryAudienceListResponse: + r"""Retrieves an audience list of users. After creating an audience, + the users are not immediately available for listing. First, a + request to ``CreateAudienceList`` is necessary to create an + audience list of users, and then second, this method is used to + retrieve the users in the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + async def sample_query_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.QueryAudienceListRequest( + ) + + # Make the request + response = await client.query_audience_list(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.analytics.data_v1alpha.types.QueryAudienceListRequest, dict]]): + The request object. A request to list users in an + audience list. + name (:class:`str`): + The name of the audience list to retrieve users from. + Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.types.QueryAudienceListResponse: + A list of users in an audience list. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = analytics_data_api.QueryAudienceListRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.query_audience_list, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_audience_list( + self, + request: Optional[ + Union[analytics_data_api.GetAudienceListRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.AudienceList: + r"""Gets configuration metadata about a specific audience + list. This method can be used to understand an audience + list after it has been created. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + async def sample_get_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.GetAudienceListRequest( + name="name_value", + ) + + # Make the request + response = await client.get_audience_list(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.analytics.data_v1alpha.types.GetAudienceListRequest, dict]]): + The request object. A request to retrieve configuration + metadata about a specific audience list. + name (:class:`str`): + Required. The audience list resource name. Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.types.AudienceList: + An audience list is a list of users + in an audience at the time of the list's + creation. One audience may have multiple + audience lists created for different + days. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = analytics_data_api.GetAudienceListRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_audience_list, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_audience_lists( + self, + request: Optional[ + Union[analytics_data_api.ListAudienceListsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAudienceListsAsyncPager: + r"""Lists all audience lists for a property. This method + can be used for you to find and reuse existing audience + lists rather than creating unnecessary new audience + lists. The same audience can have multiple audience + lists that represent the list of users that were in an + audience on different days. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + async def sample_list_audience_lists(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.ListAudienceListsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_audience_lists(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.analytics.data_v1alpha.types.ListAudienceListsRequest, dict]]): + The request object. A request to list all audience lists + for a property. + parent (:class:`str`): + Required. All audience lists for this property will be + listed in the response. Format: + ``properties/{propertyId}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.services.alpha_analytics_data.pagers.ListAudienceListsAsyncPager: + A list of all audience lists for a + property. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = analytics_data_api.ListAudienceListsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_audience_lists, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListAudienceListsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + async def __aenter__(self) -> "AlphaAnalyticsDataAsyncClient": return self diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py index 501671c..56c3a86 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/client.py @@ -46,6 +46,11 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object] # type: ignore +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + +from google.analytics.data_v1alpha.services.alpha_analytics_data import pagers from google.analytics.data_v1alpha.types import analytics_data_api, data from .transports.base import DEFAULT_CLIENT_INFO, AlphaAnalyticsDataTransport @@ -176,6 +181,26 @@ def transport(self) -> AlphaAnalyticsDataTransport: """ return self._transport + @staticmethod + def audience_list_path( + propertyId: str, + audienceListId: str, + ) -> str: + """Returns a fully-qualified audience_list string.""" + return "properties/{propertyId}/audienceLists/{audienceListId}".format( + propertyId=propertyId, + audienceListId=audienceListId, + ) + + @staticmethod + def parse_audience_list_path(path: str) -> Dict[str, str]: + """Parses a audience_list path into its component segments.""" + m = re.match( + r"^properties/(?P.+?)/audienceLists/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def common_billing_account_path( billing_account: str, @@ -443,6 +468,12 @@ def run_funnel_report( `GA4 Funnel Explorations `__. + This method is introduced at alpha stability with the intention + of gathering feedback on syntax and capabilities before entering + beta. To give your feedback on this API, complete the `Google + Analytics Data API Funnel Reporting + Feedback `__. + .. code-block:: python # This snippet has been automatically generated and should be regarded as a @@ -514,6 +545,496 @@ def sample_run_funnel_report(): # Done; return the response. return response + def create_audience_list( + self, + request: Optional[ + Union[analytics_data_api.CreateAudienceListRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + audience_list: Optional[analytics_data_api.AudienceList] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates an audience list for later retrieval. This method + quickly returns the audience list's resource name and initiates + a long running asynchronous request to form an audience list. To + list the users in an audience list, first create the audience + list through this method and then send the audience resource + name to the ``QueryAudienceList`` method. + + An audience list is a snapshot of the users currently in the + audience at the time of audience list creation. Creating + audience lists for one audience on different days will return + different results as users enter and exit the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + Audience lists contain the users in each audience. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + def sample_create_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + audience_list = data_v1alpha.AudienceList() + audience_list.audience = "audience_value" + + request = data_v1alpha.CreateAudienceListRequest( + parent="parent_value", + audience_list=audience_list, + ) + + # Make the request + operation = client.create_audience_list(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.analytics.data_v1alpha.types.CreateAudienceListRequest, dict]): + The request object. A request to create a new audience + list. + parent (str): + Required. The parent resource where this audience list + will be created. Format: ``properties/{propertyId}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + audience_list (google.analytics.data_v1alpha.types.AudienceList): + Required. The audience list to + create. + + This corresponds to the ``audience_list`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.analytics.data_v1alpha.types.AudienceList` An audience list is a list of users in an audience at the time of the list's + creation. One audience may have multiple audience + lists created for different days. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, audience_list]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a analytics_data_api.CreateAudienceListRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_data_api.CreateAudienceListRequest): + request = analytics_data_api.CreateAudienceListRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if audience_list is not None: + request.audience_list = audience_list + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_audience_list] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + analytics_data_api.AudienceList, + metadata_type=analytics_data_api.AudienceListMetadata, + ) + + # Done; return the response. + return response + + def query_audience_list( + self, + request: Optional[ + Union[analytics_data_api.QueryAudienceListRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.QueryAudienceListResponse: + r"""Retrieves an audience list of users. After creating an audience, + the users are not immediately available for listing. First, a + request to ``CreateAudienceList`` is necessary to create an + audience list of users, and then second, this method is used to + retrieve the users in the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + def sample_query_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.QueryAudienceListRequest( + ) + + # Make the request + response = client.query_audience_list(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.analytics.data_v1alpha.types.QueryAudienceListRequest, dict]): + The request object. A request to list users in an + audience list. + name (str): + The name of the audience list to retrieve users from. + Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.types.QueryAudienceListResponse: + A list of users in an audience list. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a analytics_data_api.QueryAudienceListRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_data_api.QueryAudienceListRequest): + request = analytics_data_api.QueryAudienceListRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.query_audience_list] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_audience_list( + self, + request: Optional[ + Union[analytics_data_api.GetAudienceListRequest, dict] + ] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.AudienceList: + r"""Gets configuration metadata about a specific audience + list. This method can be used to understand an audience + list after it has been created. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + def sample_get_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.GetAudienceListRequest( + name="name_value", + ) + + # Make the request + response = client.get_audience_list(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.analytics.data_v1alpha.types.GetAudienceListRequest, dict]): + The request object. A request to retrieve configuration + metadata about a specific audience list. + name (str): + Required. The audience list resource name. Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.types.AudienceList: + An audience list is a list of users + in an audience at the time of the list's + creation. One audience may have multiple + audience lists created for different + days. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a analytics_data_api.GetAudienceListRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_data_api.GetAudienceListRequest): + request = analytics_data_api.GetAudienceListRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_audience_list] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_audience_lists( + self, + request: Optional[ + Union[analytics_data_api.ListAudienceListsRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAudienceListsPager: + r"""Lists all audience lists for a property. This method + can be used for you to find and reuse existing audience + lists rather than creating unnecessary new audience + lists. The same audience can have multiple audience + lists that represent the list of users that were in an + audience on different days. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.analytics import data_v1alpha + + def sample_list_audience_lists(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.ListAudienceListsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_audience_lists(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.analytics.data_v1alpha.types.ListAudienceListsRequest, dict]): + The request object. A request to list all audience lists + for a property. + parent (str): + Required. All audience lists for this property will be + listed in the response. Format: + ``properties/{propertyId}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1alpha.services.alpha_analytics_data.pagers.ListAudienceListsPager: + A list of all audience lists for a + property. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a analytics_data_api.ListAudienceListsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_data_api.ListAudienceListsRequest): + request = analytics_data_api.ListAudienceListsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_audience_lists] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListAudienceListsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + def __enter__(self) -> "AlphaAnalyticsDataClient": return self diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/pagers.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/pagers.py new file mode 100644 index 0000000..1e50618 --- /dev/null +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/pagers.py @@ -0,0 +1,157 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +from typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Iterator, + Optional, + Sequence, + Tuple, +) + +from google.analytics.data_v1alpha.types import analytics_data_api + + +class ListAudienceListsPager: + """A pager for iterating through ``list_audience_lists`` requests. + + This class thinly wraps an initial + :class:`google.analytics.data_v1alpha.types.ListAudienceListsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``audience_lists`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListAudienceLists`` requests and continue to iterate + through the ``audience_lists`` field on the + corresponding responses. + + All the usual :class:`google.analytics.data_v1alpha.types.ListAudienceListsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., analytics_data_api.ListAudienceListsResponse], + request: analytics_data_api.ListAudienceListsRequest, + response: analytics_data_api.ListAudienceListsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.analytics.data_v1alpha.types.ListAudienceListsRequest): + The initial request object. + response (google.analytics.data_v1alpha.types.ListAudienceListsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = analytics_data_api.ListAudienceListsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[analytics_data_api.ListAudienceListsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[analytics_data_api.AudienceList]: + for page in self.pages: + yield from page.audience_lists + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListAudienceListsAsyncPager: + """A pager for iterating through ``list_audience_lists`` requests. + + This class thinly wraps an initial + :class:`google.analytics.data_v1alpha.types.ListAudienceListsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``audience_lists`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListAudienceLists`` requests and continue to iterate + through the ``audience_lists`` field on the + corresponding responses. + + All the usual :class:`google.analytics.data_v1alpha.types.ListAudienceListsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[analytics_data_api.ListAudienceListsResponse]], + request: analytics_data_api.ListAudienceListsRequest, + response: analytics_data_api.ListAudienceListsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.analytics.data_v1alpha.types.ListAudienceListsRequest): + The initial request object. + response (google.analytics.data_v1alpha.types.ListAudienceListsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = analytics_data_api.ListAudienceListsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[analytics_data_api.ListAudienceListsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[analytics_data_api.AudienceList]: + async def async_generator(): + async for page in self.pages: + for response in page.audience_lists: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py index 0df851f..d2317d1 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py @@ -18,10 +18,11 @@ import google.api_core from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 +from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore from google.analytics.data_v1alpha import gapic_version as package_version @@ -130,6 +131,26 @@ def _prep_wrapped_messages(self, client_info): default_timeout=60.0, client_info=client_info, ), + self.create_audience_list: gapic_v1.method.wrap_method( + self.create_audience_list, + default_timeout=None, + client_info=client_info, + ), + self.query_audience_list: gapic_v1.method.wrap_method( + self.query_audience_list, + default_timeout=None, + client_info=client_info, + ), + self.get_audience_list: gapic_v1.method.wrap_method( + self.get_audience_list, + default_timeout=None, + client_info=client_info, + ), + self.list_audience_lists: gapic_v1.method.wrap_method( + self.list_audience_lists, + default_timeout=None, + client_info=client_info, + ), } def close(self): @@ -141,6 +162,11 @@ def close(self): """ raise NotImplementedError() + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + @property def run_funnel_report( self, @@ -153,6 +179,50 @@ def run_funnel_report( ]: raise NotImplementedError() + @property + def create_audience_list( + self, + ) -> Callable[ + [analytics_data_api.CreateAudienceListRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def query_audience_list( + self, + ) -> Callable[ + [analytics_data_api.QueryAudienceListRequest], + Union[ + analytics_data_api.QueryAudienceListResponse, + Awaitable[analytics_data_api.QueryAudienceListResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_audience_list( + self, + ) -> Callable[ + [analytics_data_api.GetAudienceListRequest], + Union[ + analytics_data_api.AudienceList, Awaitable[analytics_data_api.AudienceList] + ], + ]: + raise NotImplementedError() + + @property + def list_audience_lists( + self, + ) -> Callable[ + [analytics_data_api.ListAudienceListsRequest], + Union[ + analytics_data_api.ListAudienceListsResponse, + Awaitable[analytics_data_api.ListAudienceListsResponse], + ], + ]: + raise NotImplementedError() + @property def kind(self) -> str: raise NotImplementedError() diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py index 1ad499d..8924a67 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py @@ -16,10 +16,11 @@ from typing import Callable, Dict, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, grpc_helpers +from google.api_core import gapic_v1, grpc_helpers, operations_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from google.analytics.data_v1alpha.types import analytics_data_api @@ -110,6 +111,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -228,6 +230,20 @@ def grpc_channel(self) -> grpc.Channel: """Return the channel designed to connect to this service.""" return self._grpc_channel + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + @property def run_funnel_report( self, @@ -250,6 +266,12 @@ def run_funnel_report( `GA4 Funnel Explorations `__. + This method is introduced at alpha stability with the intention + of gathering feedback on syntax and capabilities before entering + beta. To give your feedback on this API, complete the `Google + Analytics Data API Funnel Reporting + Feedback `__. + Returns: Callable[[~.RunFunnelReportRequest], ~.RunFunnelReportResponse]: @@ -268,6 +290,150 @@ def run_funnel_report( ) return self._stubs["run_funnel_report"] + @property + def create_audience_list( + self, + ) -> Callable[ + [analytics_data_api.CreateAudienceListRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create audience list method over gRPC. + + Creates an audience list for later retrieval. This method + quickly returns the audience list's resource name and initiates + a long running asynchronous request to form an audience list. To + list the users in an audience list, first create the audience + list through this method and then send the audience resource + name to the ``QueryAudienceList`` method. + + An audience list is a snapshot of the users currently in the + audience at the time of audience list creation. Creating + audience lists for one audience on different days will return + different results as users enter and exit the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + Audience lists contain the users in each audience. + + Returns: + Callable[[~.CreateAudienceListRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_audience_list" not in self._stubs: + self._stubs["create_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/CreateAudienceList", + request_serializer=analytics_data_api.CreateAudienceListRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_audience_list"] + + @property + def query_audience_list( + self, + ) -> Callable[ + [analytics_data_api.QueryAudienceListRequest], + analytics_data_api.QueryAudienceListResponse, + ]: + r"""Return a callable for the query audience list method over gRPC. + + Retrieves an audience list of users. After creating an audience, + the users are not immediately available for listing. First, a + request to ``CreateAudienceList`` is necessary to create an + audience list of users, and then second, this method is used to + retrieve the users in the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + + Returns: + Callable[[~.QueryAudienceListRequest], + ~.QueryAudienceListResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_audience_list" not in self._stubs: + self._stubs["query_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/QueryAudienceList", + request_serializer=analytics_data_api.QueryAudienceListRequest.serialize, + response_deserializer=analytics_data_api.QueryAudienceListResponse.deserialize, + ) + return self._stubs["query_audience_list"] + + @property + def get_audience_list( + self, + ) -> Callable[ + [analytics_data_api.GetAudienceListRequest], analytics_data_api.AudienceList + ]: + r"""Return a callable for the get audience list method over gRPC. + + Gets configuration metadata about a specific audience + list. This method can be used to understand an audience + list after it has been created. + + Returns: + Callable[[~.GetAudienceListRequest], + ~.AudienceList]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_audience_list" not in self._stubs: + self._stubs["get_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/GetAudienceList", + request_serializer=analytics_data_api.GetAudienceListRequest.serialize, + response_deserializer=analytics_data_api.AudienceList.deserialize, + ) + return self._stubs["get_audience_list"] + + @property + def list_audience_lists( + self, + ) -> Callable[ + [analytics_data_api.ListAudienceListsRequest], + analytics_data_api.ListAudienceListsResponse, + ]: + r"""Return a callable for the list audience lists method over gRPC. + + Lists all audience lists for a property. This method + can be used for you to find and reuse existing audience + lists rather than creating unnecessary new audience + lists. The same audience can have multiple audience + lists that represent the list of users that were in an + audience on different days. + + Returns: + Callable[[~.ListAudienceListsRequest], + ~.ListAudienceListsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_audience_lists" not in self._stubs: + self._stubs["list_audience_lists"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/ListAudienceLists", + request_serializer=analytics_data_api.ListAudienceListsRequest.serialize, + response_deserializer=analytics_data_api.ListAudienceListsResponse.deserialize, + ) + return self._stubs["list_audience_lists"] + def close(self): self.grpc_channel.close() diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py index ca7ce09..bfb764c 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py @@ -16,9 +16,10 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, grpc_helpers_async +from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.longrunning import operations_pb2 # type: ignore import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -156,6 +157,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -231,6 +233,22 @@ def grpc_channel(self) -> aio.Channel: # Return the channel from cache. return self._grpc_channel + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + @property def run_funnel_report( self, @@ -253,6 +271,12 @@ def run_funnel_report( `GA4 Funnel Explorations `__. + This method is introduced at alpha stability with the intention + of gathering feedback on syntax and capabilities before entering + beta. To give your feedback on this API, complete the `Google + Analytics Data API Funnel Reporting + Feedback `__. + Returns: Callable[[~.RunFunnelReportRequest], Awaitable[~.RunFunnelReportResponse]]: @@ -271,6 +295,152 @@ def run_funnel_report( ) return self._stubs["run_funnel_report"] + @property + def create_audience_list( + self, + ) -> Callable[ + [analytics_data_api.CreateAudienceListRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create audience list method over gRPC. + + Creates an audience list for later retrieval. This method + quickly returns the audience list's resource name and initiates + a long running asynchronous request to form an audience list. To + list the users in an audience list, first create the audience + list through this method and then send the audience resource + name to the ``QueryAudienceList`` method. + + An audience list is a snapshot of the users currently in the + audience at the time of audience list creation. Creating + audience lists for one audience on different days will return + different results as users enter and exit the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + Audience lists contain the users in each audience. + + Returns: + Callable[[~.CreateAudienceListRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_audience_list" not in self._stubs: + self._stubs["create_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/CreateAudienceList", + request_serializer=analytics_data_api.CreateAudienceListRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_audience_list"] + + @property + def query_audience_list( + self, + ) -> Callable[ + [analytics_data_api.QueryAudienceListRequest], + Awaitable[analytics_data_api.QueryAudienceListResponse], + ]: + r"""Return a callable for the query audience list method over gRPC. + + Retrieves an audience list of users. After creating an audience, + the users are not immediately available for listing. First, a + request to ``CreateAudienceList`` is necessary to create an + audience list of users, and then second, this method is used to + retrieve the users in the audience. + + Audiences in Google Analytics 4 allow you to segment your users + in the ways that are important to your business. To learn more, + see https://support.google.com/analytics/answer/9267572. + + Returns: + Callable[[~.QueryAudienceListRequest], + Awaitable[~.QueryAudienceListResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_audience_list" not in self._stubs: + self._stubs["query_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/QueryAudienceList", + request_serializer=analytics_data_api.QueryAudienceListRequest.serialize, + response_deserializer=analytics_data_api.QueryAudienceListResponse.deserialize, + ) + return self._stubs["query_audience_list"] + + @property + def get_audience_list( + self, + ) -> Callable[ + [analytics_data_api.GetAudienceListRequest], + Awaitable[analytics_data_api.AudienceList], + ]: + r"""Return a callable for the get audience list method over gRPC. + + Gets configuration metadata about a specific audience + list. This method can be used to understand an audience + list after it has been created. + + Returns: + Callable[[~.GetAudienceListRequest], + Awaitable[~.AudienceList]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_audience_list" not in self._stubs: + self._stubs["get_audience_list"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/GetAudienceList", + request_serializer=analytics_data_api.GetAudienceListRequest.serialize, + response_deserializer=analytics_data_api.AudienceList.deserialize, + ) + return self._stubs["get_audience_list"] + + @property + def list_audience_lists( + self, + ) -> Callable[ + [analytics_data_api.ListAudienceListsRequest], + Awaitable[analytics_data_api.ListAudienceListsResponse], + ]: + r"""Return a callable for the list audience lists method over gRPC. + + Lists all audience lists for a property. This method + can be used for you to find and reuse existing audience + lists rather than creating unnecessary new audience + lists. The same audience can have multiple audience + lists that represent the list of users that were in an + audience on different days. + + Returns: + Callable[[~.ListAudienceListsRequest], + Awaitable[~.ListAudienceListsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_audience_lists" not in self._stubs: + self._stubs["list_audience_lists"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1alpha.AlphaAnalyticsData/ListAudienceLists", + request_serializer=analytics_data_api.ListAudienceListsRequest.serialize, + response_deserializer=analytics_data_api.ListAudienceListsResponse.deserialize, + ) + return self._stubs["list_audience_lists"] + def close(self): return self.grpc_channel.close() diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py index 501816d..dfc1eeb 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/transports/rest.py @@ -20,7 +20,13 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, path_template, rest_helpers, rest_streaming +from google.api_core import ( + gapic_v1, + operations_v1, + path_template, + rest_helpers, + rest_streaming, +) from google.api_core import exceptions as core_exceptions from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore @@ -36,6 +42,8 @@ OptionalRetry = Union[retries.Retry, object] # type: ignore +from google.longrunning import operations_pb2 # type: ignore + from google.analytics.data_v1alpha.types import analytics_data_api from .base import AlphaAnalyticsDataTransport @@ -63,6 +71,38 @@ class AlphaAnalyticsDataRestInterceptor: .. code-block:: python class MyCustomAlphaAnalyticsDataInterceptor(AlphaAnalyticsDataRestInterceptor): + def pre_create_audience_list(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_audience_list(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_audience_list(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_audience_list(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_audience_lists(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_audience_lists(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_query_audience_list(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_query_audience_list(self, response): + logging.log(f"Received response: {response}") + return response + def pre_run_funnel_report(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -77,6 +117,98 @@ def post_run_funnel_report(self, response): """ + def pre_create_audience_list( + self, + request: analytics_data_api.CreateAudienceListRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[analytics_data_api.CreateAudienceListRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_audience_list + + Override in a subclass to manipulate the request or metadata + before they are sent to the AlphaAnalyticsData server. + """ + return request, metadata + + def post_create_audience_list( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for create_audience_list + + Override in a subclass to manipulate the response + after it is returned by the AlphaAnalyticsData server but before + it is returned to user code. + """ + return response + + def pre_get_audience_list( + self, + request: analytics_data_api.GetAudienceListRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[analytics_data_api.GetAudienceListRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_audience_list + + Override in a subclass to manipulate the request or metadata + before they are sent to the AlphaAnalyticsData server. + """ + return request, metadata + + def post_get_audience_list( + self, response: analytics_data_api.AudienceList + ) -> analytics_data_api.AudienceList: + """Post-rpc interceptor for get_audience_list + + Override in a subclass to manipulate the response + after it is returned by the AlphaAnalyticsData server but before + it is returned to user code. + """ + return response + + def pre_list_audience_lists( + self, + request: analytics_data_api.ListAudienceListsRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[analytics_data_api.ListAudienceListsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_audience_lists + + Override in a subclass to manipulate the request or metadata + before they are sent to the AlphaAnalyticsData server. + """ + return request, metadata + + def post_list_audience_lists( + self, response: analytics_data_api.ListAudienceListsResponse + ) -> analytics_data_api.ListAudienceListsResponse: + """Post-rpc interceptor for list_audience_lists + + Override in a subclass to manipulate the response + after it is returned by the AlphaAnalyticsData server but before + it is returned to user code. + """ + return response + + def pre_query_audience_list( + self, + request: analytics_data_api.QueryAudienceListRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[analytics_data_api.QueryAudienceListRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for query_audience_list + + Override in a subclass to manipulate the request or metadata + before they are sent to the AlphaAnalyticsData server. + """ + return request, metadata + + def post_query_audience_list( + self, response: analytics_data_api.QueryAudienceListResponse + ) -> analytics_data_api.QueryAudienceListResponse: + """Post-rpc interceptor for query_audience_list + + Override in a subclass to manipulate the response + after it is returned by the AlphaAnalyticsData server but before + it is returned to user code. + """ + return response + def pre_run_funnel_report( self, request: analytics_data_api.RunFunnelReportRequest, @@ -192,11 +324,410 @@ def __init__( self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST ) + self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None if client_cert_source_for_mtls: self._session.configure_mtls_channel(client_cert_source_for_mtls) self._interceptor = interceptor or AlphaAnalyticsDataRestInterceptor() self._prep_wrapped_messages(client_info) + @property + def operations_client(self) -> operations_v1.AbstractOperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Only create a new client if we do not already have one. + if self._operations_client is None: + http_options: Dict[str, List[Dict[str, str]]] = {} + + rest_transport = operations_v1.OperationsRestTransport( + host=self._host, + # use the credentials which are saved + credentials=self._credentials, + scopes=self._scopes, + http_options=http_options, + path_prefix="v1alpha", + ) + + self._operations_client = operations_v1.AbstractOperationsClient( + transport=rest_transport + ) + + # Return the client from cache. + return self._operations_client + + class _CreateAudienceList(AlphaAnalyticsDataRestStub): + def __hash__(self): + return hash("CreateAudienceList") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: analytics_data_api.CreateAudienceListRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Call the create audience list method over HTTP. + + Args: + request (~.analytics_data_api.CreateAudienceListRequest): + The request object. A request to create a new audience + list. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1alpha/{parent=properties/*}/audienceLists", + "body": "audience_list", + }, + ] + request, metadata = self._interceptor.pre_create_audience_list( + request, metadata + ) + pb_request = analytics_data_api.CreateAudienceListRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_audience_list(resp) + return resp + + class _GetAudienceList(AlphaAnalyticsDataRestStub): + def __hash__(self): + return hash("GetAudienceList") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: analytics_data_api.GetAudienceListRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.AudienceList: + r"""Call the get audience list method over HTTP. + + Args: + request (~.analytics_data_api.GetAudienceListRequest): + The request object. A request to retrieve configuration + metadata about a specific audience list. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.analytics_data_api.AudienceList: + An audience list is a list of users + in an audience at the time of the list's + creation. One audience may have multiple + audience lists created for different + days. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1alpha/{name=properties/*/audienceLists/*}", + }, + ] + request, metadata = self._interceptor.pre_get_audience_list( + request, metadata + ) + pb_request = analytics_data_api.GetAudienceListRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = analytics_data_api.AudienceList() + pb_resp = analytics_data_api.AudienceList.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_audience_list(resp) + return resp + + class _ListAudienceLists(AlphaAnalyticsDataRestStub): + def __hash__(self): + return hash("ListAudienceLists") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: analytics_data_api.ListAudienceListsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.ListAudienceListsResponse: + r"""Call the list audience lists method over HTTP. + + Args: + request (~.analytics_data_api.ListAudienceListsRequest): + The request object. A request to list all audience lists + for a property. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.analytics_data_api.ListAudienceListsResponse: + A list of all audience lists for a + property. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1alpha/{parent=properties/*}/audienceLists", + }, + ] + request, metadata = self._interceptor.pre_list_audience_lists( + request, metadata + ) + pb_request = analytics_data_api.ListAudienceListsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = analytics_data_api.ListAudienceListsResponse() + pb_resp = analytics_data_api.ListAudienceListsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_audience_lists(resp) + return resp + + class _QueryAudienceList(AlphaAnalyticsDataRestStub): + def __hash__(self): + return hash("QueryAudienceList") + + def __call__( + self, + request: analytics_data_api.QueryAudienceListRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.QueryAudienceListResponse: + r"""Call the query audience list method over HTTP. + + Args: + request (~.analytics_data_api.QueryAudienceListRequest): + The request object. A request to list users in an + audience list. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.analytics_data_api.QueryAudienceListResponse: + A list of users in an audience list. + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1alpha/{name=properties/*/audienceLists/*}:query", + "body": "*", + }, + ] + request, metadata = self._interceptor.pre_query_audience_list( + request, metadata + ) + pb_request = analytics_data_api.QueryAudienceListRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = analytics_data_api.QueryAudienceListResponse() + pb_resp = analytics_data_api.QueryAudienceListResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_query_audience_list(resp) + return resp + class _RunFunnelReport(AlphaAnalyticsDataRestStub): def __hash__(self): return hash("RunFunnelReport") @@ -287,6 +818,48 @@ def __call__( resp = self._interceptor.post_run_funnel_report(resp) return resp + @property + def create_audience_list( + self, + ) -> Callable[ + [analytics_data_api.CreateAudienceListRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateAudienceList(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_audience_list( + self, + ) -> Callable[ + [analytics_data_api.GetAudienceListRequest], analytics_data_api.AudienceList + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetAudienceList(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_audience_lists( + self, + ) -> Callable[ + [analytics_data_api.ListAudienceListsRequest], + analytics_data_api.ListAudienceListsResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListAudienceLists(self._session, self._host, self._interceptor) # type: ignore + + @property + def query_audience_list( + self, + ) -> Callable[ + [analytics_data_api.QueryAudienceListRequest], + analytics_data_api.QueryAudienceListResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._QueryAudienceList(self._session, self._host, self._interceptor) # type: ignore + @property def run_funnel_report( self, diff --git a/google/analytics/data_v1alpha/types/__init__.py b/google/analytics/data_v1alpha/types/__init__.py index 20a3094..53b58de 100644 --- a/google/analytics/data_v1alpha/types/__init__.py +++ b/google/analytics/data_v1alpha/types/__init__.py @@ -13,7 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .analytics_data_api import RunFunnelReportRequest, RunFunnelReportResponse +from .analytics_data_api import ( + AudienceDimension, + AudienceDimensionValue, + AudienceList, + AudienceListMetadata, + AudienceRow, + CreateAudienceListRequest, + GetAudienceListRequest, + ListAudienceListsRequest, + ListAudienceListsResponse, + QueryAudienceListRequest, + QueryAudienceListResponse, + RunFunnelReportRequest, + RunFunnelReportResponse, +) from .data import ( BetweenFilter, DateRange, @@ -81,6 +95,17 @@ ) __all__ = ( + "AudienceDimension", + "AudienceDimensionValue", + "AudienceList", + "AudienceListMetadata", + "AudienceRow", + "CreateAudienceListRequest", + "GetAudienceListRequest", + "ListAudienceListsRequest", + "ListAudienceListsResponse", + "QueryAudienceListRequest", + "QueryAudienceListResponse", "RunFunnelReportRequest", "RunFunnelReportResponse", "BetweenFilter", diff --git a/google/analytics/data_v1alpha/types/analytics_data_api.py b/google/analytics/data_v1alpha/types/analytics_data_api.py index 009e6dd..a5019f8 100644 --- a/google/analytics/data_v1alpha/types/analytics_data_api.py +++ b/google/analytics/data_v1alpha/types/analytics_data_api.py @@ -17,6 +17,7 @@ from typing import MutableMapping, MutableSequence +from google.protobuf import timestamp_pb2 # type: ignore import proto # type: ignore from google.analytics.data_v1alpha.types import data @@ -24,12 +25,385 @@ __protobuf__ = proto.module( package="google.analytics.data.v1alpha", manifest={ + "GetAudienceListRequest", + "ListAudienceListsRequest", + "ListAudienceListsResponse", + "CreateAudienceListRequest", + "AudienceList", + "AudienceListMetadata", + "QueryAudienceListRequest", + "QueryAudienceListResponse", + "AudienceRow", + "AudienceDimension", + "AudienceDimensionValue", "RunFunnelReportRequest", "RunFunnelReportResponse", }, ) +class GetAudienceListRequest(proto.Message): + r"""A request to retrieve configuration metadata about a specific + audience list. + + Attributes: + name (str): + Required. The audience list resource name. Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListAudienceListsRequest(proto.Message): + r"""A request to list all audience lists for a property. + + Attributes: + parent (str): + Required. All audience lists for this property will be + listed in the response. Format: ``properties/{propertyId}`` + page_size (int): + The maximum number of audience lists to + return. The service may return fewer than this + value. If unspecified, at most 200 audience + lists will be returned. The maximum value is + 1000 (higher values will be coerced to the + maximum). + page_token (str): + A page token, received from a previous ``ListAudienceLists`` + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListAudienceLists`` must match the call that provided the + page token. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListAudienceListsResponse(proto.Message): + r"""A list of all audience lists for a property. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + audience_lists (MutableSequence[google.analytics.data_v1alpha.types.AudienceList]): + Each audience list for a property. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + + This field is a member of `oneof`_ ``_next_page_token``. + """ + + @property + def raw_page(self): + return self + + audience_lists: MutableSequence["AudienceList"] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="AudienceList", + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + + +class CreateAudienceListRequest(proto.Message): + r"""A request to create a new audience list. + + Attributes: + parent (str): + Required. The parent resource where this audience list will + be created. Format: ``properties/{propertyId}`` + audience_list (google.analytics.data_v1alpha.types.AudienceList): + Required. The audience list to create. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + audience_list: "AudienceList" = proto.Field( + proto.MESSAGE, + number=2, + message="AudienceList", + ) + + +class AudienceList(proto.Message): + r"""An audience list is a list of users in an audience at the + time of the list's creation. One audience may have multiple + audience lists created for different days. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + Output only. The audience list resource name assigned during + creation. This resource name identifies this + ``AudienceList``. + + Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + audience (str): + Required. The audience resource name. This resource name + identifies the audience being listed and is shared between + the Analytics Data & Admin APIs. + + Format: ``properties/{propertyId}/audiences/{audienceId}`` + audience_display_name (str): + Output only. The descriptive display name for + this audience. For example, "Purchasers". + dimensions (MutableSequence[google.analytics.data_v1alpha.types.AudienceDimension]): + Required. The dimensions requested and + displayed in the report response. + state (google.analytics.data_v1alpha.types.AudienceList.State): + Output only. The current state for this + AudienceList. + + This field is a member of `oneof`_ ``_state``. + begin_creating_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when CreateAudienceList was called and + the AudienceList began the ``CREATING`` state. + + This field is a member of `oneof`_ ``_begin_creating_time``. + """ + + class State(proto.Enum): + r"""The AudienceList currently exists in this state. + + Values: + STATE_UNSPECIFIED (0): + Unspecified state will never be used. + CREATING (1): + The AudienceList is currently creating and + will be available in the future. Creating occurs + immediately after the CreateAudienceList call. + ACTIVE (2): + The AudienceList is fully created and ready + for querying. An AudienceList is updated to + active asynchronously from a request; this + occurs some time (for example 15 minutes) after + the initial create call. + FAILED (3): + The AudienceList failed to be created. It is + possible that re-requesting this audience list + will succeed. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + ACTIVE = 2 + FAILED = 3 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + audience: str = proto.Field( + proto.STRING, + number=2, + ) + audience_display_name: str = proto.Field( + proto.STRING, + number=3, + ) + dimensions: MutableSequence["AudienceDimension"] = proto.RepeatedField( + proto.MESSAGE, + number=4, + message="AudienceDimension", + ) + state: State = proto.Field( + proto.ENUM, + number=5, + optional=True, + enum=State, + ) + begin_creating_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=6, + optional=True, + message=timestamp_pb2.Timestamp, + ) + + +class AudienceListMetadata(proto.Message): + r"""This metadata is currently blank.""" + + +class QueryAudienceListRequest(proto.Message): + r"""A request to list users in an audience list. + + Attributes: + name (str): + The name of the audience list to retrieve users from. + Format: + ``properties/{propertyId}/audienceLists/{audienceListId}`` + offset (int): + The row count of the start row. The first row is counted as + row 0. + + When paging, the first request does not specify offset; or + equivalently, sets offset to 0; the first request returns + the first ``limit`` of rows. The second request sets offset + to the ``limit`` of the first request; the second request + returns the second ``limit`` of rows. + + To learn more about this pagination parameter, see + `Pagination `__. + limit (int): + The number of rows to return. If unspecified, 10,000 rows + are returned. The API returns a maximum of 250,000 rows per + request, no matter how many you ask for. ``limit`` must be + positive. + + The API can also return fewer rows than the requested + ``limit``, if there aren't as many dimension values as the + ``limit``. + + To learn more about this pagination parameter, see + `Pagination `__. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + offset: int = proto.Field( + proto.INT64, + number=2, + ) + limit: int = proto.Field( + proto.INT64, + number=3, + ) + + +class QueryAudienceListResponse(proto.Message): + r"""A list of users in an audience list. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + audience_list (google.analytics.data_v1alpha.types.AudienceList): + Configuration data about AudienceList being + queried. Returned to help interpret the audience + rows in this response. For example, the + dimensions in this AudienceList correspond to + the columns in the AudienceRows. + + This field is a member of `oneof`_ ``_audience_list``. + audience_rows (MutableSequence[google.analytics.data_v1alpha.types.AudienceRow]): + Rows for each user in an audience list. The + number of rows in this response will be less + than or equal to request's page size. + row_count (int): + The total number of rows in the query result. ``rowCount`` + is independent of the number of rows returned in the + response, the ``limit`` request parameter, and the + ``offset`` request parameter. For example if a query returns + 175 rows and includes ``limit`` of 50 in the API request, + the response will contain ``rowCount`` of 175 but only 50 + rows. + + To learn more about this pagination parameter, see + `Pagination `__. + + This field is a member of `oneof`_ ``_row_count``. + """ + + audience_list: "AudienceList" = proto.Field( + proto.MESSAGE, + number=1, + optional=True, + message="AudienceList", + ) + audience_rows: MutableSequence["AudienceRow"] = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="AudienceRow", + ) + row_count: int = proto.Field( + proto.INT32, + number=3, + optional=True, + ) + + +class AudienceRow(proto.Message): + r"""Dimension value attributes for the audience user row. + + Attributes: + dimension_values (MutableSequence[google.analytics.data_v1alpha.types.AudienceDimensionValue]): + Each dimension value attribute for an + audience user. One dimension value will be added + for each dimension column requested. + """ + + dimension_values: MutableSequence["AudienceDimensionValue"] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="AudienceDimensionValue", + ) + + +class AudienceDimension(proto.Message): + r"""An audience dimension is a user attribute. Specific user attributed + are requested and then later returned in the + ``QueryAudienceListResponse``. + + Attributes: + dimension_name (str): + The API name of the dimension. See the `API + Dimensions `__ + for the list of dimension names. + """ + + dimension_name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class AudienceDimensionValue(proto.Message): + r"""The value of a dimension. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + value (str): + Value as a string if the dimension type is a + string. + + This field is a member of `oneof`_ ``one_value``. + """ + + value: str = proto.Field( + proto.STRING, + number=1, + oneof="one_value", + ) + + class RunFunnelReportRequest(proto.Message): r"""The request for a funnel report. @@ -66,7 +440,7 @@ class RunFunnelReportRequest(proto.Message): dimension expands each funnel step to the unique values of the next action. For example a next action of the ``eventName`` dimension will create rows for several events - (i.e. ``session_start`` & ``click``) and the total. + (for example ``session_start`` & ``click``) and the total. Next action only supports ``eventName`` and most Page / Screen dimensions like ``pageTitle`` and ``pagePath``. @@ -87,7 +461,7 @@ class RunFunnelReportRequest(proto.Message): limited to 4 segments. limit (int): The number of rows to return. If unspecified, 10,000 rows - are returned. The API returns a maximum of 100,000 rows per + are returned. The API returns a maximum of 250,000 rows per request, no matter how many you ask for. ``limit`` must be positive. @@ -197,9 +571,9 @@ class RunFunnelReportResponse(proto.Message): The segment dimension is only present in this response if a segment was requested. The date dimension is only present in - this response if it was requested via the ``TRENDED_FUNNEL`` - funnel type. The next action dimension is only present in - the response if it was requested. + this response if it was requested through the + ``TRENDED_FUNNEL`` funnel type. The next action dimension is + only present in the response if it was requested. property_quota (google.analytics.data_v1alpha.types.PropertyQuota): This Analytics Property's quota state including this request. diff --git a/google/analytics/data_v1alpha/types/data.py b/google/analytics/data_v1alpha/types/data.py index 3af86b9..78256a3 100644 --- a/google/analytics/data_v1alpha/types/data.py +++ b/google/analytics/data_v1alpha/types/data.py @@ -900,16 +900,16 @@ class PropertyQuota(proto.Message): Attributes: tokens_per_day (google.analytics.data_v1alpha.types.QuotaStatus): Standard Analytics Properties can use up to - 25,000 tokens per day; Analytics 360 Properties - can use 250,000 tokens per day. Most requests + 200,000 tokens per day; Analytics 360 Properties + can use 2,000,000 tokens per day. Most requests consume fewer than 10 tokens. tokens_per_hour (google.analytics.data_v1alpha.types.QuotaStatus): Standard Analytics Properties can use up to - 5,000 tokens per hour; Analytics 360 Properties - can use 50,000 tokens per hour. An API request + 40,000 tokens per hour; Analytics 360 Properties + can use 400,000 tokens per hour. An API request consumes a single number of tokens, and that - number is deducted from both the hourly and - daily quotas. + number is deducted from all of the hourly, + daily, and per project hourly quotas. concurrent_requests (google.analytics.data_v1alpha.types.QuotaStatus): Standard Analytics Properties can send up to 10 concurrent requests; Analytics 360 Properties @@ -927,6 +927,16 @@ class PropertyQuota(proto.Message): request is individually counted for this quota if the request contains potentially thresholded dimensions. + tokens_per_project_per_hour (google.analytics.data_v1alpha.types.QuotaStatus): + Analytics Properties can use up to 35% of + their tokens per project per hour. This amounts + to standard Analytics Properties can use up to + 14,000 tokens per project per hour, and + Analytics 360 Properties can use 140,000 tokens + per project per hour. An API request consumes a + single number of tokens, and that number is + deducted from all of the hourly, daily, and per + project hourly quotas. """ tokens_per_day: "QuotaStatus" = proto.Field( @@ -954,6 +964,11 @@ class PropertyQuota(proto.Message): number=5, message="QuotaStatus", ) + tokens_per_project_per_hour: "QuotaStatus" = proto.Field( + proto.MESSAGE, + number=6, + message="QuotaStatus", + ) class QuotaStatus(proto.Message): @@ -1096,8 +1111,8 @@ class FunnelStep(proto.Message): Attributes: name (str): The distinctive name for this step. If unspecified, steps - will be named by a 1 based indexed name (i.e. "0. ", "1. ", - etc.). This name defines string value returned by the + will be named by a 1 based indexed name (for example "0. ", + "1. ", etc.). This name defines string value returned by the ``funnelStepName`` dimension. For example, specifying ``name = Purchase`` in the request's third funnel step will produce ``3. Purchase`` in the funnel report response. @@ -1654,8 +1669,8 @@ class Segment(proto.Message): named "Segment". This name defines string value returned by the ``segment`` dimension. The ``segment`` dimension prefixes segment names by the 1-based index number of the - segment in the request (i.e. "1. Segment", "2. Segment", - etc.). + segment in the request (for example "1. Segment", "2. + Segment", etc.). user_segment (google.analytics.data_v1alpha.types.UserSegment): User segments are subsets of users who engaged with your site or app. diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py new file mode 100644 index 0000000..42138ff --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +async def sample_create_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + audience_list = data_v1alpha.AudienceList() + audience_list.audience = "audience_value" + + request = data_v1alpha.CreateAudienceListRequest( + parent="parent_value", + audience_list=audience_list, + ) + + # Make the request + operation = client.create_audience_list(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_async] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py new file mode 100644 index 0000000..3d107e5 --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +def sample_create_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + audience_list = data_v1alpha.AudienceList() + audience_list.audience = "audience_value" + + request = data_v1alpha.CreateAudienceListRequest( + parent="parent_value", + audience_list=audience_list, + ) + + # Make the request + operation = client.create_audience_list(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_sync] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py new file mode 100644 index 0000000..71c4555 --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +async def sample_get_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.GetAudienceListRequest( + name="name_value", + ) + + # Make the request + response = await client.get_audience_list(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_async] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py new file mode 100644 index 0000000..e1d3dfd --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +def sample_get_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.GetAudienceListRequest( + name="name_value", + ) + + # Make the request + response = client.get_audience_list(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_sync] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py new file mode 100644 index 0000000..a786ce9 --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAudienceLists +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +async def sample_list_audience_lists(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.ListAudienceListsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_audience_lists(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_async] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py new file mode 100644 index 0000000..67dfe75 --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAudienceLists +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +def sample_list_audience_lists(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.ListAudienceListsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_audience_lists(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_sync] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py new file mode 100644 index 0000000..1114cad --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +async def sample_query_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1alpha.QueryAudienceListRequest( + ) + + # Make the request + response = await client.query_audience_list(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_async] diff --git a/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py new file mode 100644 index 0000000..828a94d --- /dev/null +++ b/samples/generated_samples/analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 Google LLC +# +# Licensed 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryAudienceList +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.analytics import data_v1alpha + + +def sample_query_audience_list(): + # Create a client + client = data_v1alpha.AlphaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1alpha.QueryAudienceListRequest( + ) + + # Make the request + response = client.query_audience_list(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_sync] diff --git a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json index 037832d..53b9e85 100644 --- a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json +++ b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json @@ -11,6 +11,658 @@ "version": "0.1.0" }, "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient", + "shortName": "AlphaAnalyticsDataAsyncClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient.create_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.CreateAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "CreateAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.CreateAudienceListRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "audience_list", + "type": "google.analytics.data_v1alpha.types.AudienceList" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_audience_list" + }, + "description": "Sample for CreateAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_async", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient", + "shortName": "AlphaAnalyticsDataClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient.create_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.CreateAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "CreateAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.CreateAudienceListRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "audience_list", + "type": "google.analytics.data_v1alpha.types.AudienceList" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_audience_list" + }, + "description": "Sample for CreateAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_CreateAudienceList_sync", + "segments": [ + { + "end": 59, + "start": 27, + "type": "FULL" + }, + { + "end": 59, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 49, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 56, + "start": 50, + "type": "REQUEST_EXECUTION" + }, + { + "end": 60, + "start": 57, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_create_audience_list_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient", + "shortName": "AlphaAnalyticsDataAsyncClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient.get_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.GetAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "GetAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.GetAudienceListRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.types.AudienceList", + "shortName": "get_audience_list" + }, + "description": "Sample for GetAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient", + "shortName": "AlphaAnalyticsDataClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient.get_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.GetAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "GetAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.GetAudienceListRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.types.AudienceList", + "shortName": "get_audience_list" + }, + "description": "Sample for GetAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_GetAudienceList_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_get_audience_list_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient", + "shortName": "AlphaAnalyticsDataAsyncClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient.list_audience_lists", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.ListAudienceLists", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "ListAudienceLists" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.ListAudienceListsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.services.alpha_analytics_data.pagers.ListAudienceListsAsyncPager", + "shortName": "list_audience_lists" + }, + "description": "Sample for ListAudienceLists", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient", + "shortName": "AlphaAnalyticsDataClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient.list_audience_lists", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.ListAudienceLists", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "ListAudienceLists" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.ListAudienceListsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.services.alpha_analytics_data.pagers.ListAudienceListsPager", + "shortName": "list_audience_lists" + }, + "description": "Sample for ListAudienceLists", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_ListAudienceLists_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_list_audience_lists_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient", + "shortName": "AlphaAnalyticsDataAsyncClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataAsyncClient.query_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.QueryAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "QueryAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.QueryAudienceListRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.types.QueryAudienceListResponse", + "shortName": "query_audience_list" + }, + "description": "Sample for QueryAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient", + "shortName": "AlphaAnalyticsDataClient" + }, + "fullName": "google.analytics.data_v1alpha.AlphaAnalyticsDataClient.query_audience_list", + "method": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData.QueryAudienceList", + "service": { + "fullName": "google.analytics.data.v1alpha.AlphaAnalyticsData", + "shortName": "AlphaAnalyticsData" + }, + "shortName": "QueryAudienceList" + }, + "parameters": [ + { + "name": "request", + "type": "google.analytics.data_v1alpha.types.QueryAudienceListRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.analytics.data_v1alpha.types.QueryAudienceListResponse", + "shortName": "query_audience_list" + }, + "description": "Sample for QueryAudienceList", + "file": "analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "analyticsdata_v1alpha_generated_AlphaAnalyticsData_QueryAudienceList_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "analyticsdata_v1alpha_generated_alpha_analytics_data_query_audience_list_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/scripts/fixup_data_v1alpha_keywords.py b/scripts/fixup_data_v1alpha_keywords.py index 48d6350..0224834 100644 --- a/scripts/fixup_data_v1alpha_keywords.py +++ b/scripts/fixup_data_v1alpha_keywords.py @@ -39,6 +39,10 @@ def partition( class dataCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'create_audience_list': ('parent', 'audience_list', ), + 'get_audience_list': ('name', ), + 'list_audience_lists': ('parent', 'page_size', 'page_token', ), + 'query_audience_list': ('name', 'offset', 'limit', ), 'run_funnel_report': ('property', 'date_ranges', 'funnel', 'funnel_breakdown', 'funnel_next_action', 'funnel_visualization_type', 'segments', 'limit', 'dimension_filter', 'return_property_quota', ), } diff --git a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py index 41597b2..d3f5333 100644 --- a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py +++ b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py @@ -26,15 +26,26 @@ import json import math -from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template +from google.api_core import ( + future, + gapic_v1, + grpc_helpers, + grpc_helpers_async, + operation, + operations_v1, + path_template, +) from google.api_core import client_options from google.api_core import exceptions as core_exceptions +from google.api_core import operation_async # type: ignore import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError +from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import duration_pb2 # type: ignore from google.protobuf import json_format +from google.protobuf import timestamp_pb2 # type: ignore import grpc from grpc.experimental import aio from proto.marshal.rules import wrappers @@ -46,6 +57,7 @@ from google.analytics.data_v1alpha.services.alpha_analytics_data import ( AlphaAnalyticsDataAsyncClient, AlphaAnalyticsDataClient, + pagers, transports, ) from google.analytics.data_v1alpha.types import analytics_data_api, data @@ -899,209 +911,2500 @@ async def test_run_funnel_report_field_headers_async(): @pytest.mark.parametrize( "request_type", [ - analytics_data_api.RunFunnelReportRequest, + analytics_data_api.CreateAudienceListRequest, dict, ], ) -def test_run_funnel_report_rest(request_type): +def test_create_audience_list(request_type, transport: str = "grpc"): client = AlphaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), - transport="rest", + transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"property": "properties/sample1"} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), "request") as req: - # Designate an appropriate value for the returned response. - return_value = analytics_data_api.RunFunnelReportResponse( - kind="kind_value", - ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = analytics_data_api.RunFunnelReportResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_audience_list(request) - response_value._content = json_return_value.encode("UTF-8") - req.return_value = response_value - response = client.run_funnel_report(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CreateAudienceListRequest() # Establish that the response is the type that we expect. - assert isinstance(response, analytics_data_api.RunFunnelReportResponse) - assert response.kind == "kind_value" + assert isinstance(response, future.Future) -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_run_funnel_report_rest_interceptors(null_interceptor): - transport = transports.AlphaAnalyticsDataRestTransport( +def test_create_audience_list_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AlphaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None - if null_interceptor - else transports.AlphaAnalyticsDataRestInterceptor(), + transport="grpc", ) - client = AlphaAnalyticsDataClient(transport=transport) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport._session), "request" - ) as req, mock.patch.object( - path_template, "transcode" - ) as transcode, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "post_run_funnel_report" - ) as post, mock.patch.object( - transports.AlphaAnalyticsDataRestInterceptor, "pre_run_funnel_report" - ) as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = analytics_data_api.RunFunnelReportRequest.pb( - analytics_data_api.RunFunnelReportRequest() - ) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } + type(client.transport.create_audience_list), "__call__" + ) as call: + client.create_audience_list() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CreateAudienceListRequest() - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = analytics_data_api.RunFunnelReportResponse.to_json( - analytics_data_api.RunFunnelReportResponse() - ) - request = analytics_data_api.RunFunnelReportRequest() - metadata = [ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = analytics_data_api.RunFunnelReportResponse() +@pytest.mark.asyncio +async def test_create_audience_list_async( + transport: str = "grpc_asyncio", + request_type=analytics_data_api.CreateAudienceListRequest, +): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - client.run_funnel_report( - request, - metadata=[ - ("key", "val"), - ("cephalopod", "squid"), - ], + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") ) + response = await client.create_audience_list(request) - pre.assert_called_once() - post.assert_called_once() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CreateAudienceListRequest() + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) -def test_run_funnel_report_rest_bad_request( - transport: str = "rest", request_type=analytics_data_api.RunFunnelReportRequest -): + +@pytest.mark.asyncio +async def test_create_audience_list_async_from_dict(): + await test_create_audience_list_async(request_type=dict) + + +def test_create_audience_list_field_headers(): client = AlphaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, ) - # send a request that will satisfy transcoding - request_init = {"property": "properties/sample1"} - request = request_type(**request_init) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.CreateAudienceListRequest() - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, "request") as req, pytest.raises( - core_exceptions.BadRequest - ): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.run_funnel_report(request) + request.parent = "parent_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_audience_list(request) -def test_run_funnel_report_rest_error(): - client = AlphaAnalyticsDataClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = AlphaAnalyticsDataClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( +@pytest.mark.asyncio +async def test_create_audience_list_field_headers_async(): + client = AlphaAnalyticsDataAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - with pytest.raises(ValueError): - client = AlphaAnalyticsDataClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.CreateAudienceListRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") ) + await client.create_audience_list(request) - # It is an error to provide an api_key and a transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_audience_list_flattened(): + client = AlphaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = AlphaAnalyticsDataClient( - client_options=options, - transport=transport, - ) - # It is an error to provide an api_key and a credential. - options = mock.Mock() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = AlphaAnalyticsDataClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_audience_list( + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), ) - # It is an error to provide scopes and a transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].audience_list + mock_val = analytics_data_api.AudienceList(name="name_value") + assert arg == mock_val + + +def test_create_audience_list_flattened_error(): + client = AlphaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. with pytest.raises(ValueError): - client = AlphaAnalyticsDataClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, + client.create_audience_list( + analytics_data_api.CreateAudienceListRequest(), + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), ) -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( +@pytest.mark.asyncio +async def test_create_audience_list_flattened_async(): + client = AlphaAnalyticsDataAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - client = AlphaAnalyticsDataClient(transport=transport) - assert client.transport is transport + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.AlphaAnalyticsDataGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_audience_list( + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), + ) - transport = transports.AlphaAnalyticsDataGrpcAsyncIOTransport( + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].audience_list + mock_val = analytics_data_api.AudienceList(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_audience_list_flattened_error_async(): + client = AlphaAnalyticsDataAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - channel = transport.grpc_channel - assert channel + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_audience_list( + analytics_data_api.CreateAudienceListRequest(), + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), + ) @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.AlphaAnalyticsDataGrpcTransport, + analytics_data_api.QueryAudienceListRequest, + dict, + ], +) +def test_query_audience_list(request_type, transport: str = "grpc"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.QueryAudienceListResponse( + row_count=992, + ) + response = client.query_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.QueryAudienceListRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.QueryAudienceListResponse) + assert response.row_count == 992 + + +def test_query_audience_list_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + client.query_audience_list() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.QueryAudienceListRequest() + + +@pytest.mark.asyncio +async def test_query_audience_list_async( + transport: str = "grpc_asyncio", + request_type=analytics_data_api.QueryAudienceListRequest, +): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.QueryAudienceListResponse( + row_count=992, + ) + ) + response = await client.query_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.QueryAudienceListRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.QueryAudienceListResponse) + assert response.row_count == 992 + + +@pytest.mark.asyncio +async def test_query_audience_list_async_from_dict(): + await test_query_audience_list_async(request_type=dict) + + +def test_query_audience_list_field_headers(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.QueryAudienceListRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + call.return_value = analytics_data_api.QueryAudienceListResponse() + client.query_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_audience_list_field_headers_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.QueryAudienceListRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.QueryAudienceListResponse() + ) + await client.query_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_query_audience_list_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.QueryAudienceListResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_audience_list( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_query_audience_list_flattened_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_audience_list( + analytics_data_api.QueryAudienceListRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_query_audience_list_flattened_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.QueryAudienceListResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.QueryAudienceListResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_audience_list( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_audience_list_flattened_error_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_audience_list( + analytics_data_api.QueryAudienceListRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.GetAudienceListRequest, + dict, + ], +) +def test_get_audience_list(request_type, transport: str = "grpc"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.AudienceList( + name="name_value", + audience="audience_value", + audience_display_name="audience_display_name_value", + state=analytics_data_api.AudienceList.State.CREATING, + ) + response = client.get_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.GetAudienceListRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.AudienceList) + assert response.name == "name_value" + assert response.audience == "audience_value" + assert response.audience_display_name == "audience_display_name_value" + assert response.state == analytics_data_api.AudienceList.State.CREATING + + +def test_get_audience_list_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + client.get_audience_list() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.GetAudienceListRequest() + + +@pytest.mark.asyncio +async def test_get_audience_list_async( + transport: str = "grpc_asyncio", + request_type=analytics_data_api.GetAudienceListRequest, +): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.AudienceList( + name="name_value", + audience="audience_value", + audience_display_name="audience_display_name_value", + state=analytics_data_api.AudienceList.State.CREATING, + ) + ) + response = await client.get_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.GetAudienceListRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.AudienceList) + assert response.name == "name_value" + assert response.audience == "audience_value" + assert response.audience_display_name == "audience_display_name_value" + assert response.state == analytics_data_api.AudienceList.State.CREATING + + +@pytest.mark.asyncio +async def test_get_audience_list_async_from_dict(): + await test_get_audience_list_async(request_type=dict) + + +def test_get_audience_list_field_headers(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.GetAudienceListRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + call.return_value = analytics_data_api.AudienceList() + client.get_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_audience_list_field_headers_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.GetAudienceListRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.AudienceList() + ) + await client.get_audience_list(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_audience_list_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.AudienceList() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_audience_list( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_audience_list_flattened_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_audience_list( + analytics_data_api.GetAudienceListRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_audience_list_flattened_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_audience_list), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.AudienceList() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.AudienceList() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_audience_list( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_audience_list_flattened_error_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_audience_list( + analytics_data_api.GetAudienceListRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.ListAudienceListsRequest, + dict, + ], +) +def test_list_audience_lists(request_type, transport: str = "grpc"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.ListAudienceListsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_audience_lists(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.ListAudienceListsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAudienceListsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_audience_lists_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + client.list_audience_lists() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.ListAudienceListsRequest() + + +@pytest.mark.asyncio +async def test_list_audience_lists_async( + transport: str = "grpc_asyncio", + request_type=analytics_data_api.ListAudienceListsRequest, +): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.ListAudienceListsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_audience_lists(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.ListAudienceListsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAudienceListsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_audience_lists_async_from_dict(): + await test_list_audience_lists_async(request_type=dict) + + +def test_list_audience_lists_field_headers(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.ListAudienceListsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + call.return_value = analytics_data_api.ListAudienceListsResponse() + client.list_audience_lists(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_audience_lists_field_headers_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.ListAudienceListsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.ListAudienceListsResponse() + ) + await client.list_audience_lists(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_audience_lists_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.ListAudienceListsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_audience_lists( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_audience_lists_flattened_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_audience_lists( + analytics_data_api.ListAudienceListsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_audience_lists_flattened_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.ListAudienceListsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.ListAudienceListsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_audience_lists( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_audience_lists_flattened_error_async(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_audience_lists( + analytics_data_api.ListAudienceListsRequest(), + parent="parent_value", + ) + + +def test_list_audience_lists_pager(transport_name: str = "grpc"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + next_page_token="abc", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[], + next_page_token="def", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + ], + next_page_token="ghi", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_audience_lists(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, analytics_data_api.AudienceList) for i in results) + + +def test_list_audience_lists_pages(transport_name: str = "grpc"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + next_page_token="abc", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[], + next_page_token="def", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + ], + next_page_token="ghi", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + ), + RuntimeError, + ) + pages = list(client.list_audience_lists(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_audience_lists_async_pager(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + next_page_token="abc", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[], + next_page_token="def", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + ], + next_page_token="ghi", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_audience_lists( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, analytics_data_api.AudienceList) for i in responses) + + +@pytest.mark.asyncio +async def test_list_audience_lists_async_pages(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_audience_lists), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + next_page_token="abc", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[], + next_page_token="def", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + ], + next_page_token="ghi", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_audience_lists(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.RunFunnelReportRequest, + dict, + ], +) +def test_run_funnel_report_rest(request_type): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"property": "properties/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.RunFunnelReportResponse( + kind="kind_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.RunFunnelReportResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.run_funnel_report(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.RunFunnelReportResponse) + assert response.kind == "kind_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_run_funnel_report_rest_interceptors(null_interceptor): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.AlphaAnalyticsDataRestInterceptor(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_run_funnel_report" + ) as post, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_run_funnel_report" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = analytics_data_api.RunFunnelReportRequest.pb( + analytics_data_api.RunFunnelReportRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = analytics_data_api.RunFunnelReportResponse.to_json( + analytics_data_api.RunFunnelReportResponse() + ) + + request = analytics_data_api.RunFunnelReportRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = analytics_data_api.RunFunnelReportResponse() + + client.run_funnel_report( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_run_funnel_report_rest_bad_request( + transport: str = "rest", request_type=analytics_data_api.RunFunnelReportRequest +): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"property": "properties/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.run_funnel_report(request) + + +def test_run_funnel_report_rest_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.CreateAudienceListRequest, + dict, + ], +) +def test_create_audience_list_rest(request_type): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "properties/sample1"} + request_init["audience_list"] = { + "name": "name_value", + "audience": "audience_value", + "audience_display_name": "audience_display_name_value", + "dimensions": [{"dimension_name": "dimension_name_value"}], + "state": 1, + "begin_creating_time": {"seconds": 751, "nanos": 543}, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.create_audience_list(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_audience_list_rest_required_fields( + request_type=analytics_data_api.CreateAudienceListRequest, +): + transport_class = transports.AlphaAnalyticsDataRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_audience_list._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_audience_list._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.create_audience_list(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_audience_list_rest_unset_required_fields(): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_audience_list._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "audienceList", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_audience_list_rest_interceptors(null_interceptor): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.AlphaAnalyticsDataRestInterceptor(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_create_audience_list" + ) as post, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_create_audience_list" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = analytics_data_api.CreateAudienceListRequest.pb( + analytics_data_api.CreateAudienceListRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = analytics_data_api.CreateAudienceListRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_audience_list( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_audience_list_rest_bad_request( + transport: str = "rest", request_type=analytics_data_api.CreateAudienceListRequest +): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "properties/sample1"} + request_init["audience_list"] = { + "name": "name_value", + "audience": "audience_value", + "audience_display_name": "audience_display_name_value", + "dimensions": [{"dimension_name": "dimension_name_value"}], + "state": 1, + "begin_creating_time": {"seconds": 751, "nanos": 543}, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_audience_list(request) + + +def test_create_audience_list_rest_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "properties/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.create_audience_list(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{parent=properties/*}/audienceLists" % client.transport._host, + args[1], + ) + + +def test_create_audience_list_rest_flattened_error(transport: str = "rest"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_audience_list( + analytics_data_api.CreateAudienceListRequest(), + parent="parent_value", + audience_list=analytics_data_api.AudienceList(name="name_value"), + ) + + +def test_create_audience_list_rest_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.QueryAudienceListRequest, + dict, + ], +) +def test_query_audience_list_rest(request_type): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "properties/sample1/audienceLists/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.QueryAudienceListResponse( + row_count=992, + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.QueryAudienceListResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.query_audience_list(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.QueryAudienceListResponse) + assert response.row_count == 992 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_query_audience_list_rest_interceptors(null_interceptor): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.AlphaAnalyticsDataRestInterceptor(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_query_audience_list" + ) as post, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_query_audience_list" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = analytics_data_api.QueryAudienceListRequest.pb( + analytics_data_api.QueryAudienceListRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = ( + analytics_data_api.QueryAudienceListResponse.to_json( + analytics_data_api.QueryAudienceListResponse() + ) + ) + + request = analytics_data_api.QueryAudienceListRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = analytics_data_api.QueryAudienceListResponse() + + client.query_audience_list( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_query_audience_list_rest_bad_request( + transport: str = "rest", request_type=analytics_data_api.QueryAudienceListRequest +): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "properties/sample1/audienceLists/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.query_audience_list(request) + + +def test_query_audience_list_rest_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.QueryAudienceListResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "properties/sample1/audienceLists/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.QueryAudienceListResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.query_audience_list(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{name=properties/*/audienceLists/*}:query" + % client.transport._host, + args[1], + ) + + +def test_query_audience_list_rest_flattened_error(transport: str = "rest"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_audience_list( + analytics_data_api.QueryAudienceListRequest(), + name="name_value", + ) + + +def test_query_audience_list_rest_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.GetAudienceListRequest, + dict, + ], +) +def test_get_audience_list_rest(request_type): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"name": "properties/sample1/audienceLists/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.AudienceList( + name="name_value", + audience="audience_value", + audience_display_name="audience_display_name_value", + state=analytics_data_api.AudienceList.State.CREATING, + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.AudienceList.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.get_audience_list(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.AudienceList) + assert response.name == "name_value" + assert response.audience == "audience_value" + assert response.audience_display_name == "audience_display_name_value" + assert response.state == analytics_data_api.AudienceList.State.CREATING + + +def test_get_audience_list_rest_required_fields( + request_type=analytics_data_api.GetAudienceListRequest, +): + transport_class = transports.AlphaAnalyticsDataRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_audience_list._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_audience_list._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.AudienceList() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = analytics_data_api.AudienceList.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.get_audience_list(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_audience_list_rest_unset_required_fields(): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_audience_list._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_audience_list_rest_interceptors(null_interceptor): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.AlphaAnalyticsDataRestInterceptor(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_get_audience_list" + ) as post, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_get_audience_list" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = analytics_data_api.GetAudienceListRequest.pb( + analytics_data_api.GetAudienceListRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = analytics_data_api.AudienceList.to_json( + analytics_data_api.AudienceList() + ) + + request = analytics_data_api.GetAudienceListRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = analytics_data_api.AudienceList() + + client.get_audience_list( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_audience_list_rest_bad_request( + transport: str = "rest", request_type=analytics_data_api.GetAudienceListRequest +): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"name": "properties/sample1/audienceLists/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_audience_list(request) + + +def test_get_audience_list_rest_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.AudienceList() + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "properties/sample1/audienceLists/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.AudienceList.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.get_audience_list(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{name=properties/*/audienceLists/*}" % client.transport._host, + args[1], + ) + + +def test_get_audience_list_rest_flattened_error(transport: str = "rest"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_audience_list( + analytics_data_api.GetAudienceListRequest(), + name="name_value", + ) + + +def test_get_audience_list_rest_error(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + +@pytest.mark.parametrize( + "request_type", + [ + analytics_data_api.ListAudienceListsRequest, + dict, + ], +) +def test_list_audience_lists_rest(request_type): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "properties/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.ListAudienceListsResponse( + next_page_token="next_page_token_value", + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.ListAudienceListsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.list_audience_lists(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAudienceListsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_audience_lists_rest_required_fields( + request_type=analytics_data_api.ListAudienceListsRequest, +): + transport_class = transports.AlphaAnalyticsDataRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_audience_lists._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_audience_lists._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.ListAudienceListsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = analytics_data_api.ListAudienceListsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.list_audience_lists(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_audience_lists_rest_unset_required_fields(): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_audience_lists._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_audience_lists_rest_interceptors(null_interceptor): + transport = transports.AlphaAnalyticsDataRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.AlphaAnalyticsDataRestInterceptor(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "post_list_audience_lists" + ) as post, mock.patch.object( + transports.AlphaAnalyticsDataRestInterceptor, "pre_list_audience_lists" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = analytics_data_api.ListAudienceListsRequest.pb( + analytics_data_api.ListAudienceListsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = ( + analytics_data_api.ListAudienceListsResponse.to_json( + analytics_data_api.ListAudienceListsResponse() + ) + ) + + request = analytics_data_api.ListAudienceListsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = analytics_data_api.ListAudienceListsResponse() + + client.list_audience_lists( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_audience_lists_rest_bad_request( + transport: str = "rest", request_type=analytics_data_api.ListAudienceListsRequest +): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "properties/sample1"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_audience_lists(request) + + +def test_list_audience_lists_rest_flattened(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = analytics_data_api.ListAudienceListsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "properties/sample1"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = analytics_data_api.ListAudienceListsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.list_audience_lists(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1alpha/{parent=properties/*}/audienceLists" % client.transport._host, + args[1], + ) + + +def test_list_audience_lists_rest_flattened_error(transport: str = "rest"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_audience_lists( + analytics_data_api.ListAudienceListsRequest(), + parent="parent_value", + ) + + +def test_list_audience_lists_rest_pager(transport: str = "rest"): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + next_page_token="abc", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[], + next_page_token="def", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + ], + next_page_token="ghi", + ), + analytics_data_api.ListAudienceListsResponse( + audience_lists=[ + analytics_data_api.AudienceList(), + analytics_data_api.AudienceList(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + analytics_data_api.ListAudienceListsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "properties/sample1"} + + pager = client.list_audience_lists(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, analytics_data_api.AudienceList) for i in results) + + pages = list(client.list_audience_lists(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = AlphaAnalyticsDataClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AlphaAnalyticsDataClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = AlphaAnalyticsDataClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = AlphaAnalyticsDataClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = AlphaAnalyticsDataClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.AlphaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.AlphaAnalyticsDataGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.AlphaAnalyticsDataGrpcTransport, transports.AlphaAnalyticsDataGrpcAsyncIOTransport, transports.AlphaAnalyticsDataRestTransport, ], @@ -1160,7 +3463,13 @@ def test_alpha_analytics_data_base_transport(): # Every method on the transport should just blindly # raise NotImplementedError. - methods = ("run_funnel_report",) + methods = ( + "run_funnel_report", + "create_audience_list", + "query_audience_list", + "get_audience_list", + "list_audience_lists", + ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) @@ -1168,6 +3477,11 @@ def test_alpha_analytics_data_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + # Catch all for all remaining methods and properties remainder = [ "kind", @@ -1369,6 +3683,23 @@ def test_alpha_analytics_data_http_transport_client_cert_source_for_mtls(): mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) +def test_alpha_analytics_data_rest_lro_client(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.AbstractOperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + @pytest.mark.parametrize( "transport_name", [ @@ -1435,6 +3766,18 @@ def test_alpha_analytics_data_client_transport_session_collision(transport_name) session1 = client1.transport.run_funnel_report._session session2 = client2.transport.run_funnel_report._session assert session1 != session2 + session1 = client1.transport.create_audience_list._session + session2 = client2.transport.create_audience_list._session + assert session1 != session2 + session1 = client1.transport.query_audience_list._session + session2 = client2.transport.query_audience_list._session + assert session1 != session2 + session1 = client1.transport.get_audience_list._session + session2 = client2.transport.get_audience_list._session + assert session1 != session2 + session1 = client1.transport.list_audience_lists._session + session2 = client2.transport.list_audience_lists._session + assert session1 != session2 def test_alpha_analytics_data_grpc_transport_channel(): @@ -1563,8 +3906,65 @@ def test_alpha_analytics_data_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel +def test_alpha_analytics_data_grpc_lro_client(): + client = AlphaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_alpha_analytics_data_grpc_lro_async_client(): + client = AlphaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_audience_list_path(): + propertyId = "squid" + audienceListId = "clam" + expected = "properties/{propertyId}/audienceLists/{audienceListId}".format( + propertyId=propertyId, + audienceListId=audienceListId, + ) + actual = AlphaAnalyticsDataClient.audience_list_path(propertyId, audienceListId) + assert expected == actual + + +def test_parse_audience_list_path(): + expected = { + "propertyId": "whelk", + "audienceListId": "octopus", + } + path = AlphaAnalyticsDataClient.audience_list_path(**expected) + + # Check that the path construction is reversible. + actual = AlphaAnalyticsDataClient.parse_audience_list_path(path) + assert expected == actual + + def test_common_billing_account_path(): - billing_account = "squid" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1574,7 +3974,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "clam", + "billing_account": "nudibranch", } path = AlphaAnalyticsDataClient.common_billing_account_path(**expected) @@ -1584,7 +3984,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "whelk" + folder = "cuttlefish" expected = "folders/{folder}".format( folder=folder, ) @@ -1594,7 +3994,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "octopus", + "folder": "mussel", } path = AlphaAnalyticsDataClient.common_folder_path(**expected) @@ -1604,7 +4004,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "oyster" + organization = "winkle" expected = "organizations/{organization}".format( organization=organization, ) @@ -1614,7 +4014,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "nautilus", } path = AlphaAnalyticsDataClient.common_organization_path(**expected) @@ -1624,7 +4024,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" + project = "scallop" expected = "projects/{project}".format( project=project, ) @@ -1634,7 +4034,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "abalone", } path = AlphaAnalyticsDataClient.common_project_path(**expected) @@ -1644,8 +4044,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -1656,8 +4056,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "whelk", + "location": "octopus", } path = AlphaAnalyticsDataClient.common_location_path(**expected) From 077f0941c83e95984fa3dfec83d97240b26ebe88 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:36:05 -0400 Subject: [PATCH 6/6] chore(main): release 0.17.0 (#368) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ google/analytics/data/gapic_version.py | 2 +- google/analytics/data_v1alpha/gapic_version.py | 2 +- google/analytics/data_v1beta/gapic_version.py | 2 +- .../snippet_metadata_google.analytics.data.v1alpha.json | 2 +- .../snippet_metadata_google.analytics.data.v1beta.json | 2 +- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 70a5955..7b51ca0 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.16.3" + ".": "0.17.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index addb4c3..a23d900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.17.0](https://github.com/googleapis/python-analytics-data/compare/v0.16.3...v0.17.0) (2023-07-11) + + +### Features + +* **v1alpha:** Add `AudienceList`, `AudienceRow`, `AudienceDimensionValue` types ([538cf45](https://github.com/googleapis/python-analytics-data/commit/538cf4586eb8883b0b4133a7fbdeb43bbdf97a81)) +* **v1alpha:** Add `CreateAudienceList`, `QueryAudienceList`,`GetAudienceList`,`ListAudienceLists` methods ([538cf45](https://github.com/googleapis/python-analytics-data/commit/538cf4586eb8883b0b4133a7fbdeb43bbdf97a81)) +* **v1alpha:** Add the `tokens_per_project_per_hour` field to the `PropertyQuota` type ([538cf45](https://github.com/googleapis/python-analytics-data/commit/538cf4586eb8883b0b4133a7fbdeb43bbdf97a81)) + ## [0.16.3](https://github.com/googleapis/python-analytics-data/compare/v0.16.2...v0.16.3) (2023-07-04) diff --git a/google/analytics/data/gapic_version.py b/google/analytics/data/gapic_version.py index 291297b..3dfeb98 100644 --- a/google/analytics/data/gapic_version.py +++ b/google/analytics/data/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.16.3" # {x-release-please-version} +__version__ = "0.17.0" # {x-release-please-version} diff --git a/google/analytics/data_v1alpha/gapic_version.py b/google/analytics/data_v1alpha/gapic_version.py index 291297b..3dfeb98 100644 --- a/google/analytics/data_v1alpha/gapic_version.py +++ b/google/analytics/data_v1alpha/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.16.3" # {x-release-please-version} +__version__ = "0.17.0" # {x-release-please-version} diff --git a/google/analytics/data_v1beta/gapic_version.py b/google/analytics/data_v1beta/gapic_version.py index 291297b..3dfeb98 100644 --- a/google/analytics/data_v1beta/gapic_version.py +++ b/google/analytics/data_v1beta/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.16.3" # {x-release-please-version} +__version__ = "0.17.0" # {x-release-please-version} diff --git a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json index 53b9e85..11b5f2e 100644 --- a/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json +++ b/samples/generated_samples/snippet_metadata_google.analytics.data.v1alpha.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-analytics-data", - "version": "0.1.0" + "version": "0.17.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json b/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json index b945bac..77327be 100644 --- a/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json +++ b/samples/generated_samples/snippet_metadata_google.analytics.data.v1beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-analytics-data", - "version": "0.1.0" + "version": "0.17.0" }, "snippets": [ {