From 3123ce95735e0d9b853985338f3c85f227435a9c Mon Sep 17 00:00:00 2001 From: Google API Publisher Date: Wed, 25 Jul 2018 20:07:57 +0000 Subject: [PATCH] Ruby GAPIC: Pubsub v1 --- generated/ruby/google-cloud-pubsub/.gitignore | 13 + .../ruby/google-cloud-pubsub/.rubocop.yml | 15 + generated/ruby/google-cloud-pubsub/.yardopts | 8 + .../ruby/google-cloud-pubsub/CHANGELOG.md | 1 + generated/ruby/google-cloud-pubsub/Gemfile | 12 + generated/ruby/google-cloud-pubsub/LICENSE | 201 +++ generated/ruby/google-cloud-pubsub/README.md | 91 + generated/ruby/google-cloud-pubsub/Rakefile | 192 +++ .../cloud/pubsub/v1/publisher_smoke_test.rb | 45 + .../google-cloud-pubsub.gemspec | 29 + .../lib/google/cloud/pubsub.rb | 214 +++ .../lib/google/cloud/pubsub/v1.rb | 216 +++ .../lib/google/cloud/pubsub/v1/credentials.rb | 41 + .../pubsub/v1/doc/google/iam/v1/iam_policy.rb | 62 + .../pubsub/v1/doc/google/iam/v1/policy.rb | 127 ++ .../pubsub/v1/doc/google/protobuf/duration.rb | 90 + .../pubsub/v1/doc/google/protobuf/empty.rb | 28 + .../v1/doc/google/protobuf/field_mask.rb | 223 +++ .../v1/doc/google/protobuf/timestamp.rb | 106 ++ .../pubsub/v1/doc/google/pubsub/v1/pubsub.rb | 640 +++++++ .../google/cloud/pubsub/v1/doc/overview.rb | 102 ++ .../cloud/pubsub/v1/publisher_client.rb | 732 ++++++++ .../pubsub/v1/publisher_client_config.json | 101 ++ .../cloud/pubsub/v1/subscriber_client.rb | 1265 ++++++++++++++ .../pubsub/v1/subscriber_client_config.json | 141 ++ .../lib/google/pubsub/v1/pubsub_pb.rb | 221 +++ .../google/pubsub/v1/pubsub_services_pb.rb | 191 +++ .../cloud/pubsub/v1/publisher_client_test.rb | 829 ++++++++++ .../cloud/pubsub/v1/subscriber_client_test.rb | 1471 +++++++++++++++++ 29 files changed, 7407 insertions(+) create mode 100644 generated/ruby/google-cloud-pubsub/.gitignore create mode 100644 generated/ruby/google-cloud-pubsub/.rubocop.yml create mode 100644 generated/ruby/google-cloud-pubsub/.yardopts create mode 100644 generated/ruby/google-cloud-pubsub/CHANGELOG.md create mode 100644 generated/ruby/google-cloud-pubsub/Gemfile create mode 100644 generated/ruby/google-cloud-pubsub/LICENSE create mode 100644 generated/ruby/google-cloud-pubsub/README.md create mode 100644 generated/ruby/google-cloud-pubsub/Rakefile create mode 100644 generated/ruby/google-cloud-pubsub/acceptance/google/cloud/pubsub/v1/publisher_smoke_test.rb create mode 100644 generated/ruby/google-cloud-pubsub/google-cloud-pubsub.gemspec create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/credentials.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/overview.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client_config.json create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client_config.json create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_pb.rb create mode 100644 generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_services_pb.rb create mode 100644 generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/publisher_client_test.rb create mode 100644 generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/subscriber_client_test.rb diff --git a/generated/ruby/google-cloud-pubsub/.gitignore b/generated/ruby/google-cloud-pubsub/.gitignore new file mode 100644 index 000000000..e9bdb1b8a --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/.gitignore @@ -0,0 +1,13 @@ +Gemfile.lock +coverage/* +doc/* +pkg/* +html/* +jsondoc/* + +# Ignore YARD stuffs +.yardoc + +# IDE settings +.idea +*.iml diff --git a/generated/ruby/google-cloud-pubsub/.rubocop.yml b/generated/ruby/google-cloud-pubsub/.rubocop.yml new file mode 100644 index 000000000..1df51b470 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/.rubocop.yml @@ -0,0 +1,15 @@ +AllCops: + Exclude: + - "google-cloud-pubsub.gemspec" + - "lib/google/**/*" + - "Rakefile" + - "test/**/*" + - "acceptance/**/*smoke_test.rb" + +Documentation: + Enabled: false + +Style/StringLiterals: + EnforcedStyle: double_quotes +Style/MethodDefParentheses: + EnforcedStyle: require_no_parentheses diff --git a/generated/ruby/google-cloud-pubsub/.yardopts b/generated/ruby/google-cloud-pubsub/.yardopts new file mode 100644 index 000000000..d6d29db6b --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/.yardopts @@ -0,0 +1,8 @@ +--no-private +--title=Google Cloud Pub/Sub API +--exclude _pb\.rb$ +--markup markdown + +./lib/**/*.rb +- +README.md diff --git a/generated/ruby/google-cloud-pubsub/CHANGELOG.md b/generated/ruby/google-cloud-pubsub/CHANGELOG.md new file mode 100644 index 000000000..125a8d83d --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/CHANGELOG.md @@ -0,0 +1 @@ +# Release History diff --git a/generated/ruby/google-cloud-pubsub/Gemfile b/generated/ruby/google-cloud-pubsub/Gemfile new file mode 100644 index 000000000..65f40f77f --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/Gemfile @@ -0,0 +1,12 @@ +source "https://rubygems.org" + +gemspec + +gem "gcloud-jsondoc", + git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git", + branch: "gcloud-jsondoc" + +# WORKAROUND: builds are having problems since the release of 3.0.0 +# pin to the last known good version +gem "public_suffix", "~> 2.0" +gem "rake", "~> 11.0" diff --git a/generated/ruby/google-cloud-pubsub/LICENSE b/generated/ruby/google-cloud-pubsub/LICENSE new file mode 100644 index 000000000..a8ee855de --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + https://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. diff --git a/generated/ruby/google-cloud-pubsub/README.md b/generated/ruby/google-cloud-pubsub/README.md new file mode 100644 index 000000000..1ae8b98ff --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/README.md @@ -0,0 +1,91 @@ +# Ruby Client for Google Cloud Pub/Sub API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning)) + +[Google Cloud Pub/Sub API][Product Documentation]: +Provides reliable, many-to-many, asynchronous messaging between +applications. +- [Client Library Documentation][] +- [Product Documentation][] + +## Quick Start +In order to use this library, you first need to go through the following +steps: + +1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) +2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project) +3. [Enable the Google Cloud Pub/Sub API.](https://console.cloud.google.com/apis/api/pubsub) +4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication) + +### Installation +``` +$ gem install google-cloud-pubsub +``` + +### Preview +#### PublisherClient +```rb +require "google/cloud/pubsub" + +publisher_client = Google::Cloud::Pubsub::Publisher.new +formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path(project_id) + +# Iterate over all results. +publisher_client.list_topics(formatted_project).each do |element| + # Process element. +end + +# Or iterate over results one page at a time. +publisher_client.list_topics(formatted_project).each_page do |page| + # Process each page at a time. + page.each do |element| + # Process element. + end +end +``` + +### Next Steps +- Read the [Client Library Documentation][] for Google Cloud Pub/Sub API + to see other available methods on the client. +- Read the [Google Cloud Pub/Sub API Product documentation][Product Documentation] + to learn more about the product and see How-to Guides. +- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md) + to see the full list of Cloud APIs that we cover. + +[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1 +[Product Documentation]: https://cloud.google.com/pubsub + +## Enabling Logging + +To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. +The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, +or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) +that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) +and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information. + +Configuring a Ruby stdlib logger: + +```ruby +require "logger" + +module MyLogger + LOGGER = Logger.new $stderr, level: Logger::WARN + def logger + LOGGER + end +end + +# Define a gRPC module-level logger method before grpc/logconfig.rb loads. +module GRPC + extend MyLogger +end +``` + +## Supported Ruby Versions + +This library is supported on Ruby 2.3+. + +Google provides official support for Ruby versions that are actively supported +by Ruby Core—that is, Ruby versions that are either in normal maintenance or +in security maintenance, and not end of life. Currently, this means Ruby 2.3 +and later. Older versions of Ruby _may_ still work, but are unsupported and not +recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details +about the Ruby support schedule. diff --git a/generated/ruby/google-cloud-pubsub/Rakefile b/generated/ruby/google-cloud-pubsub/Rakefile new file mode 100644 index 000000000..af9d1589f --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/Rakefile @@ -0,0 +1,192 @@ +# Copyright 2018 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 +# +# https://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. + +require "bundler/setup" +require "bundler/gem_tasks" + +require "rubocop/rake_task" +RuboCop::RakeTask.new + +desc "Run tests." +task :test do + $LOAD_PATH.unshift "lib", "test" + Dir.glob("test/**/*test.rb") + .reject { |file| file.include? "smoke_test" } + .each { |file| require_relative file } +end + +namespace :test do + desc "Runs tests with coverage." + task :coverage do + require "simplecov" + SimpleCov.start do + command_name "google-cloud-pubsub" + track_files "lib/**/*.rb" + add_filter "test/" + end + + Rake::Task["test"].invoke + end +end + +desc "Runs the smoke tests." +task :smoke_test do + + $LOAD_PATH.unshift "lib", "smoke_test" + Dir.glob("acceptance/**/*smoke_test.rb").each { |file| require_relative file } +end + +namespace :smoke_test do + desc "Runs smoke tests with coverage." + task :coverage do + require "simplecov" + SimpleCov.start do + command_name "google-cloud-pubsub" + track_files "lib/**/*.rb" + add_filter "test/" + end + + Rake::Task["smoke_test"].invoke + end +end + +# Acceptance tests +desc "Run the google-cloud-pubsub acceptance tests." +task :acceptance, :project, :keyfile do |t, args| + project = args[:project] + project ||= + ENV["PUBSUB_TEST_PROJECT"] || + ENV["GCLOUD_TEST_PROJECT"] + keyfile = args[:keyfile] + keyfile ||= + ENV["PUBSUB_TEST_KEYFILE"] || + ENV["GCLOUD_TEST_KEYFILE"] + if keyfile + keyfile = File.read keyfile + else + keyfile ||= + ENV["PUBSUB_TEST_KEYFILE_JSON"] || + ENV["GCLOUD_TEST_KEYFILE_JSON"] + end + if project.nil? || keyfile.nil? + fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or PUBSUB_TEST_PROJECT=test123 PUBSUB_TEST_KEYFILE=/path/to/keyfile.json rake acceptance" + end + require "google/cloud/pubsub/v1/credentials" + (Google::Cloud::Pubsub::V1::Credentials::PATH_ENV_VARS + + Google::Cloud::Pubsub::V1::Credentials::JSON_ENV_VARS).each do |path| + ENV[path] = nil + end + ENV["PUBSUB_PROJECT"] = project + ENV["PUBSUB_TEST_PROJECT"] = project + ENV["PUBSUB_KEYFILE_JSON"] = keyfile + + Rake::Task["acceptance:run"].invoke +end + +namespace :acceptance do + task :run do + Rake::Task["smoke_test"].invoke + end + + desc "Run acceptance tests with coverage." + task :coverage do + end + + desc "Run acceptance cleanup." + task :cleanup do + end +end + +require "yard" +require "yard/rake/yardoc_task" +YARD::Rake::YardocTask.new + +desc "Generates JSON output from google-cloud-pubsub .yardoc" +task :jsondoc => :yard do + require "rubygems" + require "gcloud/jsondoc" + + registry = YARD::Registry.load! ".yardoc" + + toc_config = { + documents: [ + { + type: "toc", + title: "Google::Pubsub::V1::DataTypes", + modules: [ + { + title: "Google::Pubsub::V1", + include: ["google/cloud/pubsub/v1"] + }, + { + title: "Google::Protobuf", + include: ["google/protobuf"] + }, + { + title: "Google::Rpc", + include: ["google/rpc"] + } + ] + } + ] + } + + generator = Gcloud::Jsondoc::Generator.new registry, + "google-cloud-pubsub", + generate: toc_config + rm_rf "jsondoc", verbose: true + generator.write_to "jsondoc" + cp ["docs/toc.json"], "jsondoc", verbose: true +end + +desc "Run yard-doctest example tests." +task :doctest do + puts "The google-cloud-pubsub gem does not have doctest tests." +end + +desc "Run the CI build" +task :ci do + header "BUILDING google-cloud-pubsub" + header "google-cloud-pubsub rubocop", "*" + sh "bundle exec rake rubocop" + header "google-cloud-pubsub jsondoc", "*" + sh "bundle exec rake jsondoc" + header "google-cloud-pubsub doctest", "*" + sh "bundle exec rake doctest" + header "google-cloud-pubsub test", "*" + sh "bundle exec rake test" +end + +namespace :ci do + desc "Run the CI build, with acceptance tests." + task :acceptance do + Rake::Task["ci"].invoke + header "google-cloud-pubsub acceptance", "*" + sh "bundle exec rake acceptance -v" + end + task :a do + # This is a handy shortcut to save typing + Rake::Task["ci:acceptance"].invoke + end +end + +task :default => :test + +def header str, token = "#" + line_length = str.length + 8 + puts "" + puts token * line_length + puts "#{token * 3} #{str} #{token * 3}" + puts token * line_length + puts "" +end diff --git a/generated/ruby/google-cloud-pubsub/acceptance/google/cloud/pubsub/v1/publisher_smoke_test.rb b/generated/ruby/google-cloud-pubsub/acceptance/google/cloud/pubsub/v1/publisher_smoke_test.rb new file mode 100644 index 000000000..d963dee76 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/acceptance/google/cloud/pubsub/v1/publisher_smoke_test.rb @@ -0,0 +1,45 @@ +# Copyright 2018 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 +# +# https://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. + +# AUTO GENERATED BY GAPIC + +require "minitest/autorun" +require "minitest/spec" + +require "google/cloud/pubsub" + +describe "PublisherSmokeTest" do + it "runs one smoke test with list_topics" do + unless ENV["PUBSUB_TEST_PROJECT"] + fail "PUBSUB_TEST_PROJECT environment variable must be defined" + end + project_id = ENV["PUBSUB_TEST_PROJECT"].freeze + + publisher_client = Google::Cloud::Pubsub::Publisher.new + formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path(project_id) + + # Iterate over all results. + publisher_client.list_topics(formatted_project).each do |element| + # Process element. + end + + # Or iterate over results one page at a time. + publisher_client.list_topics(formatted_project).each_page do |page| + # Process each page at a time. + page.each do |element| + # Process element. + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/google-cloud-pubsub.gemspec b/generated/ruby/google-cloud-pubsub/google-cloud-pubsub.gemspec new file mode 100644 index 000000000..971a36b1c --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/google-cloud-pubsub.gemspec @@ -0,0 +1,29 @@ +# -*- ruby -*- +# encoding: utf-8 + +Gem::Specification.new do |gem| + gem.name = "google-cloud-pubsub" + gem.version = "0.1.0" + + gem.authors = ["Google LLC"] + gem.email = "googleapis-packages@google.com" + gem.description = "google-cloud-pubsub is the official library for Google Cloud Pub/Sub API." + gem.summary = "API Client library for Google Cloud Pub/Sub API" + gem.homepage = "https://github.com/googleapis/googleapis" + gem.license = "Apache-2.0" + + gem.platform = Gem::Platform::RUBY + + gem.files = `git ls-files -- lib/*`.split("\n") + + ["README.md", "LICENSE", ".yardopts"] + gem.require_paths = ["lib"] + + gem.required_ruby_version = ">= 2.0.0" + + gem.add_dependency "google-gax", "~> 1.3" + gem.add_dependency "grpc-google-iam-v1", "~> 0.6.9" + + gem.add_development_dependency "minitest", "~> 5.10" + gem.add_development_dependency "rubocop", "~> 0.50.0" + gem.add_development_dependency "simplecov", "~> 0.9" +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub.rb new file mode 100644 index 000000000..6258bebe3 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub.rb @@ -0,0 +1,214 @@ +# Copyright 2018 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 +# +# https://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. + +require "google/gax" +require "pathname" + +module Google + module Cloud + # rubocop:disable LineLength + + ## + # # Ruby Client for Google Cloud Pub/Sub API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning)) + # + # [Google Cloud Pub/Sub API][Product Documentation]: + # Provides reliable, many-to-many, asynchronous messaging between + # applications. + # - [Product Documentation][] + # + # ## Quick Start + # In order to use this library, you first need to go through the following + # steps: + # + # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) + # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project) + # 3. [Enable the Google Cloud Pub/Sub API.](https://console.cloud.google.com/apis/api/pubsub) + # 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication) + # + # ### Preview + # #### PublisherClient + # ```rb + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new + # formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path(project_id) + # + # # Iterate over all results. + # publisher_client.list_topics(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # publisher_client.list_topics(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + # ``` + # + # ### Next Steps + # - Read the [Google Cloud Pub/Sub API Product documentation][Product Documentation] + # to learn more about the product and see How-to Guides. + # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md) + # to see the full list of Cloud APIs that we cover. + # + # [Product Documentation]: https://cloud.google.com/pubsub + # + # ## Enabling Logging + # + # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. + # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, + # or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) + # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) + # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information. + # + # Configuring a Ruby stdlib logger: + # + # ```ruby + # require "logger" + # + # module MyLogger + # LOGGER = Logger.new $stderr, level: Logger::WARN + # def logger + # LOGGER + # end + # end + # + # # Define a gRPC module-level logger method before grpc/logconfig.rb loads. + # module GRPC + # extend MyLogger + # end + # ``` + # + module Pubsub + # rubocop:enable LineLength + + FILE_DIR = File.realdirpath(Pathname.new(__FILE__).join("..").join("pubsub")) + + AVAILABLE_VERSIONS = Dir["#{FILE_DIR}/*"] + .select { |file| File.directory?(file) } + .select { |dir| Google::Gax::VERSION_MATCHER.match(File.basename(dir)) } + .select { |dir| File.exist?(dir + ".rb") } + .map { |dir| File.basename(dir) } + + module Publisher + ## + # The service that an application uses to manipulate topics, and to send + # messages to a topic. + # + # @param version [Symbol, String] + # The major version of the service to be used. By default :v1 + # is used. + # @overload new(version:, credentials:, scopes:, client_config:, timeout:) + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def self.new(*args, version: :v1, **kwargs) + unless AVAILABLE_VERSIONS.include?(version.to_s.downcase) + raise "The version: #{version} is not available. The available versions " \ + "are: [#{AVAILABLE_VERSIONS.join(", ")}]" + end + + require "#{FILE_DIR}/#{version.to_s.downcase}" + version_module = Google::Cloud::Pubsub + .constants + .select {|sym| sym.to_s.downcase == version.to_s.downcase} + .first + Google::Cloud::Pubsub.const_get(version_module)::Publisher.new(*args, **kwargs) + end + end + + module Subscriber + ## + # The service that an application uses to manipulate subscriptions and to + # consume messages from a subscription via the +Pull+ method or by + # establishing a bi-directional stream using the +StreamingPull+ method. + # + # @param version [Symbol, String] + # The major version of the service to be used. By default :v1 + # is used. + # @overload new(version:, credentials:, scopes:, client_config:, timeout:) + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def self.new(*args, version: :v1, **kwargs) + unless AVAILABLE_VERSIONS.include?(version.to_s.downcase) + raise "The version: #{version} is not available. The available versions " \ + "are: [#{AVAILABLE_VERSIONS.join(", ")}]" + end + + require "#{FILE_DIR}/#{version.to_s.downcase}" + version_module = Google::Cloud::Pubsub + .constants + .select {|sym| sym.to_s.downcase == version.to_s.downcase} + .first + Google::Cloud::Pubsub.const_get(version_module)::Subscriber.new(*args, **kwargs) + end + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1.rb new file mode 100644 index 000000000..530ace96d --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1.rb @@ -0,0 +1,216 @@ +# Copyright 2018 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 +# +# https://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. + +require "google/cloud/pubsub/v1/publisher_client" +require "google/cloud/pubsub/v1/subscriber_client" + +module Google + module Cloud + module Pubsub + # rubocop:disable LineLength + + ## + # # Ruby Client for Google Cloud Pub/Sub API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning)) + # + # [Google Cloud Pub/Sub API][Product Documentation]: + # Provides reliable, many-to-many, asynchronous messaging between + # applications. + # - [Product Documentation][] + # + # ## Quick Start + # In order to use this library, you first need to go through the following + # steps: + # + # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) + # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project) + # 3. [Enable the Google Cloud Pub/Sub API.](https://console.cloud.google.com/apis/api/pubsub) + # 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication) + # + # ### Preview + # #### PublisherClient + # ```rb + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path(project_id) + # + # # Iterate over all results. + # publisher_client.list_topics(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # publisher_client.list_topics(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + # ``` + # + # ### Next Steps + # - Read the [Google Cloud Pub/Sub API Product documentation][Product Documentation] + # to learn more about the product and see How-to Guides. + # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md) + # to see the full list of Cloud APIs that we cover. + # + # [Product Documentation]: https://cloud.google.com/pubsub + # + # ## Enabling Logging + # + # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. + # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, + # or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) + # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) + # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information. + # + # Configuring a Ruby stdlib logger: + # + # ```ruby + # require "logger" + # + # module MyLogger + # LOGGER = Logger.new $stderr, level: Logger::WARN + # def logger + # LOGGER + # end + # end + # + # # Define a gRPC module-level logger method before grpc/logconfig.rb loads. + # module GRPC + # extend MyLogger + # end + # ``` + # + module V1 + # rubocop:enable LineLength + + module Publisher + ## + # The service that an application uses to manipulate topics, and to send + # messages to a topic. + # + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def self.new \ + credentials: nil, + scopes: nil, + client_config: nil, + timeout: nil, + metadata: nil, + exception_transformer: nil, + lib_name: nil, + lib_version: nil + kwargs = { + credentials: credentials, + scopes: scopes, + client_config: client_config, + timeout: timeout, + metadata: metadata, + exception_transformer: exception_transformer, + lib_name: lib_name, + lib_version: lib_version + }.select { |_, v| v != nil } + Google::Cloud::Pubsub::V1::PublisherClient.new(**kwargs) + end + end + + module Subscriber + ## + # The service that an application uses to manipulate subscriptions and to + # consume messages from a subscription via the +Pull+ method or by + # establishing a bi-directional stream using the +StreamingPull+ method. + # + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def self.new \ + credentials: nil, + scopes: nil, + client_config: nil, + timeout: nil, + metadata: nil, + exception_transformer: nil, + lib_name: nil, + lib_version: nil + kwargs = { + credentials: credentials, + scopes: scopes, + client_config: client_config, + timeout: timeout, + metadata: metadata, + exception_transformer: exception_transformer, + lib_name: lib_name, + lib_version: lib_version + }.select { |_, v| v != nil } + Google::Cloud::Pubsub::V1::SubscriberClient.new(**kwargs) + end + end + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/credentials.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/credentials.rb new file mode 100644 index 000000000..03c126856 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/credentials.rb @@ -0,0 +1,41 @@ +# Copyright 2018 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 +# +# https://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. + +require "googleauth" + +module Google + module Cloud + module Pubsub + module V1 + class Credentials < Google::Auth::Credentials + SCOPE = [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/pubsub" + ].freeze + PATH_ENV_VARS = %w(PUBSUB_KEYFILE + PUBSUB_CREDENTIALS + GOOGLE_CLOUD_CREDENTIALS + GOOGLE_CLOUD_KEYFILE + GCLOUD_KEYFILE) + JSON_ENV_VARS = %w(PUBSUB_KEYFILE_JSON + PUBSUB_CREDENTIALS_JSON + GOOGLE_CLOUD_CREDENTIALS_JSON + GOOGLE_CLOUD_KEYFILE_JSON + GCLOUD_KEYFILE_JSON) + DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"] + end + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb new file mode 100644 index 000000000..68de3c444 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb @@ -0,0 +1,62 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Iam + module V1 + # Request message for +SetIamPolicy+ method. + # @!attribute [rw] resource + # @return [String] + # REQUIRED: The resource for which the policy is being specified. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @!attribute [rw] policy + # @return [Google::Iam::V1::Policy] + # REQUIRED: The complete policy to be applied to the +resource+. The size of + # the policy is limited to a few 10s of KB. An empty policy is a + # valid policy but certain Cloud Platform services (such as Projects) + # might reject them. + class SetIamPolicyRequest; end + + # Request message for +GetIamPolicy+ method. + # @!attribute [rw] resource + # @return [String] + # REQUIRED: The resource for which the policy is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + class GetIamPolicyRequest; end + + # Request message for +TestIamPermissions+ method. + # @!attribute [rw] resource + # @return [String] + # REQUIRED: The resource for which the policy detail is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @!attribute [rw] permissions + # @return [Array] + # The set of permissions to check for the +resource+. Permissions with + # wildcards (such as '*' or 'storage.*') are not allowed. For more + # information see + # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + class TestIamPermissionsRequest; end + + # Response message for +TestIamPermissions+ method. + # @!attribute [rw] permissions + # @return [Array] + # A subset of +TestPermissionsRequest.permissions+ that the caller is + # allowed. + class TestIamPermissionsResponse; end + end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb new file mode 100644 index 000000000..a9d342b89 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb @@ -0,0 +1,127 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Iam + module V1 + # Defines an Identity and Access Management (IAM) policy. It is used to + # specify access control policies for Cloud Platform resources. + # + # + # A +Policy+ consists of a list of +bindings+. A +Binding+ binds a list of + # +members+ to a +role+, where the members can be user accounts, Google groups, + # Google domains, and service accounts. A +role+ is a named list of permissions + # defined by IAM. + # + # **Example** + # + # { + # "bindings": [ + # { + # "role": "roles/owner", + # "members": [ + # "user:mike@example.com", + # "group:admins@example.com", + # "domain:google.com", + # "serviceAccount:my-other-app@appspot.gserviceaccount.com", + # ] + # }, + # { + # "role": "roles/viewer", + # "members": ["user:sean@example.com"] + # } + # ] + # } + # + # For a description of IAM and its features, see the + # [IAM developer's guide](https://cloud.google.com/iam). + # @!attribute [rw] version + # @return [Integer] + # Version of the +Policy+. The default version is 0. + # @!attribute [rw] bindings + # @return [Array] + # Associates a list of +members+ to a +role+. + # Multiple +bindings+ must not be specified for the same +role+. + # +bindings+ with no members will result in an error. + # @!attribute [rw] etag + # @return [String] + # +etag+ is used for optimistic concurrency control as a way to help + # prevent simultaneous updates of a policy from overwriting each other. + # It is strongly suggested that systems make use of the +etag+ in the + # read-modify-write cycle to perform policy updates in order to avoid race + # conditions: An +etag+ is returned in the response to +getIamPolicy+, and + # systems are expected to put that etag in the request to +setIamPolicy+ to + # ensure that their change will be applied to the same version of the policy. + # + # If no +etag+ is provided in the call to +setIamPolicy+, then the existing + # policy is overwritten blindly. + class Policy; end + + # Associates +members+ with a +role+. + # @!attribute [rw] role + # @return [String] + # Role that is assigned to +members+. + # For example, +roles/viewer+, +roles/editor+, or +roles/owner+. + # Required + # @!attribute [rw] members + # @return [Array] + # Specifies the identities requesting access for a Cloud Platform resource. + # +members+ can have the following values: + # + # * +allUsers+: A special identifier that represents anyone who is + # on the internet; with or without a Google account. + # + # * +allAuthenticatedUsers+: A special identifier that represents anyone + # who is authenticated with a Google account or a service account. + # + # * +user:{emailid}+: An email address that represents a specific Google + # account. For example, +alice@gmail.com+ or +joe@example.com+. + # + # + # * +serviceAccount:{emailid}+: An email address that represents a service + # account. For example, +my-other-app@appspot.gserviceaccount.com+. + # + # * +group:{emailid}+: An email address that represents a Google group. + # For example, +admins@example.com+. + # + # * +domain:{domain}+: A Google Apps domain name that represents all the + # users of that domain. For example, +google.com+ or +example.com+. + class Binding; end + + # The difference delta between two policies. + # @!attribute [rw] binding_deltas + # @return [Array] + # The delta for Bindings between two policies. + class PolicyDelta; end + + # One delta entry for Binding. Each individual change (only one member in each + # entry) to a binding will be a separate entry. + # @!attribute [rw] action + # @return [Google::Iam::V1::BindingDelta::Action] + # The action that was performed on a Binding. + # Required + # @!attribute [rw] role + # @return [String] + # Role that is assigned to +members+. + # For example, +roles/viewer+, +roles/editor+, or +roles/owner+. + # Required + # @!attribute [rw] member + # @return [String] + # A single identity requesting access for a Cloud Platform resource. + # Follows the same format of Binding.members. + # Required + class BindingDelta; end + end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb new file mode 100644 index 000000000..494c711c5 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb @@ -0,0 +1,90 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Protobuf + # A Duration represents a signed, fixed-length span of time represented + # as a count of seconds and fractions of seconds at nanosecond + # resolution. It is independent of any calendar and concepts like "day" + # or "month". It is related to Timestamp in that the difference between + # two Timestamp values is a Duration and it can be added or subtracted + # from a Timestamp. Range is approximately +-10,000 years. + # + # = Examples + # + # Example 1: Compute Duration from two Timestamps in pseudo code. + # + # Timestamp start = ...; + # Timestamp end = ...; + # Duration duration = ...; + # + # duration.seconds = end.seconds - start.seconds; + # duration.nanos = end.nanos - start.nanos; + # + # if (duration.seconds < 0 && duration.nanos > 0) { + # duration.seconds += 1; + # duration.nanos -= 1000000000; + # } else if (durations.seconds > 0 && duration.nanos < 0) { + # duration.seconds -= 1; + # duration.nanos += 1000000000; + # } + # + # Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + # + # Timestamp start = ...; + # Duration duration = ...; + # Timestamp end = ...; + # + # end.seconds = start.seconds + duration.seconds; + # end.nanos = start.nanos + duration.nanos; + # + # if (end.nanos < 0) { + # end.seconds -= 1; + # end.nanos += 1000000000; + # } else if (end.nanos >= 1000000000) { + # end.seconds += 1; + # end.nanos -= 1000000000; + # } + # + # Example 3: Compute Duration from datetime.timedelta in Python. + # + # td = datetime.timedelta(days=3, minutes=10) + # duration = Duration() + # duration.FromTimedelta(td) + # + # = JSON Mapping + # + # In JSON format, the Duration type is encoded as a string rather than an + # object, where the string ends in the suffix "s" (indicating seconds) and + # is preceded by the number of seconds, with nanoseconds expressed as + # fractional seconds. For example, 3 seconds with 0 nanoseconds should be + # encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + # be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + # microsecond should be expressed in JSON format as "3.000001s". + # @!attribute [rw] seconds + # @return [Integer] + # Signed seconds of the span of time. Must be from -315,576,000,000 + # to +315,576,000,000 inclusive. Note: these bounds are computed from: + # 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + # @!attribute [rw] nanos + # @return [Integer] + # Signed fractions of a second at nanosecond resolution of the span + # of time. Durations less than one second are represented with a 0 + # +seconds+ field and a positive or negative +nanos+ field. For durations + # of one second or more, a non-zero value for the +nanos+ field must be + # of the same sign as the +seconds+ field. Must be from -999,999,999 + # to +999,999,999 inclusive. + class Duration; end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb new file mode 100644 index 000000000..df00690a1 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb @@ -0,0 +1,28 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Protobuf + # A generic empty message that you can re-use to avoid defining duplicated + # empty messages in your APIs. A typical example is to use it as the request + # or the response type of an API method. For instance: + # + # service Foo { + # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + # } + # + # The JSON representation for +Empty+ is empty JSON object +{}+. + class Empty; end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb new file mode 100644 index 000000000..1f9fcca63 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb @@ -0,0 +1,223 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Protobuf + # +FieldMask+ represents a set of symbolic field paths, for example: + # + # paths: "f.a" + # paths: "f.b.d" + # + # Here +f+ represents a field in some root message, +a+ and +b+ + # fields in the message found in +f+, and +d+ a field found in the + # message in +f.b+. + # + # Field masks are used to specify a subset of fields that should be + # returned by a get operation or modified by an update operation. + # Field masks also have a custom JSON encoding (see below). + # + # = Field Masks in Projections + # + # When used in the context of a projection, a response message or + # sub-message is filtered by the API to only contain those fields as + # specified in the mask. For example, if the mask in the previous + # example is applied to a response message as follows: + # + # f { + # a : 22 + # b { + # d : 1 + # x : 2 + # } + # y : 13 + # } + # z: 8 + # + # The result will not contain specific values for fields x,y and z + # (their value will be set to the default, and omitted in proto text + # output): + # + # + # f { + # a : 22 + # b { + # d : 1 + # } + # } + # + # A repeated field is not allowed except at the last position of a + # paths string. + # + # If a FieldMask object is not present in a get operation, the + # operation applies to all fields (as if a FieldMask of all fields + # had been specified). + # + # Note that a field mask does not necessarily apply to the + # top-level response message. In case of a REST get operation, the + # field mask applies directly to the response, but in case of a REST + # list operation, the mask instead applies to each individual message + # in the returned resource list. In case of a REST custom method, + # other definitions may be used. Where the mask applies will be + # clearly documented together with its declaration in the API. In + # any case, the effect on the returned resource/resources is required + # behavior for APIs. + # + # = Field Masks in Update Operations + # + # A field mask in update operations specifies which fields of the + # targeted resource are going to be updated. The API is required + # to only change the values of the fields as specified in the mask + # and leave the others untouched. If a resource is passed in to + # describe the updated values, the API ignores the values of all + # fields not covered by the mask. + # + # If a repeated field is specified for an update operation, the existing + # repeated values in the target resource will be overwritten by the new values. + # Note that a repeated field is only allowed in the last position of a +paths+ + # string. + # + # If a sub-message is specified in the last position of the field mask for an + # update operation, then the existing sub-message in the target resource is + # overwritten. Given the target message: + # + # f { + # b { + # d : 1 + # x : 2 + # } + # c : 1 + # } + # + # And an update message: + # + # f { + # b { + # d : 10 + # } + # } + # + # then if the field mask is: + # + # paths: "f.b" + # + # then the result will be: + # + # f { + # b { + # d : 10 + # } + # c : 1 + # } + # + # However, if the update mask was: + # + # paths: "f.b.d" + # + # then the result would be: + # + # f { + # b { + # d : 10 + # x : 2 + # } + # c : 1 + # } + # + # In order to reset a field's value to the default, the field must + # be in the mask and set to the default value in the provided resource. + # Hence, in order to reset all fields of a resource, provide a default + # instance of the resource and set all fields in the mask, or do + # not provide a mask as described below. + # + # If a field mask is not present on update, the operation applies to + # all fields (as if a field mask of all fields has been specified). + # Note that in the presence of schema evolution, this may mean that + # fields the client does not know and has therefore not filled into + # the request will be reset to their default. If this is unwanted + # behavior, a specific service may require a client to always specify + # a field mask, producing an error if not. + # + # As with get operations, the location of the resource which + # describes the updated values in the request message depends on the + # operation kind. In any case, the effect of the field mask is + # required to be honored by the API. + # + # == Considerations for HTTP REST + # + # The HTTP kind of an update operation which uses a field mask must + # be set to PATCH instead of PUT in order to satisfy HTTP semantics + # (PUT must only be used for full updates). + # + # = JSON Encoding of Field Masks + # + # In JSON, a field mask is encoded as a single string where paths are + # separated by a comma. Fields name in each path are converted + # to/from lower-camel naming conventions. + # + # As an example, consider the following message declarations: + # + # message Profile { + # User user = 1; + # Photo photo = 2; + # } + # message User { + # string display_name = 1; + # string address = 2; + # } + # + # In proto a field mask for +Profile+ may look as such: + # + # mask { + # paths: "user.display_name" + # paths: "photo" + # } + # + # In JSON, the same mask is represented as below: + # + # { + # mask: "user.displayName,photo" + # } + # + # = Field Masks and Oneof Fields + # + # Field masks treat fields in oneofs just as regular fields. Consider the + # following message: + # + # message SampleMessage { + # oneof test_oneof { + # string name = 4; + # SubMessage sub_message = 9; + # } + # } + # + # The field mask can be: + # + # mask { + # paths: "name" + # } + # + # Or: + # + # mask { + # paths: "sub_message" + # } + # + # Note that oneof type names ("test_oneof" in this case) cannot be used in + # paths. + # @!attribute [rw] paths + # @return [Array] + # The set of field mask paths. + class FieldMask; end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb new file mode 100644 index 000000000..1620ae26d --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb @@ -0,0 +1,106 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Protobuf + # A Timestamp represents a point in time independent of any time zone + # or calendar, represented as seconds and fractions of seconds at + # nanosecond resolution in UTC Epoch time. It is encoded using the + # Proleptic Gregorian Calendar which extends the Gregorian calendar + # backwards to year one. It is encoded assuming all minutes are 60 + # seconds long, i.e. leap seconds are "smeared" so that no leap second + # table is needed for interpretation. Range is from + # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. + # By restricting to that range, we ensure that we can convert to + # and from RFC 3339 date strings. + # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). + # + # = Examples + # + # Example 1: Compute Timestamp from POSIX +time()+. + # + # Timestamp timestamp; + # timestamp.set_seconds(time(NULL)); + # timestamp.set_nanos(0); + # + # Example 2: Compute Timestamp from POSIX +gettimeofday()+. + # + # struct timeval tv; + # gettimeofday(&tv, NULL); + # + # Timestamp timestamp; + # timestamp.set_seconds(tv.tv_sec); + # timestamp.set_nanos(tv.tv_usec * 1000); + # + # Example 3: Compute Timestamp from Win32 +GetSystemTimeAsFileTime()+. + # + # FILETIME ft; + # GetSystemTimeAsFileTime(&ft); + # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + # + # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + # Timestamp timestamp; + # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + # + # Example 4: Compute Timestamp from Java +System.currentTimeMillis()+. + # + # long millis = System.currentTimeMillis(); + # + # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + # .setNanos((int) ((millis % 1000) * 1000000)).build(); + # + # + # Example 5: Compute Timestamp from current time in Python. + # + # timestamp = Timestamp() + # timestamp.GetCurrentTime() + # + # = JSON Mapping + # + # In JSON format, the Timestamp type is encoded as a string in the + # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + # where {year} is always expressed using four digits while {month}, {day}, + # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + # is required, though only UTC (as indicated by "Z") is presently supported. + # + # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + # 01:30 UTC on January 15, 2017. + # + # In JavaScript, one can convert a Date object to this format using the + # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] + # method. In Python, a standard +datetime.datetime+ object can be converted + # to this format using [+strftime+](https://docs.python.org/2/library/time.html#time.strftime) + # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one + # can use the Joda Time's [+ISODateTimeFormat.dateTime()+]( + # http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) + # to obtain a formatter capable of generating timestamps in this format. + # @!attribute [rw] seconds + # @return [Integer] + # Represents seconds of UTC time since Unix epoch + # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + # 9999-12-31T23:59:59Z inclusive. + # @!attribute [rw] nanos + # @return [Integer] + # Non-negative fractions of a second at nanosecond resolution. Negative + # second values with fractions must still have non-negative nanos values + # that count forward in time. Must be from 0 to 999,999,999 + # inclusive. + class Timestamp; end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb new file mode 100644 index 000000000..95100b77b --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb @@ -0,0 +1,640 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Pubsub + ## + # # Google Cloud Pub/Sub API Contents + # + # | Class | Description | + # | ----- | ----------- | + # | [PublisherClient][] | The service that an application uses to manipulate topics, and to send messages to a topic. | + # | [SubscriberClient][] | The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the +Pull+ method or by establishing a bi-directional stream using the +StreamingPull+ method. | + # | [Data Types][] | Data types for Google::Cloud::Pubsub::V1 | + # + # [PublisherClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/publisherclient + # [SubscriberClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/subscriberclient + # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/datatypes + # + module V1 + # @!attribute [rw] allowed_persistence_regions + # @return [Array] + # The list of GCP regions where messages that are published to the topic may + # be persisted in storage. Messages published by publishers running in + # non-allowed GCP regions (or running outside of GCP altogether) will be + # routed for storage in one of the allowed regions. An empty list indicates a + # misconfiguration at the project or organization level, which will result in + # all Publish operations failing. + class MessageStoragePolicy; end + + # A topic resource. + # @!attribute [rw] name + # @return [String] + # The name of the topic. It must have the format + # +"projects/{project}/topics/{topic}"+. +{topic}+ must start with a letter, + # and contain only letters (+[A-Za-z]+), numbers (+[0-9]+), dashes (+-+), + # underscores (+_+), periods (+.+), tildes (+~+), plus (+++) or percent + # signs (+%+). It must be between 3 and 255 characters in length, and it + # must not start with +"goog"+. + # @!attribute [rw] labels + # @return [Hash{String => String}] + # User labels. + # @!attribute [rw] message_storage_policy + # @return [Google::Pubsub::V1::MessageStoragePolicy] + # Policy constraining how messages published to the topic may be stored. It + # is determined when the topic is created based on the policy configured at + # the project level. It must not be set by the caller in the request to + # CreateTopic or to UpdateTopic. This field will be populated in the + # responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the + # response, then no constraints are in effect. + class Topic; end + + # A message data and its attributes. The message payload must not be empty; + # it must contain either a non-empty data field, or at least one attribute. + # @!attribute [rw] data + # @return [String] + # The message payload. + # @!attribute [rw] attributes + # @return [Hash{String => String}] + # Optional attributes for this message. + # @!attribute [rw] message_id + # @return [String] + # ID of this message, assigned by the server when the message is published. + # Guaranteed to be unique within the topic. This value may be read by a + # subscriber that receives a +PubsubMessage+ via a +Pull+ call or a push + # delivery. It must not be populated by the publisher in a +Publish+ call. + # @!attribute [rw] publish_time + # @return [Google::Protobuf::Timestamp] + # The time at which the message was published, populated by the server when + # it receives the +Publish+ call. It must not be populated by the + # publisher in a +Publish+ call. + class PubsubMessage; end + + # Request for the GetTopic method. + # @!attribute [rw] topic + # @return [String] + # The name of the topic to get. + # Format is +projects/{project}/topics/{topic}+. + class GetTopicRequest; end + + # Request for the UpdateTopic method. + # @!attribute [rw] topic + # @return [Google::Pubsub::V1::Topic] + # The updated topic object. + # @!attribute [rw] update_mask + # @return [Google::Protobuf::FieldMask] + # Indicates which fields in the provided topic to update. Must be specified + # and non-empty. Note that if +update_mask+ contains + # "message_storage_policy" then the new value will be determined based on the + # policy configured at the project or organization level. The + # +message_storage_policy+ must not be set in the +topic+ provided above. + class UpdateTopicRequest; end + + # Request for the Publish method. + # @!attribute [rw] topic + # @return [String] + # The messages in the request will be published on this topic. + # Format is +projects/{project}/topics/{topic}+. + # @!attribute [rw] messages + # @return [Array] + # The messages to publish. + class PublishRequest; end + + # Response for the +Publish+ method. + # @!attribute [rw] message_ids + # @return [Array] + # The server-assigned ID of each published message, in the same order as + # the messages in the request. IDs are guaranteed to be unique within + # the topic. + class PublishResponse; end + + # Request for the +ListTopics+ method. + # @!attribute [rw] project + # @return [String] + # The name of the cloud project that topics belong to. + # Format is +projects/{project}+. + # @!attribute [rw] page_size + # @return [Integer] + # Maximum number of topics to return. + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last +ListTopicsResponse+; indicates that this is + # a continuation of a prior +ListTopics+ call, and that the system should + # return the next page of data. + class ListTopicsRequest; end + + # Response for the +ListTopics+ method. + # @!attribute [rw] topics + # @return [Array] + # The resulting topics. + # @!attribute [rw] next_page_token + # @return [String] + # If not empty, indicates that there may be more topics that match the + # request; this value should be passed in a new +ListTopicsRequest+. + class ListTopicsResponse; end + + # Request for the +ListTopicSubscriptions+ method. + # @!attribute [rw] topic + # @return [String] + # The name of the topic that subscriptions are attached to. + # Format is +projects/{project}/topics/{topic}+. + # @!attribute [rw] page_size + # @return [Integer] + # Maximum number of subscription names to return. + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last +ListTopicSubscriptionsResponse+; indicates + # that this is a continuation of a prior +ListTopicSubscriptions+ call, and + # that the system should return the next page of data. + class ListTopicSubscriptionsRequest; end + + # Response for the +ListTopicSubscriptions+ method. + # @!attribute [rw] subscriptions + # @return [Array] + # The names of the subscriptions that match the request. + # @!attribute [rw] next_page_token + # @return [String] + # If not empty, indicates that there may be more subscriptions that match + # the request; this value should be passed in a new + # +ListTopicSubscriptionsRequest+ to get more subscriptions. + class ListTopicSubscriptionsResponse; end + + # Request for the +ListTopicSnapshots+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] topic + # @return [String] + # The name of the topic that snapshots are attached to. + # Format is +projects/{project}/topics/{topic}+. + # @!attribute [rw] page_size + # @return [Integer] + # Maximum number of snapshot names to return. + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last +ListTopicSnapshotsResponse+; indicates + # that this is a continuation of a prior +ListTopicSnapshots+ call, and + # that the system should return the next page of data. + class ListTopicSnapshotsRequest; end + + # Response for the +ListTopicSnapshots+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] snapshots + # @return [Array] + # The names of the snapshots that match the request. + # @!attribute [rw] next_page_token + # @return [String] + # If not empty, indicates that there may be more snapshots that match + # the request; this value should be passed in a new + # +ListTopicSnapshotsRequest+ to get more snapshots. + class ListTopicSnapshotsResponse; end + + # Request for the +DeleteTopic+ method. + # @!attribute [rw] topic + # @return [String] + # Name of the topic to delete. + # Format is +projects/{project}/topics/{topic}+. + class DeleteTopicRequest; end + + # A subscription resource. + # @!attribute [rw] name + # @return [String] + # The name of the subscription. It must have the format + # +"projects/{project}/subscriptions/{subscription}"+. +{subscription}+ must + # start with a letter, and contain only letters (+[A-Za-z]+), numbers + # (+[0-9]+), dashes (+-+), underscores (+_+), periods (+.+), tildes (+~+), + # plus (+++) or percent signs (+%+). It must be between 3 and 255 characters + # in length, and it must not start with +"goog"+ + # @!attribute [rw] topic + # @return [String] + # The name of the topic from which this subscription is receiving messages. + # Format is +projects/{project}/topics/{topic}+. + # The value of this field will be +_deleted-topic_+ if the topic has been + # deleted. + # @!attribute [rw] push_config + # @return [Google::Pubsub::V1::PushConfig] + # If push delivery is used with this subscription, this field is + # used to configure it. An empty +pushConfig+ signifies that the subscriber + # will pull and ack messages using API methods. + # @!attribute [rw] ack_deadline_seconds + # @return [Integer] + # This value is the maximum time after a subscriber receives a message + # before the subscriber should acknowledge the message. After message + # delivery but before the ack deadline expires and before the message is + # acknowledged, it is an outstanding message and will not be delivered + # again during that time (on a best-effort basis). + # + # For pull subscriptions, this value is used as the initial value for the ack + # deadline. To override this value for a given message, call + # +ModifyAckDeadline+ with the corresponding +ack_id+ if using + # non-streaming pull or send the +ack_id+ in a + # +StreamingModifyAckDeadlineRequest+ if using streaming pull. + # The minimum custom deadline you can specify is 10 seconds. + # The maximum custom deadline you can specify is 600 seconds (10 minutes). + # If this parameter is 0, a default value of 10 seconds is used. + # + # For push delivery, this value is also used to set the request timeout for + # the call to the push endpoint. + # + # If the subscriber never acknowledges the message, the Pub/Sub + # system will eventually redeliver the message. + # @!attribute [rw] retain_acked_messages + # @return [true, false] + # Indicates whether to retain acknowledged messages. If true, then + # messages are not expunged from the subscription's backlog, even if they are + # acknowledged, until they fall out of the +message_retention_duration+ + # window.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] message_retention_duration + # @return [Google::Protobuf::Duration] + # How long to retain unacknowledged messages in the subscription's backlog, + # from the moment a message is published. + # If +retain_acked_messages+ is true, then this also configures the retention + # of acknowledged messages, and thus configures how far back in time a +Seek+ + # can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 + # minutes.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] labels + # @return [Hash{String => String}] + # User labels. + class Subscription; end + + # Configuration for a push delivery endpoint. + # @!attribute [rw] push_endpoint + # @return [String] + # A URL locating the endpoint to which messages should be pushed. + # For example, a Webhook endpoint might use "https://example.com/push". + # @!attribute [rw] attributes + # @return [Hash{String => String}] + # Endpoint configuration attributes. + # + # Every endpoint has a set of API supported attributes that can be used to + # control different aspects of the message delivery. + # + # The currently supported attribute is +x-goog-version+, which you can + # use to change the format of the pushed message. This attribute + # indicates the version of the data expected by the endpoint. This + # controls the shape of the pushed message (i.e., its fields and metadata). + # The endpoint version is based on the version of the Pub/Sub API. + # + # If not present during the +CreateSubscription+ call, it will default to + # the version of the API used to make such call. If not present during a + # +ModifyPushConfig+ call, its value will not be changed. +GetSubscription+ + # calls will always return a valid version, even if the subscription was + # created without this attribute. + # + # The possible values for this attribute are: + # + # * +v1beta1+: uses the push format defined in the v1beta1 Pub/Sub API. + # * +v1+ or +v1beta2+: uses the push format defined in the v1 Pub/Sub API. + class PushConfig; end + + # A message and its corresponding acknowledgment ID. + # @!attribute [rw] ack_id + # @return [String] + # This ID can be used to acknowledge the received message. + # @!attribute [rw] message + # @return [Google::Pubsub::V1::PubsubMessage] + # The message. + class ReceivedMessage; end + + # Request for the GetSubscription method. + # @!attribute [rw] subscription + # @return [String] + # The name of the subscription to get. + # Format is +projects/{project}/subscriptions/{sub}+. + class GetSubscriptionRequest; end + + # Request for the UpdateSubscription method. + # @!attribute [rw] subscription + # @return [Google::Pubsub::V1::Subscription] + # The updated subscription object. + # @!attribute [rw] update_mask + # @return [Google::Protobuf::FieldMask] + # Indicates which fields in the provided subscription to update. + # Must be specified and non-empty. + class UpdateSubscriptionRequest; end + + # Request for the +ListSubscriptions+ method. + # @!attribute [rw] project + # @return [String] + # The name of the cloud project that subscriptions belong to. + # Format is +projects/{project}+. + # @!attribute [rw] page_size + # @return [Integer] + # Maximum number of subscriptions to return. + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last +ListSubscriptionsResponse+; indicates that + # this is a continuation of a prior +ListSubscriptions+ call, and that the + # system should return the next page of data. + class ListSubscriptionsRequest; end + + # Response for the +ListSubscriptions+ method. + # @!attribute [rw] subscriptions + # @return [Array] + # The subscriptions that match the request. + # @!attribute [rw] next_page_token + # @return [String] + # If not empty, indicates that there may be more subscriptions that match + # the request; this value should be passed in a new + # +ListSubscriptionsRequest+ to get more subscriptions. + class ListSubscriptionsResponse; end + + # Request for the DeleteSubscription method. + # @!attribute [rw] subscription + # @return [String] + # The subscription to delete. + # Format is +projects/{project}/subscriptions/{sub}+. + class DeleteSubscriptionRequest; end + + # Request for the ModifyPushConfig method. + # @!attribute [rw] subscription + # @return [String] + # The name of the subscription. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] push_config + # @return [Google::Pubsub::V1::PushConfig] + # The push configuration for future deliveries. + # + # An empty +pushConfig+ indicates that the Pub/Sub system should + # stop pushing messages from the given subscription and allow + # messages to be pulled and acknowledged - effectively pausing + # the subscription if +Pull+ or +StreamingPull+ is not called. + class ModifyPushConfigRequest; end + + # Request for the +Pull+ method. + # @!attribute [rw] subscription + # @return [String] + # The subscription from which messages should be pulled. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] return_immediately + # @return [true, false] + # If this field set to true, the system will respond immediately even if + # it there are no messages available to return in the +Pull+ response. + # Otherwise, the system may wait (for a bounded amount of time) until at + # least one message is available, rather than returning no messages. The + # client may cancel the request if it does not wish to wait any longer for + # the response. + # @!attribute [rw] max_messages + # @return [Integer] + # The maximum number of messages returned for this request. The Pub/Sub + # system may return fewer than the number specified. + class PullRequest; end + + # Response for the +Pull+ method. + # @!attribute [rw] received_messages + # @return [Array] + # Received Pub/Sub messages. The Pub/Sub system will return zero messages if + # there are no more available in the backlog. The Pub/Sub system may return + # fewer than the +maxMessages+ requested even if there are more messages + # available in the backlog. + class PullResponse; end + + # Request for the ModifyAckDeadline method. + # @!attribute [rw] subscription + # @return [String] + # The name of the subscription. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] ack_ids + # @return [Array] + # List of acknowledgment IDs. + # @!attribute [rw] ack_deadline_seconds + # @return [Integer] + # The new ack deadline with respect to the time this request was sent to + # the Pub/Sub system. For example, if the value is 10, the new + # ack deadline will expire 10 seconds after the +ModifyAckDeadline+ call + # was made. Specifying zero may immediately make the message available for + # another pull request. + # The minimum deadline you can specify is 0 seconds. + # The maximum deadline you can specify is 600 seconds (10 minutes). + class ModifyAckDeadlineRequest; end + + # Request for the Acknowledge method. + # @!attribute [rw] subscription + # @return [String] + # The subscription whose message is being acknowledged. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] ack_ids + # @return [Array] + # The acknowledgment ID for the messages being acknowledged that was returned + # by the Pub/Sub system in the +Pull+ response. Must not be empty. + class AcknowledgeRequest; end + + # Request for the +StreamingPull+ streaming RPC method. This request is used to + # establish the initial stream as well as to stream acknowledgements and ack + # deadline modifications from the client to the server. + # @!attribute [rw] subscription + # @return [String] + # The subscription for which to initialize the new stream. This must be + # provided in the first request on the stream, and must not be set in + # subsequent requests from client to server. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] ack_ids + # @return [Array] + # List of acknowledgement IDs for acknowledging previously received messages + # (received on this stream or a different stream). If an ack ID has expired, + # the corresponding message may be redelivered later. Acknowledging a message + # more than once will not result in an error. If the acknowledgement ID is + # malformed, the stream will be aborted with status +INVALID_ARGUMENT+. + # @!attribute [rw] modify_deadline_seconds + # @return [Array] + # The list of new ack deadlines for the IDs listed in + # +modify_deadline_ack_ids+. The size of this list must be the same as the + # size of +modify_deadline_ack_ids+. If it differs the stream will be aborted + # with +INVALID_ARGUMENT+. Each element in this list is applied to the + # element in the same position in +modify_deadline_ack_ids+. The new ack + # deadline is with respect to the time this request was sent to the Pub/Sub + # system. Must be >= 0. For example, if the value is 10, the new ack deadline + # will expire 10 seconds after this request is received. If the value is 0, + # the message is immediately made available for another streaming or + # non-streaming pull request. If the value is < 0 (an error), the stream will + # be aborted with status +INVALID_ARGUMENT+. + # @!attribute [rw] modify_deadline_ack_ids + # @return [Array] + # List of acknowledgement IDs whose deadline will be modified based on the + # corresponding element in +modify_deadline_seconds+. This field can be used + # to indicate that more time is needed to process a message by the + # subscriber, or to make the message available for redelivery if the + # processing was interrupted. + # @!attribute [rw] stream_ack_deadline_seconds + # @return [Integer] + # The ack deadline to use for the stream. This must be provided in the + # first request on the stream, but it can also be updated on subsequent + # requests from client to server. The minimum deadline you can specify is 10 + # seconds. The maximum deadline you can specify is 600 seconds (10 minutes). + class StreamingPullRequest; end + + # Response for the +StreamingPull+ method. This response is used to stream + # messages from the server to the client. + # @!attribute [rw] received_messages + # @return [Array] + # Received Pub/Sub messages. This will not be empty. + class StreamingPullResponse; end + + # Request for the +CreateSnapshot+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be changed in + # backward-incompatible ways and is not recommended for production use. + # It is not subject to any SLA or deprecation policy. + # @!attribute [rw] name + # @return [String] + # Optional user-provided name for this snapshot. + # If the name is not provided in the request, the server will assign a random + # name for this snapshot on the same project as the subscription. + # Note that for REST API requests, you must specify a name. + # Format is +projects/{project}/snapshots/{snap}+. + # @!attribute [rw] subscription + # @return [String] + # The subscription whose backlog the snapshot retains. + # Specifically, the created snapshot is guaranteed to retain: + # (a) The existing backlog on the subscription. More precisely, this is + # defined as the messages in the subscription's backlog that are + # unacknowledged upon the successful completion of the + # +CreateSnapshot+ request; as well as: + # (b) Any messages published to the subscription's topic following the + # successful completion of the CreateSnapshot request. + # Format is +projects/{project}/subscriptions/{sub}+. + # @!attribute [rw] labels + # @return [Hash{String => String}] + # User labels. + class CreateSnapshotRequest; end + + # Request for the UpdateSnapshot method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] snapshot + # @return [Google::Pubsub::V1::Snapshot] + # The updated snapshot object. + # @!attribute [rw] update_mask + # @return [Google::Protobuf::FieldMask] + # Indicates which fields in the provided snapshot to update. + # Must be specified and non-empty. + class UpdateSnapshotRequest; end + + # A snapshot resource.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] name + # @return [String] + # The name of the snapshot. + # @!attribute [rw] topic + # @return [String] + # The name of the topic from which this snapshot is retaining messages. + # @!attribute [rw] expire_time + # @return [Google::Protobuf::Timestamp] + # The snapshot is guaranteed to exist up until this time. + # A newly-created snapshot expires no later than 7 days from the time of its + # creation. Its exact lifetime is determined at creation by the existing + # backlog in the source subscription. Specifically, the lifetime of the + # snapshot is +7 days - (age of oldest unacked message in the subscription)+. + # For example, consider a subscription whose oldest unacked message is 3 days + # old. If a snapshot is created from this subscription, the snapshot -- which + # will always capture this 3-day-old backlog as long as the snapshot + # exists -- will expire in 4 days. The service will refuse to create a + # snapshot that would expire in less than 1 hour after creation. + # @!attribute [rw] labels + # @return [Hash{String => String}] + # User labels. + class Snapshot; end + + # Request for the GetSnapshot method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] snapshot + # @return [String] + # The name of the snapshot to get. + # Format is +projects/{project}/snapshots/{snap}+. + class GetSnapshotRequest; end + + # Request for the +ListSnapshots+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] project + # @return [String] + # The name of the cloud project that snapshots belong to. + # Format is +projects/{project}+. + # @!attribute [rw] page_size + # @return [Integer] + # Maximum number of snapshots to return. + # @!attribute [rw] page_token + # @return [String] + # The value returned by the last +ListSnapshotsResponse+; indicates that this + # is a continuation of a prior +ListSnapshots+ call, and that the system + # should return the next page of data. + class ListSnapshotsRequest; end + + # Response for the +ListSnapshots+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] snapshots + # @return [Array] + # The resulting snapshots. + # @!attribute [rw] next_page_token + # @return [String] + # If not empty, indicates that there may be more snapshot that match the + # request; this value should be passed in a new +ListSnapshotsRequest+. + class ListSnapshotsResponse; end + + # Request for the +DeleteSnapshot+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] snapshot + # @return [String] + # The name of the snapshot to delete. + # Format is +projects/{project}/snapshots/{snap}+. + class DeleteSnapshotRequest; end + + # Request for the +Seek+ method.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @!attribute [rw] subscription + # @return [String] + # The subscription to affect. + # @!attribute [rw] time + # @return [Google::Protobuf::Timestamp] + # The time to seek to. + # Messages retained in the subscription that were published before this + # time are marked as acknowledged, and messages retained in the + # subscription that were published after this time are marked as + # unacknowledged. Note that this operation affects only those messages + # retained in the subscription (configured by the combination of + # +message_retention_duration+ and +retain_acked_messages+). For example, + # if +time+ corresponds to a point before the message retention + # window (or to a point before the system's notion of the subscription + # creation time), only retained messages will be marked as unacknowledged, + # and already-expunged messages will not be restored. + # @!attribute [rw] snapshot + # @return [String] + # The snapshot to seek to. The snapshot's topic must be the same as that of + # the provided subscription. + # Format is +projects/{project}/snapshots/{snap}+. + class SeekRequest; end + + class SeekResponse; end + end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/overview.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/overview.rb new file mode 100644 index 000000000..05a643bfa --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/doc/overview.rb @@ -0,0 +1,102 @@ +# Copyright 2018 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 +# +# https://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. + +module Google + module Cloud + # rubocop:disable LineLength + + ## + # # Ruby Client for Google Cloud Pub/Sub API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning)) + # + # [Google Cloud Pub/Sub API][Product Documentation]: + # Provides reliable, many-to-many, asynchronous messaging between + # applications. + # - [Product Documentation][] + # + # ## Quick Start + # In order to use this library, you first need to go through the following + # steps: + # + # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) + # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project) + # 3. [Enable the Google Cloud Pub/Sub API.](https://console.cloud.google.com/apis/api/pubsub) + # 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication) + # + # ### Installation + # ``` + # $ gem install google-cloud-pubsub + # ``` + # + # ### Preview + # #### PublisherClient + # ```rb + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new + # formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path(project_id) + # + # # Iterate over all results. + # publisher_client.list_topics(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # publisher_client.list_topics(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + # ``` + # + # ### Next Steps + # - Read the [Google Cloud Pub/Sub API Product documentation][Product Documentation] + # to learn more about the product and see How-to Guides. + # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md) + # to see the full list of Cloud APIs that we cover. + # + # [Product Documentation]: https://cloud.google.com/pubsub + # + # ## Enabling Logging + # + # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. + # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, + # or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) + # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) + # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information. + # + # Configuring a Ruby stdlib logger: + # + # ```ruby + # require "logger" + # + # module MyLogger + # LOGGER = Logger.new $stderr, level: Logger::WARN + # def logger + # LOGGER + # end + # end + # + # # Define a gRPC module-level logger method before grpc/logconfig.rb loads. + # module GRPC + # extend MyLogger + # end + # ``` + # + module Pubsub + module V1 + end + end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client.rb new file mode 100644 index 000000000..222aa6705 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client.rb @@ -0,0 +1,732 @@ +# Copyright 2018 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 +# +# https://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. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/googleapis/googleapis/blob/master/google/pubsub/v1/pubsub.proto, +# and updates to that file get reflected here through a refresh process. +# For the short term, the refresh process will only be runnable by Google +# engineers. + +require "json" +require "pathname" + +require "google/gax" + +require "google/iam/v1/iam_policy_pb" +require "google/pubsub/v1/pubsub_pb" +require "google/cloud/pubsub/v1/credentials" + +module Google + module Cloud + module Pubsub + module V1 + # The service that an application uses to manipulate topics, and to send + # messages to a topic. + # + # @!attribute [r] iam_policy_stub + # @return [Google::Iam::V1::IAMPolicy::Stub] + # @!attribute [r] publisher_stub + # @return [Google::Pubsub::V1::Publisher::Stub] + class PublisherClient + attr_reader :iam_policy_stub, :publisher_stub + + # The default address of the service. + SERVICE_ADDRESS = "pubsub.googleapis.com".freeze + + # The default port of the service. + DEFAULT_SERVICE_PORT = 443 + + # The default set of gRPC interceptors. + GRPC_INTERCEPTORS = [] + + DEFAULT_TIMEOUT = 30 + + PAGE_DESCRIPTORS = { + "list_topics" => Google::Gax::PageDescriptor.new( + "page_token", + "next_page_token", + "topics"), + "list_topic_subscriptions" => Google::Gax::PageDescriptor.new( + "page_token", + "next_page_token", + "subscriptions") + }.freeze + + private_constant :PAGE_DESCRIPTORS + + BUNDLE_DESCRIPTORS = { + "publish" => Google::Gax::BundleDescriptor.new( + "messages", + [ + "topic" + ], + subresponse_field: "message_ids") + }.freeze + + private_constant :BUNDLE_DESCRIPTORS + + # The scopes needed to make gRPC calls to all of the methods defined in + # this service. + ALL_SCOPES = [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/pubsub" + ].freeze + + + TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}/topics/{topic}" + ) + + private_constant :TOPIC_PATH_TEMPLATE + + PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}" + ) + + private_constant :PROJECT_PATH_TEMPLATE + + # Returns a fully-qualified topic resource name string. + # @param project [String] + # @param topic [String] + # @return [String] + def self.topic_path project, topic + TOPIC_PATH_TEMPLATE.render( + :"project" => project, + :"topic" => topic + ) + end + + # Returns a fully-qualified project resource name string. + # @param project [String] + # @return [String] + def self.project_path project + PROJECT_PATH_TEMPLATE.render( + :"project" => project + ) + end + + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def initialize \ + credentials: nil, + scopes: ALL_SCOPES, + client_config: {}, + timeout: DEFAULT_TIMEOUT, + metadata: nil, + exception_transformer: nil, + lib_name: nil, + lib_version: "" + # These require statements are intentionally placed here to initialize + # the gRPC module only when it's required. + # See https://github.com/googleapis/toolkit/issues/446 + require "google/gax/grpc" + require "google/iam/v1/iam_policy_services_pb" + require "google/pubsub/v1/pubsub_services_pb" + + credentials ||= Google::Cloud::Pubsub::V1::Credentials.default + + if credentials.is_a?(String) || credentials.is_a?(Hash) + updater_proc = Google::Cloud::Pubsub::V1::Credentials.new(credentials).updater_proc + end + if credentials.is_a?(GRPC::Core::Channel) + channel = credentials + end + if credentials.is_a?(GRPC::Core::ChannelCredentials) + chan_creds = credentials + end + if credentials.is_a?(Proc) + updater_proc = credentials + end + if credentials.is_a?(Google::Auth::Credentials) + updater_proc = credentials.updater_proc + end + + package_version = Gem.loaded_specs['google-cloud-pubsub'].version.version + + google_api_client = "gl-ruby/#{RUBY_VERSION}" + google_api_client << " #{lib_name}/#{lib_version}" if lib_name + google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}" + google_api_client << " grpc/#{GRPC::VERSION}" + google_api_client.freeze + + headers = { :"x-goog-api-client" => google_api_client } + headers.merge!(metadata) unless metadata.nil? + client_config_file = Pathname.new(__dir__).join( + "publisher_client_config.json" + ) + defaults = client_config_file.open do |f| + Google::Gax.construct_settings( + "google.pubsub.v1.Publisher", + JSON.parse(f.read), + client_config, + Google::Gax::Grpc::STATUS_CODE_NAMES, + timeout, + bundle_descriptors: BUNDLE_DESCRIPTORS, + page_descriptors: PAGE_DESCRIPTORS, + errors: Google::Gax::Grpc::API_ERRORS, + metadata: headers + ) + end + + # Allow overriding the service path/port in subclasses. + service_path = self.class::SERVICE_ADDRESS + port = self.class::DEFAULT_SERVICE_PORT + interceptors = self.class::GRPC_INTERCEPTORS + @iam_policy_stub = Google::Gax::Grpc.create_stub( + service_path, + port, + chan_creds: chan_creds, + channel: channel, + updater_proc: updater_proc, + scopes: scopes, + interceptors: interceptors, + &Google::Iam::V1::IAMPolicy::Stub.method(:new) + ) + @publisher_stub = Google::Gax::Grpc.create_stub( + service_path, + port, + chan_creds: chan_creds, + channel: channel, + updater_proc: updater_proc, + scopes: scopes, + interceptors: interceptors, + &Google::Pubsub::V1::Publisher::Stub.method(:new) + ) + + @create_topic = Google::Gax.create_api_call( + @publisher_stub.method(:create_topic), + defaults["create_topic"], + exception_transformer: exception_transformer + ) + @update_topic = Google::Gax.create_api_call( + @publisher_stub.method(:update_topic), + defaults["update_topic"], + exception_transformer: exception_transformer + ) + @publish = Google::Gax.create_api_call( + @publisher_stub.method(:publish), + defaults["publish"], + exception_transformer: exception_transformer + ) + @get_topic = Google::Gax.create_api_call( + @publisher_stub.method(:get_topic), + defaults["get_topic"], + exception_transformer: exception_transformer + ) + @list_topics = Google::Gax.create_api_call( + @publisher_stub.method(:list_topics), + defaults["list_topics"], + exception_transformer: exception_transformer + ) + @list_topic_subscriptions = Google::Gax.create_api_call( + @publisher_stub.method(:list_topic_subscriptions), + defaults["list_topic_subscriptions"], + exception_transformer: exception_transformer + ) + @delete_topic = Google::Gax.create_api_call( + @publisher_stub.method(:delete_topic), + defaults["delete_topic"], + exception_transformer: exception_transformer + ) + @set_iam_policy = Google::Gax.create_api_call( + @iam_policy_stub.method(:set_iam_policy), + defaults["set_iam_policy"], + exception_transformer: exception_transformer + ) + @get_iam_policy = Google::Gax.create_api_call( + @iam_policy_stub.method(:get_iam_policy), + defaults["get_iam_policy"], + exception_transformer: exception_transformer + ) + @test_iam_permissions = Google::Gax.create_api_call( + @iam_policy_stub.method(:test_iam_permissions), + defaults["test_iam_permissions"], + exception_transformer: exception_transformer + ) + end + + # Service calls + + # Creates the given topic with the given name. See the + # resource name rules. + # + # @param name [String] + # The name of the topic. It must have the format + # +"projects/{project}/topics/{topic}"+. +{topic}+ must start with a letter, + # and contain only letters (+[A-Za-z]+), numbers (+[0-9]+), dashes (+-+), + # underscores (+_+), periods (+.+), tildes (+~+), plus (+++) or percent + # signs (+%+). It must be between 3 and 255 characters in length, and it + # must not start with +"goog"+. + # @param labels [Hash{String => String}] + # User labels. + # @param message_storage_policy [Google::Pubsub::V1::MessageStoragePolicy | Hash] + # Policy constraining how messages published to the topic may be stored. It + # is determined when the topic is created based on the policy configured at + # the project level. It must not be set by the caller in the request to + # CreateTopic or to UpdateTopic. This field will be populated in the + # responses for GetTopic, CreateTopic, and UpdateTopic: if not present in the + # response, then no constraints are in effect. + # A hash of the same form as `Google::Pubsub::V1::MessageStoragePolicy` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Topic] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Topic] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_name = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # response = publisher_client.create_topic(formatted_name) + + def create_topic \ + name, + labels: nil, + message_storage_policy: nil, + options: nil, + &block + req = { + name: name, + labels: labels, + message_storage_policy: message_storage_policy + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::Topic) + @create_topic.call(req, options, &block) + end + + # Updates an existing topic. Note that certain properties of a + # topic are not modifiable. + # + # @param topic [Google::Pubsub::V1::Topic | Hash] + # The updated topic object. + # A hash of the same form as `Google::Pubsub::V1::Topic` + # can also be provided. + # @param update_mask [Google::Protobuf::FieldMask | Hash] + # Indicates which fields in the provided topic to update. Must be specified + # and non-empty. Note that if +update_mask+ contains + # "message_storage_policy" then the new value will be determined based on the + # policy configured at the project or organization level. The + # +message_storage_policy+ must not be set in the +topic+ provided above. + # A hash of the same form as `Google::Protobuf::FieldMask` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Topic] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Topic] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # + # # TODO: Initialize +topic+: + # topic = {} + # + # # TODO: Initialize +update_mask+: + # update_mask = {} + # response = publisher_client.update_topic(topic, update_mask) + + def update_topic \ + topic, + update_mask, + options: nil, + &block + req = { + topic: topic, + update_mask: update_mask + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::UpdateTopicRequest) + @update_topic.call(req, options, &block) + end + + # Adds one or more messages to the topic. Returns +NOT_FOUND+ if the topic + # does not exist. The message payload must not be empty; it must contain + # either a non-empty data field, or at least one attribute. + # + # @param topic [String] + # The messages in the request will be published on this topic. + # Format is +projects/{project}/topics/{topic}+. + # @param messages [Array] + # The messages to publish. + # A hash of the same form as `Google::Pubsub::V1::PubsubMessage` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::PublishResponse] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::PublishResponse] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # data = '' + # messages_element = { data: data } + # messages = [messages_element] + # response = publisher_client.publish(formatted_topic, messages) + + def publish \ + topic, + messages, + options: nil, + &block + req = { + topic: topic, + messages: messages + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::PublishRequest) + @publish.call(req, options, &block) + end + + # Gets the configuration of a topic. + # + # @param topic [String] + # The name of the topic to get. + # Format is +projects/{project}/topics/{topic}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Topic] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Topic] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # response = publisher_client.get_topic(formatted_topic) + + def get_topic \ + topic, + options: nil, + &block + req = { + topic: topic + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::GetTopicRequest) + @get_topic.call(req, options, &block) + end + + # Lists matching topics. + # + # @param project [String] + # The name of the cloud project that topics belong to. + # Format is +projects/{project}+. + # @param page_size [Integer] + # The maximum number of resources contained in the underlying API + # response. If page streaming is performed per-resource, this + # parameter does not affect the return value. If page streaming is + # performed per-page, this determines the maximum number of + # resources in a page. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Gax::PagedEnumerable] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Gax::PagedEnumerable] + # An enumerable of Google::Pubsub::V1::Topic instances. + # See Google::Gax::PagedEnumerable documentation for other + # operations such as per-page iteration or access to the response + # object. + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path("[PROJECT]") + # + # # Iterate over all results. + # publisher_client.list_topics(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # publisher_client.list_topics(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + + def list_topics \ + project, + page_size: nil, + options: nil, + &block + req = { + project: project, + page_size: page_size + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListTopicsRequest) + @list_topics.call(req, options, &block) + end + + # Lists the names of the subscriptions on this topic. + # + # @param topic [String] + # The name of the topic that subscriptions are attached to. + # Format is +projects/{project}/topics/{topic}+. + # @param page_size [Integer] + # The maximum number of resources contained in the underlying API + # response. If page streaming is performed per-resource, this + # parameter does not affect the return value. If page streaming is + # performed per-page, this determines the maximum number of + # resources in a page. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Gax::PagedEnumerable] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Gax::PagedEnumerable] + # An enumerable of String instances. + # See Google::Gax::PagedEnumerable documentation for other + # operations such as per-page iteration or access to the response + # object. + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # + # # Iterate over all results. + # publisher_client.list_topic_subscriptions(formatted_topic).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # publisher_client.list_topic_subscriptions(formatted_topic).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + + def list_topic_subscriptions \ + topic, + page_size: nil, + options: nil, + &block + req = { + topic: topic, + page_size: page_size + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListTopicSubscriptionsRequest) + @list_topic_subscriptions.call(req, options, &block) + end + + # Deletes the topic with the given name. Returns +NOT_FOUND+ if the topic + # does not exist. After a topic is deleted, a new topic may be created with + # the same name; this is an entirely new topic with none of the old + # configuration or subscriptions. Existing subscriptions to this topic are + # not deleted, but their +topic+ field is set to +_deleted-topic_+. + # + # @param topic [String] + # Name of the topic to delete. + # Format is +projects/{project}/topics/{topic}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # publisher_client.delete_topic(formatted_topic) + + def delete_topic \ + topic, + options: nil, + &block + req = { + topic: topic + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::DeleteTopicRequest) + @delete_topic.call(req, options, &block) + nil + end + + # Sets the access control policy on the specified resource. Replaces any + # existing policy. + # + # @param resource [String] + # REQUIRED: The resource for which the policy is being specified. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param policy [Google::Iam::V1::Policy | Hash] + # REQUIRED: The complete policy to be applied to the +resource+. The size of + # the policy is limited to a few 10s of KB. An empty policy is a + # valid policy but certain Cloud Platform services (such as Projects) + # might reject them. + # A hash of the same form as `Google::Iam::V1::Policy` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::Policy] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::Policy] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # + # # TODO: Initialize +policy+: + # policy = {} + # response = publisher_client.set_iam_policy(formatted_resource, policy) + + def set_iam_policy \ + resource, + policy, + options: nil, + &block + req = { + resource: resource, + policy: policy + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest) + @set_iam_policy.call(req, options, &block) + end + + # Gets the access control policy for a resource. + # Returns an empty policy if the resource exists and does not have a policy + # set. + # + # @param resource [String] + # REQUIRED: The resource for which the policy is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::Policy] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::Policy] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # response = publisher_client.get_iam_policy(formatted_resource) + + def get_iam_policy \ + resource, + options: nil, + &block + req = { + resource: resource + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest) + @get_iam_policy.call(req, options, &block) + end + + # Returns permissions that a caller has on the specified resource. + # If the resource does not exist, this will return an empty set of + # permissions, not a NOT_FOUND error. + # + # @param resource [String] + # REQUIRED: The resource for which the policy detail is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param permissions [Array] + # The set of permissions to check for the +resource+. Permissions with + # wildcards (such as '*' or 'storage.*') are not allowed. For more + # information see + # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::TestIamPermissionsResponse] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # publisher_client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + # + # # TODO: Initialize +permissions+: + # permissions = [] + # response = publisher_client.test_iam_permissions(formatted_resource, permissions) + + def test_iam_permissions \ + resource, + permissions, + options: nil, + &block + req = { + resource: resource, + permissions: permissions + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest) + @test_iam_permissions.call(req, options, &block) + end + end + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client_config.json b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client_config.json new file mode 100644 index 000000000..72dec325a --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/publisher_client_config.json @@ -0,0 +1,101 @@ +{ + "interfaces": { + "google.pubsub.v1.Publisher": { + "retry_codes": { + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "one_plus_delivery": [ + "ABORTED", + "CANCELLED", + "DEADLINE_EXCEEDED", + "INTERNAL", + "RESOURCE_EXHAUSTED", + "UNAVAILABLE", + "UNKNOWN" + ], + "non_idempotent": [] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "messaging": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 12000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 30000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "UpdateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "Publish": { + "timeout_millis": 60000, + "retry_codes_name": "one_plus_delivery", + "retry_params_name": "messaging", + "bundling": { + "element_count_threshold": 10, + "element_count_limit": 1000, + "request_byte_threshold": 1024, + "request_byte_limit": 10485760, + "delay_threshold_millis": 10 + } + }, + "GetTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListTopics": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListTopicSubscriptions": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "DeleteTopic": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "SetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "GetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "TestIamPermissions": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client.rb b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client.rb new file mode 100644 index 000000000..887050cf7 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client.rb @@ -0,0 +1,1265 @@ +# Copyright 2018 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 +# +# https://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. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/googleapis/googleapis/blob/master/google/pubsub/v1/pubsub.proto, +# and updates to that file get reflected here through a refresh process. +# For the short term, the refresh process will only be runnable by Google +# engineers. + +require "json" +require "pathname" + +require "google/gax" + +require "google/iam/v1/iam_policy_pb" +require "google/pubsub/v1/pubsub_pb" +require "google/cloud/pubsub/v1/credentials" + +module Google + module Cloud + module Pubsub + module V1 + # The service that an application uses to manipulate subscriptions and to + # consume messages from a subscription via the +Pull+ method or by + # establishing a bi-directional stream using the +StreamingPull+ method. + # + # @!attribute [r] iam_policy_stub + # @return [Google::Iam::V1::IAMPolicy::Stub] + # @!attribute [r] subscriber_stub + # @return [Google::Pubsub::V1::Subscriber::Stub] + class SubscriberClient + attr_reader :iam_policy_stub, :subscriber_stub + + # The default address of the service. + SERVICE_ADDRESS = "pubsub.googleapis.com".freeze + + # The default port of the service. + DEFAULT_SERVICE_PORT = 443 + + # The default set of gRPC interceptors. + GRPC_INTERCEPTORS = [] + + DEFAULT_TIMEOUT = 30 + + PAGE_DESCRIPTORS = { + "list_subscriptions" => Google::Gax::PageDescriptor.new( + "page_token", + "next_page_token", + "subscriptions"), + "list_snapshots" => Google::Gax::PageDescriptor.new( + "page_token", + "next_page_token", + "snapshots") + }.freeze + + private_constant :PAGE_DESCRIPTORS + + # The scopes needed to make gRPC calls to all of the methods defined in + # this service. + ALL_SCOPES = [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/pubsub" + ].freeze + + + SUBSCRIPTION_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}/subscriptions/{subscription}" + ) + + private_constant :SUBSCRIPTION_PATH_TEMPLATE + + TOPIC_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}/topics/{topic}" + ) + + private_constant :TOPIC_PATH_TEMPLATE + + PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}" + ) + + private_constant :PROJECT_PATH_TEMPLATE + + SNAPSHOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new( + "projects/{project}/snapshots/{snapshot}" + ) + + private_constant :SNAPSHOT_PATH_TEMPLATE + + # Returns a fully-qualified subscription resource name string. + # @param project [String] + # @param subscription [String] + # @return [String] + def self.subscription_path project, subscription + SUBSCRIPTION_PATH_TEMPLATE.render( + :"project" => project, + :"subscription" => subscription + ) + end + + # Returns a fully-qualified topic resource name string. + # @param project [String] + # @param topic [String] + # @return [String] + def self.topic_path project, topic + TOPIC_PATH_TEMPLATE.render( + :"project" => project, + :"topic" => topic + ) + end + + # Returns a fully-qualified project resource name string. + # @param project [String] + # @return [String] + def self.project_path project + PROJECT_PATH_TEMPLATE.render( + :"project" => project + ) + end + + # Returns a fully-qualified snapshot resource name string. + # @param project [String] + # @param snapshot [String] + # @return [String] + def self.snapshot_path project, snapshot + SNAPSHOT_PATH_TEMPLATE.render( + :"project" => project, + :"snapshot" => snapshot + ) + end + + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] + # Provides the means for authenticating requests made by the client. This parameter can + # be many types. + # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for + # authenticating requests made by this client. + # A `String` will be treated as the path to the keyfile to be used for the construction of + # credentials for this client. + # A `Hash` will be treated as the contents of a keyfile to be used for the construction of + # credentials for this client. + # A `GRPC::Core::Channel` will be used to make calls through. + # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials + # should already be composed with a `GRPC::Core::CallCredentials` object. + # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the + # metadata for requests, generally, to give OAuth credentials. + # @param scopes [Array] + # The OAuth scopes for this service. This parameter is ignored if + # an updater_proc is supplied. + # @param client_config [Hash] + # A Hash for call options for each method. See + # Google::Gax#construct_settings for the structure of + # this data. Falls back to the default config if not specified + # or the specified config is missing data points. + # @param timeout [Numeric] + # The default timeout, in seconds, for calls made through this client. + # @param metadata [Hash] + # Default metadata to be sent with each request. This can be overridden on a per call basis. + # @param exception_transformer [Proc] + # An optional proc that intercepts any exceptions raised during an API call to inject + # custom error handling. + def initialize \ + credentials: nil, + scopes: ALL_SCOPES, + client_config: {}, + timeout: DEFAULT_TIMEOUT, + metadata: nil, + exception_transformer: nil, + lib_name: nil, + lib_version: "" + # These require statements are intentionally placed here to initialize + # the gRPC module only when it's required. + # See https://github.com/googleapis/toolkit/issues/446 + require "google/gax/grpc" + require "google/iam/v1/iam_policy_services_pb" + require "google/pubsub/v1/pubsub_services_pb" + + credentials ||= Google::Cloud::Pubsub::V1::Credentials.default + + if credentials.is_a?(String) || credentials.is_a?(Hash) + updater_proc = Google::Cloud::Pubsub::V1::Credentials.new(credentials).updater_proc + end + if credentials.is_a?(GRPC::Core::Channel) + channel = credentials + end + if credentials.is_a?(GRPC::Core::ChannelCredentials) + chan_creds = credentials + end + if credentials.is_a?(Proc) + updater_proc = credentials + end + if credentials.is_a?(Google::Auth::Credentials) + updater_proc = credentials.updater_proc + end + + package_version = Gem.loaded_specs['google-cloud-pubsub'].version.version + + google_api_client = "gl-ruby/#{RUBY_VERSION}" + google_api_client << " #{lib_name}/#{lib_version}" if lib_name + google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}" + google_api_client << " grpc/#{GRPC::VERSION}" + google_api_client.freeze + + headers = { :"x-goog-api-client" => google_api_client } + headers.merge!(metadata) unless metadata.nil? + client_config_file = Pathname.new(__dir__).join( + "subscriber_client_config.json" + ) + defaults = client_config_file.open do |f| + Google::Gax.construct_settings( + "google.pubsub.v1.Subscriber", + JSON.parse(f.read), + client_config, + Google::Gax::Grpc::STATUS_CODE_NAMES, + timeout, + page_descriptors: PAGE_DESCRIPTORS, + errors: Google::Gax::Grpc::API_ERRORS, + metadata: headers + ) + end + + # Allow overriding the service path/port in subclasses. + service_path = self.class::SERVICE_ADDRESS + port = self.class::DEFAULT_SERVICE_PORT + interceptors = self.class::GRPC_INTERCEPTORS + @iam_policy_stub = Google::Gax::Grpc.create_stub( + service_path, + port, + chan_creds: chan_creds, + channel: channel, + updater_proc: updater_proc, + scopes: scopes, + interceptors: interceptors, + &Google::Iam::V1::IAMPolicy::Stub.method(:new) + ) + @subscriber_stub = Google::Gax::Grpc.create_stub( + service_path, + port, + chan_creds: chan_creds, + channel: channel, + updater_proc: updater_proc, + scopes: scopes, + interceptors: interceptors, + &Google::Pubsub::V1::Subscriber::Stub.method(:new) + ) + + @create_subscription = Google::Gax.create_api_call( + @subscriber_stub.method(:create_subscription), + defaults["create_subscription"], + exception_transformer: exception_transformer + ) + @get_subscription = Google::Gax.create_api_call( + @subscriber_stub.method(:get_subscription), + defaults["get_subscription"], + exception_transformer: exception_transformer + ) + @update_subscription = Google::Gax.create_api_call( + @subscriber_stub.method(:update_subscription), + defaults["update_subscription"], + exception_transformer: exception_transformer + ) + @list_subscriptions = Google::Gax.create_api_call( + @subscriber_stub.method(:list_subscriptions), + defaults["list_subscriptions"], + exception_transformer: exception_transformer + ) + @delete_subscription = Google::Gax.create_api_call( + @subscriber_stub.method(:delete_subscription), + defaults["delete_subscription"], + exception_transformer: exception_transformer + ) + @modify_ack_deadline = Google::Gax.create_api_call( + @subscriber_stub.method(:modify_ack_deadline), + defaults["modify_ack_deadline"], + exception_transformer: exception_transformer + ) + @acknowledge = Google::Gax.create_api_call( + @subscriber_stub.method(:acknowledge), + defaults["acknowledge"], + exception_transformer: exception_transformer + ) + @pull = Google::Gax.create_api_call( + @subscriber_stub.method(:pull), + defaults["pull"], + exception_transformer: exception_transformer + ) + @streaming_pull = Google::Gax.create_api_call( + @subscriber_stub.method(:streaming_pull), + defaults["streaming_pull"], + exception_transformer: exception_transformer + ) + @modify_push_config = Google::Gax.create_api_call( + @subscriber_stub.method(:modify_push_config), + defaults["modify_push_config"], + exception_transformer: exception_transformer + ) + @list_snapshots = Google::Gax.create_api_call( + @subscriber_stub.method(:list_snapshots), + defaults["list_snapshots"], + exception_transformer: exception_transformer + ) + @create_snapshot = Google::Gax.create_api_call( + @subscriber_stub.method(:create_snapshot), + defaults["create_snapshot"], + exception_transformer: exception_transformer + ) + @update_snapshot = Google::Gax.create_api_call( + @subscriber_stub.method(:update_snapshot), + defaults["update_snapshot"], + exception_transformer: exception_transformer + ) + @delete_snapshot = Google::Gax.create_api_call( + @subscriber_stub.method(:delete_snapshot), + defaults["delete_snapshot"], + exception_transformer: exception_transformer + ) + @seek = Google::Gax.create_api_call( + @subscriber_stub.method(:seek), + defaults["seek"], + exception_transformer: exception_transformer + ) + @set_iam_policy = Google::Gax.create_api_call( + @iam_policy_stub.method(:set_iam_policy), + defaults["set_iam_policy"], + exception_transformer: exception_transformer + ) + @get_iam_policy = Google::Gax.create_api_call( + @iam_policy_stub.method(:get_iam_policy), + defaults["get_iam_policy"], + exception_transformer: exception_transformer + ) + @test_iam_permissions = Google::Gax.create_api_call( + @iam_policy_stub.method(:test_iam_permissions), + defaults["test_iam_permissions"], + exception_transformer: exception_transformer + ) + end + + # Service calls + + # Creates a subscription to a given topic. See the + # resource name rules. + # If the subscription already exists, returns +ALREADY_EXISTS+. + # If the corresponding topic doesn't exist, returns +NOT_FOUND+. + # + # If the name is not provided in the request, the server will assign a random + # name for this subscription on the same project as the topic, conforming + # to the + # [resource name format](https://cloud.google.com/pubsub/docs/overview#names). + # The generated name is populated in the returned Subscription object. + # Note that for REST API requests, you must specify a name in the request. + # + # @param name [String] + # The name of the subscription. It must have the format + # +"projects/{project}/subscriptions/{subscription}"+. +{subscription}+ must + # start with a letter, and contain only letters (+[A-Za-z]+), numbers + # (+[0-9]+), dashes (+-+), underscores (+_+), periods (+.+), tildes (+~+), + # plus (+++) or percent signs (+%+). It must be between 3 and 255 characters + # in length, and it must not start with +"goog"+ + # @param topic [String] + # The name of the topic from which this subscription is receiving messages. + # Format is +projects/{project}/topics/{topic}+. + # The value of this field will be +_deleted-topic_+ if the topic has been + # deleted. + # @param push_config [Google::Pubsub::V1::PushConfig | Hash] + # If push delivery is used with this subscription, this field is + # used to configure it. An empty +pushConfig+ signifies that the subscriber + # will pull and ack messages using API methods. + # A hash of the same form as `Google::Pubsub::V1::PushConfig` + # can also be provided. + # @param ack_deadline_seconds [Integer] + # This value is the maximum time after a subscriber receives a message + # before the subscriber should acknowledge the message. After message + # delivery but before the ack deadline expires and before the message is + # acknowledged, it is an outstanding message and will not be delivered + # again during that time (on a best-effort basis). + # + # For pull subscriptions, this value is used as the initial value for the ack + # deadline. To override this value for a given message, call + # +ModifyAckDeadline+ with the corresponding +ack_id+ if using + # non-streaming pull or send the +ack_id+ in a + # +StreamingModifyAckDeadlineRequest+ if using streaming pull. + # The minimum custom deadline you can specify is 10 seconds. + # The maximum custom deadline you can specify is 600 seconds (10 minutes). + # If this parameter is 0, a default value of 10 seconds is used. + # + # For push delivery, this value is also used to set the request timeout for + # the call to the push endpoint. + # + # If the subscriber never acknowledges the message, the Pub/Sub + # system will eventually redeliver the message. + # @param retain_acked_messages [true, false] + # Indicates whether to retain acknowledged messages. If true, then + # messages are not expunged from the subscription's backlog, even if they are + # acknowledged, until they fall out of the +message_retention_duration+ + # window.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # @param message_retention_duration [Google::Protobuf::Duration | Hash] + # How long to retain unacknowledged messages in the subscription's backlog, + # from the moment a message is published. + # If +retain_acked_messages+ is true, then this also configures the retention + # of acknowledged messages, and thus configures how far back in time a +Seek+ + # can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 + # minutes.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # A hash of the same form as `Google::Protobuf::Duration` + # can also be provided. + # @param labels [Hash{String => String}] + # User labels. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Subscription] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Subscription] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # formatted_topic = Google::Cloud::Pubsub::V1::SubscriberClient.topic_path("[PROJECT]", "[TOPIC]") + # response = subscriber_client.create_subscription(formatted_name, formatted_topic) + + def create_subscription \ + name, + topic, + push_config: nil, + ack_deadline_seconds: nil, + retain_acked_messages: nil, + message_retention_duration: nil, + labels: nil, + options: nil, + &block + req = { + name: name, + topic: topic, + push_config: push_config, + ack_deadline_seconds: ack_deadline_seconds, + retain_acked_messages: retain_acked_messages, + message_retention_duration: message_retention_duration, + labels: labels + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::Subscription) + @create_subscription.call(req, options, &block) + end + + # Gets the configuration details of a subscription. + # + # @param subscription [String] + # The name of the subscription to get. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Subscription] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Subscription] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # response = subscriber_client.get_subscription(formatted_subscription) + + def get_subscription \ + subscription, + options: nil, + &block + req = { + subscription: subscription + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::GetSubscriptionRequest) + @get_subscription.call(req, options, &block) + end + + # Updates an existing subscription. Note that certain properties of a + # subscription, such as its topic, are not modifiable. + # + # @param subscription [Google::Pubsub::V1::Subscription | Hash] + # The updated subscription object. + # A hash of the same form as `Google::Pubsub::V1::Subscription` + # can also be provided. + # @param update_mask [Google::Protobuf::FieldMask | Hash] + # Indicates which fields in the provided subscription to update. + # Must be specified and non-empty. + # A hash of the same form as `Google::Protobuf::FieldMask` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Subscription] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Subscription] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # ack_deadline_seconds = 42 + # subscription = { ack_deadline_seconds: ack_deadline_seconds } + # paths_element = "ack_deadline_seconds" + # paths = [paths_element] + # update_mask = { paths: paths } + # response = subscriber_client.update_subscription(subscription, update_mask) + + def update_subscription \ + subscription, + update_mask, + options: nil, + &block + req = { + subscription: subscription, + update_mask: update_mask + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::UpdateSubscriptionRequest) + @update_subscription.call(req, options, &block) + end + + # Lists matching subscriptions. + # + # @param project [String] + # The name of the cloud project that subscriptions belong to. + # Format is +projects/{project}+. + # @param page_size [Integer] + # The maximum number of resources contained in the underlying API + # response. If page streaming is performed per-resource, this + # parameter does not affect the return value. If page streaming is + # performed per-page, this determines the maximum number of + # resources in a page. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Gax::PagedEnumerable] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Gax::PagedEnumerable] + # An enumerable of Google::Pubsub::V1::Subscription instances. + # See Google::Gax::PagedEnumerable documentation for other + # operations such as per-page iteration or access to the response + # object. + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + # + # # Iterate over all results. + # subscriber_client.list_subscriptions(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # subscriber_client.list_subscriptions(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + + def list_subscriptions \ + project, + page_size: nil, + options: nil, + &block + req = { + project: project, + page_size: page_size + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListSubscriptionsRequest) + @list_subscriptions.call(req, options, &block) + end + + # Deletes an existing subscription. All messages retained in the subscription + # are immediately dropped. Calls to +Pull+ after deletion will return + # +NOT_FOUND+. After a subscription is deleted, a new one may be created with + # the same name, but the new one has no association with the old + # subscription or its topic unless the same topic is specified. + # + # @param subscription [String] + # The subscription to delete. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # subscriber_client.delete_subscription(formatted_subscription) + + def delete_subscription \ + subscription, + options: nil, + &block + req = { + subscription: subscription + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::DeleteSubscriptionRequest) + @delete_subscription.call(req, options, &block) + nil + end + + # Modifies the ack deadline for a specific message. This method is useful + # to indicate that more time is needed to process a message by the + # subscriber, or to make the message available for redelivery if the + # processing was interrupted. Note that this does not modify the + # subscription-level +ackDeadlineSeconds+ used for subsequent messages. + # + # @param subscription [String] + # The name of the subscription. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param ack_ids [Array] + # List of acknowledgment IDs. + # @param ack_deadline_seconds [Integer] + # The new ack deadline with respect to the time this request was sent to + # the Pub/Sub system. For example, if the value is 10, the new + # ack deadline will expire 10 seconds after the +ModifyAckDeadline+ call + # was made. Specifying zero may immediately make the message available for + # another pull request. + # The minimum deadline you can specify is 0 seconds. + # The maximum deadline you can specify is 600 seconds (10 minutes). + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +ack_ids+: + # ack_ids = [] + # + # # TODO: Initialize +ack_deadline_seconds+: + # ack_deadline_seconds = 0 + # subscriber_client.modify_ack_deadline(formatted_subscription, ack_ids, ack_deadline_seconds) + + def modify_ack_deadline \ + subscription, + ack_ids, + ack_deadline_seconds, + options: nil, + &block + req = { + subscription: subscription, + ack_ids: ack_ids, + ack_deadline_seconds: ack_deadline_seconds + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ModifyAckDeadlineRequest) + @modify_ack_deadline.call(req, options, &block) + nil + end + + # Acknowledges the messages associated with the +ack_ids+ in the + # +AcknowledgeRequest+. The Pub/Sub system can remove the relevant messages + # from the subscription. + # + # Acknowledging a message whose ack deadline has expired may succeed, + # but such a message may be redelivered later. Acknowledging a message more + # than once will not result in an error. + # + # @param subscription [String] + # The subscription whose message is being acknowledged. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param ack_ids [Array] + # The acknowledgment ID for the messages being acknowledged that was returned + # by the Pub/Sub system in the +Pull+ response. Must not be empty. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +ack_ids+: + # ack_ids = [] + # subscriber_client.acknowledge(formatted_subscription, ack_ids) + + def acknowledge \ + subscription, + ack_ids, + options: nil, + &block + req = { + subscription: subscription, + ack_ids: ack_ids + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::AcknowledgeRequest) + @acknowledge.call(req, options, &block) + nil + end + + # Pulls messages from the server. Returns an empty list if there are no + # messages available in the backlog. The server may return +UNAVAILABLE+ if + # there are too many concurrent pull requests pending for the given + # subscription. + # + # @param subscription [String] + # The subscription from which messages should be pulled. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param max_messages [Integer] + # The maximum number of messages returned for this request. The Pub/Sub + # system may return fewer than the number specified. + # @param return_immediately [true, false] + # If this field set to true, the system will respond immediately even if + # it there are no messages available to return in the +Pull+ response. + # Otherwise, the system may wait (for a bounded amount of time) until at + # least one message is available, rather than returning no messages. The + # client may cancel the request if it does not wish to wait any longer for + # the response. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::PullResponse] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::PullResponse] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +max_messages+: + # max_messages = 0 + # response = subscriber_client.pull(formatted_subscription, max_messages) + + def pull \ + subscription, + max_messages, + return_immediately: nil, + options: nil, + &block + req = { + subscription: subscription, + max_messages: max_messages, + return_immediately: return_immediately + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::PullRequest) + @pull.call(req, options, &block) + end + + # Establishes a stream with the server, which sends messages down to the + # client. The client streams acknowledgements and ack deadline modifications + # back to the server. The server will close the stream and return the status + # on any error. The server may close the stream with status +UNAVAILABLE+ to + # reassign server-side resources, in which case, the client should + # re-establish the stream. Flow control can be achieved by configuring the + # underlying RPC channel. + # + # @param reqs [Enumerable] + # The input requests. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @return [Enumerable] + # An enumerable of Google::Pubsub::V1::StreamingPullResponse instances. + # + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # + # @note + # EXPERIMENTAL: + # Streaming requests are still undergoing review. + # This method interface might change in the future. + # + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +stream_ack_deadline_seconds+: + # stream_ack_deadline_seconds = 0 + # request = { subscription: formatted_subscription, stream_ack_deadline_seconds: stream_ack_deadline_seconds } + # requests = [request] + # subscriber_client.streaming_pull(requests).each do |element| + # # Process element. + # end + + def streaming_pull reqs, options: nil + request_protos = reqs.lazy.map do |req| + Google::Gax::to_proto(req, Google::Pubsub::V1::StreamingPullRequest) + end + @streaming_pull.call(request_protos, options) + end + + # Modifies the +PushConfig+ for a specified subscription. + # + # This may be used to change a push subscription to a pull one (signified by + # an empty +PushConfig+) or vice versa, or change the endpoint URL and other + # attributes of a push subscription. Messages will accumulate for delivery + # continuously through the call regardless of changes to the +PushConfig+. + # + # @param subscription [String] + # The name of the subscription. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param push_config [Google::Pubsub::V1::PushConfig | Hash] + # The push configuration for future deliveries. + # + # An empty +pushConfig+ indicates that the Pub/Sub system should + # stop pushing messages from the given subscription and allow + # messages to be pulled and acknowledged - effectively pausing + # the subscription if +Pull+ or +StreamingPull+ is not called. + # A hash of the same form as `Google::Pubsub::V1::PushConfig` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +push_config+: + # push_config = {} + # subscriber_client.modify_push_config(formatted_subscription, push_config) + + def modify_push_config \ + subscription, + push_config, + options: nil, + &block + req = { + subscription: subscription, + push_config: push_config + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ModifyPushConfigRequest) + @modify_push_config.call(req, options, &block) + nil + end + + # Lists the existing snapshots.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # + # @param project [String] + # The name of the cloud project that snapshots belong to. + # Format is +projects/{project}+. + # @param page_size [Integer] + # The maximum number of resources contained in the underlying API + # response. If page streaming is performed per-resource, this + # parameter does not affect the return value. If page streaming is + # performed per-page, this determines the maximum number of + # resources in a page. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Gax::PagedEnumerable] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Gax::PagedEnumerable] + # An enumerable of Google::Pubsub::V1::Snapshot instances. + # See Google::Gax::PagedEnumerable documentation for other + # operations such as per-page iteration or access to the response + # object. + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + # + # # Iterate over all results. + # subscriber_client.list_snapshots(formatted_project).each do |element| + # # Process element. + # end + # + # # Or iterate over results one page at a time. + # subscriber_client.list_snapshots(formatted_project).each_page do |page| + # # Process each page at a time. + # page.each do |element| + # # Process element. + # end + # end + + def list_snapshots \ + project, + page_size: nil, + options: nil, + &block + req = { + project: project, + page_size: page_size + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::ListSnapshotsRequest) + @list_snapshots.call(req, options, &block) + end + + # Creates a snapshot from the requested subscription.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # If the snapshot already exists, returns +ALREADY_EXISTS+. + # If the requested subscription doesn't exist, returns +NOT_FOUND+. + # If the backlog in the subscription is too old -- and the resulting snapshot + # would expire in less than 1 hour -- then +FAILED_PRECONDITION+ is returned. + # See also the +Snapshot.expire_time+ field. If the name is not provided in + # the request, the server will assign a random + # name for this snapshot on the same project as the subscription, conforming + # to the [resource name format](https://cloud.google.com/pubsub/docs/overview#names). + # The generated + # name is populated in the returned Snapshot object. Note that for REST API + # requests, you must specify a name in the request. + # + # @param name [String] + # Optional user-provided name for this snapshot. + # If the name is not provided in the request, the server will assign a random + # name for this snapshot on the same project as the subscription. + # Note that for REST API requests, you must specify a name. + # Format is +projects/{project}/snapshots/{snap}+. + # @param subscription [String] + # The subscription whose backlog the snapshot retains. + # Specifically, the created snapshot is guaranteed to retain: + # (a) The existing backlog on the subscription. More precisely, this is + # defined as the messages in the subscription's backlog that are + # unacknowledged upon the successful completion of the + # +CreateSnapshot+ request; as well as: + # (b) Any messages published to the subscription's topic following the + # successful completion of the CreateSnapshot request. + # Format is +projects/{project}/subscriptions/{sub}+. + # @param labels [Hash{String => String}] + # User labels. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Snapshot] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Snapshot] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # response = subscriber_client.create_snapshot(formatted_name, formatted_subscription) + + def create_snapshot \ + name, + subscription, + labels: nil, + options: nil, + &block + req = { + name: name, + subscription: subscription, + labels: labels + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::CreateSnapshotRequest) + @create_snapshot.call(req, options, &block) + end + + # Updates an existing snapshot.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # Note that certain properties of a snapshot are not modifiable. + # + # @param snapshot [Google::Pubsub::V1::Snapshot | Hash] + # The updated snapshot object. + # A hash of the same form as `Google::Pubsub::V1::Snapshot` + # can also be provided. + # @param update_mask [Google::Protobuf::FieldMask | Hash] + # Indicates which fields in the provided snapshot to update. + # Must be specified and non-empty. + # A hash of the same form as `Google::Protobuf::FieldMask` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::Snapshot] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::Snapshot] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # seconds = 123456 + # expire_time = { seconds: seconds } + # snapshot = { expire_time: expire_time } + # paths_element = "expire_time" + # paths = [paths_element] + # update_mask = { paths: paths } + # response = subscriber_client.update_snapshot(snapshot, update_mask) + + def update_snapshot \ + snapshot, + update_mask, + options: nil, + &block + req = { + snapshot: snapshot, + update_mask: update_mask + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::UpdateSnapshotRequest) + @update_snapshot.call(req, options, &block) + end + + # Removes an existing snapshot.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # When the snapshot is deleted, all messages retained in the snapshot + # are immediately dropped. After a snapshot is deleted, a new one may be + # created with the same name, but the new one has no association with the old + # snapshot or its subscription, unless the same subscription is specified. + # + # @param snapshot [String] + # The name of the snapshot to delete. + # Format is +projects/{project}/snapshots/{snap}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_snapshot = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + # subscriber_client.delete_snapshot(formatted_snapshot) + + def delete_snapshot \ + snapshot, + options: nil, + &block + req = { + snapshot: snapshot + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::DeleteSnapshotRequest) + @delete_snapshot.call(req, options, &block) + nil + end + + # Seeks an existing subscription to a point in time or to a given snapshot, + # whichever is provided in the request.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # + # @param subscription [String] + # The subscription to affect. + # @param time [Google::Protobuf::Timestamp | Hash] + # The time to seek to. + # Messages retained in the subscription that were published before this + # time are marked as acknowledged, and messages retained in the + # subscription that were published after this time are marked as + # unacknowledged. Note that this operation affects only those messages + # retained in the subscription (configured by the combination of + # +message_retention_duration+ and +retain_acked_messages+). For example, + # if +time+ corresponds to a point before the message retention + # window (or to a point before the system's notion of the subscription + # creation time), only retained messages will be marked as unacknowledged, + # and already-expunged messages will not be restored. + # A hash of the same form as `Google::Protobuf::Timestamp` + # can also be provided. + # @param snapshot [String] + # The snapshot to seek to. The snapshot's topic must be the same as that of + # the provided subscription. + # Format is +projects/{project}/snapshots/{snap}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Pubsub::V1::SeekResponse] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Pubsub::V1::SeekResponse] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # response = subscriber_client.seek(formatted_subscription) + + def seek \ + subscription, + time: nil, + snapshot: nil, + options: nil, + &block + req = { + subscription: subscription, + time: time, + snapshot: snapshot + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Pubsub::V1::SeekRequest) + @seek.call(req, options, &block) + end + + # Sets the access control policy on the specified resource. Replaces any + # existing policy. + # + # @param resource [String] + # REQUIRED: The resource for which the policy is being specified. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param policy [Google::Iam::V1::Policy | Hash] + # REQUIRED: The complete policy to be applied to the +resource+. The size of + # the policy is limited to a few 10s of KB. An empty policy is a + # valid policy but certain Cloud Platform services (such as Projects) + # might reject them. + # A hash of the same form as `Google::Iam::V1::Policy` + # can also be provided. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::Policy] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::Policy] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +policy+: + # policy = {} + # response = subscriber_client.set_iam_policy(formatted_resource, policy) + + def set_iam_policy \ + resource, + policy, + options: nil, + &block + req = { + resource: resource, + policy: policy + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest) + @set_iam_policy.call(req, options, &block) + end + + # Gets the access control policy for a resource. + # Returns an empty policy if the resource exists and does not have a policy + # set. + # + # @param resource [String] + # REQUIRED: The resource for which the policy is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::Policy] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::Policy] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # response = subscriber_client.get_iam_policy(formatted_resource) + + def get_iam_policy \ + resource, + options: nil, + &block + req = { + resource: resource + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest) + @get_iam_policy.call(req, options, &block) + end + + # Returns permissions that a caller has on the specified resource. + # If the resource does not exist, this will return an empty set of + # permissions, not a NOT_FOUND error. + # + # @param resource [String] + # REQUIRED: The resource for which the policy detail is being requested. + # +resource+ is usually specified as a path. For example, a Project + # resource is specified as +projects/{project}+. + # @param permissions [Array] + # The set of permissions to check for the +resource+. Permissions with + # wildcards (such as '*' or 'storage.*') are not allowed. For more + # information see + # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + # @param options [Google::Gax::CallOptions] + # Overrides the default settings for this call, e.g, timeout, + # retries, etc. + # @yield [result, operation] Access the result along with the RPC operation + # @yieldparam result [Google::Iam::V1::TestIamPermissionsResponse] + # @yieldparam operation [GRPC::ActiveCall::Operation] + # @return [Google::Iam::V1::TestIamPermissionsResponse] + # @raise [Google::Gax::GaxError] if the RPC is aborted. + # @example + # require "google/cloud/pubsub" + # + # subscriber_client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + # formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + # + # # TODO: Initialize +permissions+: + # permissions = [] + # response = subscriber_client.test_iam_permissions(formatted_resource, permissions) + + def test_iam_permissions \ + resource, + permissions, + options: nil, + &block + req = { + resource: resource, + permissions: permissions + }.delete_if { |_, v| v.nil? } + req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest) + @test_iam_permissions.call(req, options, &block) + end + end + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client_config.json b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client_config.json new file mode 100644 index 000000000..0d793ba4f --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/cloud/pubsub/v1/subscriber_client_config.json @@ -0,0 +1,141 @@ +{ + "interfaces": { + "google.pubsub.v1.Subscriber": { + "retry_codes": { + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "non_idempotent": [], + "pull": [ + "CANCELLED", + "DEADLINE_EXCEEDED", + "INTERNAL", + "RESOURCE_EXHAUSTED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "messaging": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 12000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 12000, + "total_timeout_millis": 600000 + }, + "streaming_messaging": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 600000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 600000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "UpdateSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListSubscriptions": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "DeleteSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ModifyAckDeadline": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "Acknowledge": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "messaging" + }, + "Pull": { + "timeout_millis": 60000, + "retry_codes_name": "pull", + "retry_params_name": "messaging" + }, + "StreamingPull": { + "timeout_millis": 900000, + "retry_codes_name": "pull", + "retry_params_name": "streaming_messaging" + }, + "ModifyPushConfig": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListSnapshots": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "CreateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "UpdateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "DeleteSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "Seek": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "SetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "GetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "TestIamPermissions": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_pb.rb b/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_pb.rb new file mode 100644 index 000000000..08e02a101 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_pb.rb @@ -0,0 +1,221 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/pubsub/v1/pubsub.proto + +require 'google/protobuf' + +require 'google/api/annotations_pb' +require 'google/protobuf/duration_pb' +require 'google/protobuf/empty_pb' +require 'google/protobuf/field_mask_pb' +require 'google/protobuf/timestamp_pb' +Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "google.pubsub.v1.MessageStoragePolicy" do + repeated :allowed_persistence_regions, :string, 1 + end + add_message "google.pubsub.v1.Topic" do + optional :name, :string, 1 + map :labels, :string, :string, 2 + optional :message_storage_policy, :message, 3, "google.pubsub.v1.MessageStoragePolicy" + end + add_message "google.pubsub.v1.PubsubMessage" do + optional :data, :bytes, 1 + map :attributes, :string, :string, 2 + optional :message_id, :string, 3 + optional :publish_time, :message, 4, "google.protobuf.Timestamp" + end + add_message "google.pubsub.v1.GetTopicRequest" do + optional :topic, :string, 1 + end + add_message "google.pubsub.v1.UpdateTopicRequest" do + optional :topic, :message, 1, "google.pubsub.v1.Topic" + optional :update_mask, :message, 2, "google.protobuf.FieldMask" + end + add_message "google.pubsub.v1.PublishRequest" do + optional :topic, :string, 1 + repeated :messages, :message, 2, "google.pubsub.v1.PubsubMessage" + end + add_message "google.pubsub.v1.PublishResponse" do + repeated :message_ids, :string, 1 + end + add_message "google.pubsub.v1.ListTopicsRequest" do + optional :project, :string, 1 + optional :page_size, :int32, 2 + optional :page_token, :string, 3 + end + add_message "google.pubsub.v1.ListTopicsResponse" do + repeated :topics, :message, 1, "google.pubsub.v1.Topic" + optional :next_page_token, :string, 2 + end + add_message "google.pubsub.v1.ListTopicSubscriptionsRequest" do + optional :topic, :string, 1 + optional :page_size, :int32, 2 + optional :page_token, :string, 3 + end + add_message "google.pubsub.v1.ListTopicSubscriptionsResponse" do + repeated :subscriptions, :string, 1 + optional :next_page_token, :string, 2 + end + add_message "google.pubsub.v1.ListTopicSnapshotsRequest" do + optional :topic, :string, 1 + optional :page_size, :int32, 2 + optional :page_token, :string, 3 + end + add_message "google.pubsub.v1.ListTopicSnapshotsResponse" do + repeated :snapshots, :string, 1 + optional :next_page_token, :string, 2 + end + add_message "google.pubsub.v1.DeleteTopicRequest" do + optional :topic, :string, 1 + end + add_message "google.pubsub.v1.Subscription" do + optional :name, :string, 1 + optional :topic, :string, 2 + optional :push_config, :message, 4, "google.pubsub.v1.PushConfig" + optional :ack_deadline_seconds, :int32, 5 + optional :retain_acked_messages, :bool, 7 + optional :message_retention_duration, :message, 8, "google.protobuf.Duration" + map :labels, :string, :string, 9 + end + add_message "google.pubsub.v1.PushConfig" do + optional :push_endpoint, :string, 1 + map :attributes, :string, :string, 2 + end + add_message "google.pubsub.v1.ReceivedMessage" do + optional :ack_id, :string, 1 + optional :message, :message, 2, "google.pubsub.v1.PubsubMessage" + end + add_message "google.pubsub.v1.GetSubscriptionRequest" do + optional :subscription, :string, 1 + end + add_message "google.pubsub.v1.UpdateSubscriptionRequest" do + optional :subscription, :message, 1, "google.pubsub.v1.Subscription" + optional :update_mask, :message, 2, "google.protobuf.FieldMask" + end + add_message "google.pubsub.v1.ListSubscriptionsRequest" do + optional :project, :string, 1 + optional :page_size, :int32, 2 + optional :page_token, :string, 3 + end + add_message "google.pubsub.v1.ListSubscriptionsResponse" do + repeated :subscriptions, :message, 1, "google.pubsub.v1.Subscription" + optional :next_page_token, :string, 2 + end + add_message "google.pubsub.v1.DeleteSubscriptionRequest" do + optional :subscription, :string, 1 + end + add_message "google.pubsub.v1.ModifyPushConfigRequest" do + optional :subscription, :string, 1 + optional :push_config, :message, 2, "google.pubsub.v1.PushConfig" + end + add_message "google.pubsub.v1.PullRequest" do + optional :subscription, :string, 1 + optional :return_immediately, :bool, 2 + optional :max_messages, :int32, 3 + end + add_message "google.pubsub.v1.PullResponse" do + repeated :received_messages, :message, 1, "google.pubsub.v1.ReceivedMessage" + end + add_message "google.pubsub.v1.ModifyAckDeadlineRequest" do + optional :subscription, :string, 1 + repeated :ack_ids, :string, 4 + optional :ack_deadline_seconds, :int32, 3 + end + add_message "google.pubsub.v1.AcknowledgeRequest" do + optional :subscription, :string, 1 + repeated :ack_ids, :string, 2 + end + add_message "google.pubsub.v1.StreamingPullRequest" do + optional :subscription, :string, 1 + repeated :ack_ids, :string, 2 + repeated :modify_deadline_seconds, :int32, 3 + repeated :modify_deadline_ack_ids, :string, 4 + optional :stream_ack_deadline_seconds, :int32, 5 + end + add_message "google.pubsub.v1.StreamingPullResponse" do + repeated :received_messages, :message, 1, "google.pubsub.v1.ReceivedMessage" + end + add_message "google.pubsub.v1.CreateSnapshotRequest" do + optional :name, :string, 1 + optional :subscription, :string, 2 + map :labels, :string, :string, 3 + end + add_message "google.pubsub.v1.UpdateSnapshotRequest" do + optional :snapshot, :message, 1, "google.pubsub.v1.Snapshot" + optional :update_mask, :message, 2, "google.protobuf.FieldMask" + end + add_message "google.pubsub.v1.Snapshot" do + optional :name, :string, 1 + optional :topic, :string, 2 + optional :expire_time, :message, 3, "google.protobuf.Timestamp" + map :labels, :string, :string, 4 + end + add_message "google.pubsub.v1.GetSnapshotRequest" do + optional :snapshot, :string, 1 + end + add_message "google.pubsub.v1.ListSnapshotsRequest" do + optional :project, :string, 1 + optional :page_size, :int32, 2 + optional :page_token, :string, 3 + end + add_message "google.pubsub.v1.ListSnapshotsResponse" do + repeated :snapshots, :message, 1, "google.pubsub.v1.Snapshot" + optional :next_page_token, :string, 2 + end + add_message "google.pubsub.v1.DeleteSnapshotRequest" do + optional :snapshot, :string, 1 + end + add_message "google.pubsub.v1.SeekRequest" do + optional :subscription, :string, 1 + oneof :target do + optional :time, :message, 2, "google.protobuf.Timestamp" + optional :snapshot, :string, 3 + end + end + add_message "google.pubsub.v1.SeekResponse" do + end +end + +module Google + module Pubsub + module V1 + MessageStoragePolicy = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.MessageStoragePolicy").msgclass + Topic = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.Topic").msgclass + PubsubMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PubsubMessage").msgclass + GetTopicRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.GetTopicRequest").msgclass + UpdateTopicRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.UpdateTopicRequest").msgclass + PublishRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PublishRequest").msgclass + PublishResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PublishResponse").msgclass + ListTopicsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicsRequest").msgclass + ListTopicsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicsResponse").msgclass + ListTopicSubscriptionsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicSubscriptionsRequest").msgclass + ListTopicSubscriptionsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicSubscriptionsResponse").msgclass + ListTopicSnapshotsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicSnapshotsRequest").msgclass + ListTopicSnapshotsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListTopicSnapshotsResponse").msgclass + DeleteTopicRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.DeleteTopicRequest").msgclass + Subscription = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.Subscription").msgclass + PushConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PushConfig").msgclass + ReceivedMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ReceivedMessage").msgclass + GetSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.GetSubscriptionRequest").msgclass + UpdateSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.UpdateSubscriptionRequest").msgclass + ListSubscriptionsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListSubscriptionsRequest").msgclass + ListSubscriptionsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListSubscriptionsResponse").msgclass + DeleteSubscriptionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.DeleteSubscriptionRequest").msgclass + ModifyPushConfigRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ModifyPushConfigRequest").msgclass + PullRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PullRequest").msgclass + PullResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.PullResponse").msgclass + ModifyAckDeadlineRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ModifyAckDeadlineRequest").msgclass + AcknowledgeRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.AcknowledgeRequest").msgclass + StreamingPullRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.StreamingPullRequest").msgclass + StreamingPullResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.StreamingPullResponse").msgclass + CreateSnapshotRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.CreateSnapshotRequest").msgclass + UpdateSnapshotRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.UpdateSnapshotRequest").msgclass + Snapshot = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.Snapshot").msgclass + GetSnapshotRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.GetSnapshotRequest").msgclass + ListSnapshotsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListSnapshotsRequest").msgclass + ListSnapshotsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.ListSnapshotsResponse").msgclass + DeleteSnapshotRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.DeleteSnapshotRequest").msgclass + SeekRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.SeekRequest").msgclass + SeekResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.pubsub.v1.SeekResponse").msgclass + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_services_pb.rb b/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_services_pb.rb new file mode 100644 index 000000000..90b4badf6 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/lib/google/pubsub/v1/pubsub_services_pb.rb @@ -0,0 +1,191 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# Source: google/pubsub/v1/pubsub.proto for package 'google.pubsub.v1' +# Original file comments: +# Copyright 2018 Google Inc. +# +# 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. +# + +require 'grpc' +require 'google/pubsub/v1/pubsub_pb' + +module Google + module Pubsub + module V1 + module Publisher + # The service that an application uses to manipulate topics, and to send + # messages to a topic. + class Service + + include GRPC::GenericService + + self.marshal_class_method = :encode + self.unmarshal_class_method = :decode + self.service_name = 'google.pubsub.v1.Publisher' + + # Creates the given topic with the given name. See the + # resource name rules. + rpc :CreateTopic, Topic, Topic + # Updates an existing topic. Note that certain properties of a + # topic are not modifiable. + rpc :UpdateTopic, UpdateTopicRequest, Topic + # Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic + # does not exist. The message payload must not be empty; it must contain + # either a non-empty data field, or at least one attribute. + rpc :Publish, PublishRequest, PublishResponse + # Gets the configuration of a topic. + rpc :GetTopic, GetTopicRequest, Topic + # Lists matching topics. + rpc :ListTopics, ListTopicsRequest, ListTopicsResponse + # Lists the names of the subscriptions on this topic. + rpc :ListTopicSubscriptions, ListTopicSubscriptionsRequest, ListTopicSubscriptionsResponse + # Lists the names of the snapshots on this topic.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + rpc :ListTopicSnapshots, ListTopicSnapshotsRequest, ListTopicSnapshotsResponse + # Deletes the topic with the given name. Returns `NOT_FOUND` if the topic + # does not exist. After a topic is deleted, a new topic may be created with + # the same name; this is an entirely new topic with none of the old + # configuration or subscriptions. Existing subscriptions to this topic are + # not deleted, but their `topic` field is set to `_deleted-topic_`. + rpc :DeleteTopic, DeleteTopicRequest, Google::Protobuf::Empty + end + + Stub = Service.rpc_stub_class + end + module Subscriber + # The service that an application uses to manipulate subscriptions and to + # consume messages from a subscription via the `Pull` method or by + # establishing a bi-directional stream using the `StreamingPull` method. + class Service + + include GRPC::GenericService + + self.marshal_class_method = :encode + self.unmarshal_class_method = :decode + self.service_name = 'google.pubsub.v1.Subscriber' + + # Creates a subscription to a given topic. See the + # resource name rules. + # If the subscription already exists, returns `ALREADY_EXISTS`. + # If the corresponding topic doesn't exist, returns `NOT_FOUND`. + # + # If the name is not provided in the request, the server will assign a random + # name for this subscription on the same project as the topic, conforming + # to the + # [resource name format](https://cloud.google.com/pubsub/docs/overview#names). + # The generated name is populated in the returned Subscription object. + # Note that for REST API requests, you must specify a name in the request. + rpc :CreateSubscription, Subscription, Subscription + # Gets the configuration details of a subscription. + rpc :GetSubscription, GetSubscriptionRequest, Subscription + # Updates an existing subscription. Note that certain properties of a + # subscription, such as its topic, are not modifiable. + rpc :UpdateSubscription, UpdateSubscriptionRequest, Subscription + # Lists matching subscriptions. + rpc :ListSubscriptions, ListSubscriptionsRequest, ListSubscriptionsResponse + # Deletes an existing subscription. All messages retained in the subscription + # are immediately dropped. Calls to `Pull` after deletion will return + # `NOT_FOUND`. After a subscription is deleted, a new one may be created with + # the same name, but the new one has no association with the old + # subscription or its topic unless the same topic is specified. + rpc :DeleteSubscription, DeleteSubscriptionRequest, Google::Protobuf::Empty + # Modifies the ack deadline for a specific message. This method is useful + # to indicate that more time is needed to process a message by the + # subscriber, or to make the message available for redelivery if the + # processing was interrupted. Note that this does not modify the + # subscription-level `ackDeadlineSeconds` used for subsequent messages. + rpc :ModifyAckDeadline, ModifyAckDeadlineRequest, Google::Protobuf::Empty + # Acknowledges the messages associated with the `ack_ids` in the + # `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages + # from the subscription. + # + # Acknowledging a message whose ack deadline has expired may succeed, + # but such a message may be redelivered later. Acknowledging a message more + # than once will not result in an error. + rpc :Acknowledge, AcknowledgeRequest, Google::Protobuf::Empty + # Pulls messages from the server. Returns an empty list if there are no + # messages available in the backlog. The server may return `UNAVAILABLE` if + # there are too many concurrent pull requests pending for the given + # subscription. + rpc :Pull, PullRequest, PullResponse + # Establishes a stream with the server, which sends messages down to the + # client. The client streams acknowledgements and ack deadline modifications + # back to the server. The server will close the stream and return the status + # on any error. The server may close the stream with status `UNAVAILABLE` to + # reassign server-side resources, in which case, the client should + # re-establish the stream. Flow control can be achieved by configuring the + # underlying RPC channel. + rpc :StreamingPull, stream(StreamingPullRequest), stream(StreamingPullResponse) + # Modifies the `PushConfig` for a specified subscription. + # + # This may be used to change a push subscription to a pull one (signified by + # an empty `PushConfig`) or vice versa, or change the endpoint URL and other + # attributes of a push subscription. Messages will accumulate for delivery + # continuously through the call regardless of changes to the `PushConfig`. + rpc :ModifyPushConfig, ModifyPushConfigRequest, Google::Protobuf::Empty + # Gets the configuration details of a snapshot.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + rpc :GetSnapshot, GetSnapshotRequest, Snapshot + # Lists the existing snapshots.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + rpc :ListSnapshots, ListSnapshotsRequest, ListSnapshotsResponse + # Creates a snapshot from the requested subscription.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # If the snapshot already exists, returns `ALREADY_EXISTS`. + # If the requested subscription doesn't exist, returns `NOT_FOUND`. + # If the backlog in the subscription is too old -- and the resulting snapshot + # would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. + # See also the `Snapshot.expire_time` field. If the name is not provided in + # the request, the server will assign a random + # name for this snapshot on the same project as the subscription, conforming + # to the [resource name format](https://cloud.google.com/pubsub/docs/overview#names). + # The generated + # name is populated in the returned Snapshot object. Note that for REST API + # requests, you must specify a name in the request. + rpc :CreateSnapshot, CreateSnapshotRequest, Snapshot + # Updates an existing snapshot.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # Note that certain properties of a snapshot are not modifiable. + rpc :UpdateSnapshot, UpdateSnapshotRequest, Snapshot + # Removes an existing snapshot.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + # When the snapshot is deleted, all messages retained in the snapshot + # are immediately dropped. After a snapshot is deleted, a new one may be + # created with the same name, but the new one has no association with the old + # snapshot or its subscription, unless the same subscription is specified. + rpc :DeleteSnapshot, DeleteSnapshotRequest, Google::Protobuf::Empty + # Seeks an existing subscription to a point in time or to a given snapshot, + # whichever is provided in the request.

+ # ALPHA: This feature is part of an alpha release. This API might be + # changed in backward-incompatible ways and is not recommended for production + # use. It is not subject to any SLA or deprecation policy. + rpc :Seek, SeekRequest, SeekResponse + end + + Stub = Service.rpc_stub_class + end + end + end +end diff --git a/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/publisher_client_test.rb b/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/publisher_client_test.rb new file mode 100644 index 000000000..83f693cf0 --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/publisher_client_test.rb @@ -0,0 +1,829 @@ +# Copyright 2018 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 +# +# https://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. + +require "minitest/autorun" +require "minitest/spec" + +require "google/gax" + +require "google/cloud/pubsub" +require "google/cloud/pubsub/v1/publisher_client" +require "google/iam/v1/iam_policy_services_pb" +require "google/pubsub/v1/pubsub_services_pb" + +class CustomTestError < StandardError; end + +# Mock for the GRPC::ClientStub class. +class MockGrpcClientStub + + # @param expected_symbol [Symbol] the symbol of the grpc method to be mocked. + # @param mock_method [Proc] The method that is being mocked. + def initialize(expected_symbol, mock_method) + @expected_symbol = expected_symbol + @mock_method = mock_method + end + + # This overrides the Object#method method to return the mocked method when the mocked method + # is being requested. For methods that aren't being tested, this method returns a proc that + # will raise an error when called. This is to assure that only the mocked grpc method is being + # called. + # + # @param symbol [Symbol] The symbol of the method being requested. + # @return [Proc] The proc of the requested method. If the requested method is not being mocked + # the proc returned will raise when called. + def method(symbol) + return @mock_method if symbol == @expected_symbol + + # The requested method is not being tested, raise if it called. + proc do + raise "The method #{symbol} was unexpectedly called during the " \ + "test for #{@expected_symbol}." + end + end +end + +class MockPublisherCredentials < Google::Cloud::Pubsub::V1::Credentials + def initialize(method_name) + @method_name = method_name + end + + def updater_proc + proc do + raise "The method `#{@method_name}` was trying to make a grpc request. This should not " \ + "happen since the grpc layer is being mocked." + end + end +end + +describe Google::Cloud::Pubsub::V1::PublisherClient do + + describe 'create_topic' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#create_topic." + + it 'invokes create_topic without error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Create expected grpc response + name_2 = "name2-1052831874" + expected_response = { name: name_2 } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Topic) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::Topic, request) + assert_equal(formatted_name, request.name) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:create_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("create_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.create_topic(formatted_name) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.create_topic(formatted_name) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes create_topic with error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::Topic, request) + assert_equal(formatted_name, request.name) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:create_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("create_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.create_topic(formatted_name) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'update_topic' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#update_topic." + + it 'invokes update_topic without error' do + # Create request parameters + topic = {} + update_mask = {} + + # Create expected grpc response + name = "name3373707" + expected_response = { name: name } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Topic) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateTopicRequest, request) + assert_equal(Google::Gax::to_proto(topic, Google::Pubsub::V1::Topic), request.topic) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:update_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("update_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.update_topic(topic, update_mask) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.update_topic(topic, update_mask) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes update_topic with error' do + # Create request parameters + topic = {} + update_mask = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateTopicRequest, request) + assert_equal(Google::Gax::to_proto(topic, Google::Pubsub::V1::Topic), request.topic) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:update_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("update_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.update_topic(topic, update_mask) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'publish' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#publish." + + it 'invokes publish without error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + data = '' + messages_element = { data: data } + messages = [messages_element] + + # Create expected grpc response + message_ids_element = "messageIdsElement-744837059" + message_ids = [message_ids_element] + expected_response = { message_ids: message_ids } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::PublishResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::PublishRequest, request) + assert_equal(formatted_topic, request.topic) + messages = messages.map do |req| + Google::Gax::to_proto(req, Google::Pubsub::V1::PubsubMessage) + end + assert_equal(messages, request.messages) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:publish, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("publish") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.publish(formatted_topic, messages) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.publish(formatted_topic, messages) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes publish with error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + data = '' + messages_element = { data: data } + messages = [messages_element] + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::PublishRequest, request) + assert_equal(formatted_topic, request.topic) + messages = messages.map do |req| + Google::Gax::to_proto(req, Google::Pubsub::V1::PubsubMessage) + end + assert_equal(messages, request.messages) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:publish, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("publish") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.publish(formatted_topic, messages) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'get_topic' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#get_topic." + + it 'invokes get_topic without error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Create expected grpc response + name = "name3373707" + expected_response = { name: name } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Topic) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::GetTopicRequest, request) + assert_equal(formatted_topic, request.topic) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:get_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("get_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.get_topic(formatted_topic) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.get_topic(formatted_topic) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes get_topic with error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::GetTopicRequest, request) + assert_equal(formatted_topic, request.topic) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("get_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_topic(formatted_topic) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'list_topics' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#list_topics." + + it 'invokes list_topics without error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path("[PROJECT]") + + # Create expected grpc response + next_page_token = "" + topics_element = {} + topics = [topics_element] + expected_response = { next_page_token: next_page_token, topics: topics } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::ListTopicsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListTopicsRequest, request) + assert_equal(formatted_project, request.project) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:list_topics, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("list_topics") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.list_topics(formatted_project) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.topics.to_a, response.to_a) + end + end + end + + it 'invokes list_topics with error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::PublisherClient.project_path("[PROJECT]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListTopicsRequest, request) + assert_equal(formatted_project, request.project) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_topics, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("list_topics") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_topics(formatted_project) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'list_topic_subscriptions' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#list_topic_subscriptions." + + it 'invokes list_topic_subscriptions without error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Create expected grpc response + next_page_token = "" + subscriptions_element = "subscriptionsElement1698708147" + subscriptions = [subscriptions_element] + expected_response = { next_page_token: next_page_token, subscriptions: subscriptions } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::ListTopicSubscriptionsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListTopicSubscriptionsRequest, request) + assert_equal(formatted_topic, request.topic) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:list_topic_subscriptions, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("list_topic_subscriptions") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.list_topic_subscriptions(formatted_topic) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.subscriptions.to_a, response.to_a) + end + end + end + + it 'invokes list_topic_subscriptions with error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListTopicSubscriptionsRequest, request) + assert_equal(formatted_topic, request.topic) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_topic_subscriptions, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("list_topic_subscriptions") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_topic_subscriptions(formatted_topic) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'delete_topic' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#delete_topic." + + it 'invokes delete_topic without error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteTopicRequest, request) + assert_equal(formatted_topic, request.topic) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:delete_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("delete_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.delete_topic(formatted_topic) + + # Verify the response + assert_nil(response) + + # Call method with block + client.delete_topic(formatted_topic) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes delete_topic with error' do + # Create request parameters + formatted_topic = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteTopicRequest, request) + assert_equal(formatted_topic, request.topic) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:delete_topic, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("delete_topic") + + Google::Pubsub::V1::Publisher::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.delete_topic(formatted_topic) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'set_iam_policy' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#set_iam_policy." + + it 'invokes set_iam_policy without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + policy = {} + + # Create expected grpc response + version = 351608024 + etag = "21" + expected_response = { version: version, etag: etag } + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::Policy) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::SetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(Google::Gax::to_proto(policy, Google::Iam::V1::Policy), request.policy) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:set_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("set_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.set_iam_policy(formatted_resource, policy) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.set_iam_policy(formatted_resource, policy) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes set_iam_policy with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + policy = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::SetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(Google::Gax::to_proto(policy, Google::Iam::V1::Policy), request.policy) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:set_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("set_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.set_iam_policy(formatted_resource, policy) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'get_iam_policy' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#get_iam_policy." + + it 'invokes get_iam_policy without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Create expected grpc response + version = 351608024 + etag = "21" + expected_response = { version: version, etag: etag } + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::Policy) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::GetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:get_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("get_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.get_iam_policy(formatted_resource) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.get_iam_policy(formatted_resource) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes get_iam_policy with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::GetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("get_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_iam_policy(formatted_resource) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'test_iam_permissions' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::PublisherClient#test_iam_permissions." + + it 'invokes test_iam_permissions without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + permissions = [] + + # Create expected grpc response + expected_response = {} + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::TestIamPermissionsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::TestIamPermissionsRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(permissions, request.permissions) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:test_iam_permissions, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("test_iam_permissions") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + response = client.test_iam_permissions(formatted_resource, permissions) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.test_iam_permissions(formatted_resource, permissions) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes test_iam_permissions with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::PublisherClient.topic_path("[PROJECT]", "[TOPIC]") + permissions = [] + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::TestIamPermissionsRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(permissions, request.permissions) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:test_iam_permissions, mock_method) + + # Mock auth layer + mock_credentials = MockPublisherCredentials.new("test_iam_permissions") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Publisher.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.test_iam_permissions(formatted_resource, permissions) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end +end \ No newline at end of file diff --git a/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/subscriber_client_test.rb b/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/subscriber_client_test.rb new file mode 100644 index 000000000..20625c9ac --- /dev/null +++ b/generated/ruby/google-cloud-pubsub/test/google/cloud/pubsub/v1/subscriber_client_test.rb @@ -0,0 +1,1471 @@ +# Copyright 2018 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 +# +# https://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. + +require "minitest/autorun" +require "minitest/spec" + +require "google/gax" + +require "google/cloud/pubsub" +require "google/cloud/pubsub/v1/subscriber_client" +require "google/iam/v1/iam_policy_services_pb" +require "google/pubsub/v1/pubsub_services_pb" + +class CustomTestError < StandardError; end + +# Mock for the GRPC::ClientStub class. +class MockGrpcClientStub + + # @param expected_symbol [Symbol] the symbol of the grpc method to be mocked. + # @param mock_method [Proc] The method that is being mocked. + def initialize(expected_symbol, mock_method) + @expected_symbol = expected_symbol + @mock_method = mock_method + end + + # This overrides the Object#method method to return the mocked method when the mocked method + # is being requested. For methods that aren't being tested, this method returns a proc that + # will raise an error when called. This is to assure that only the mocked grpc method is being + # called. + # + # @param symbol [Symbol] The symbol of the method being requested. + # @return [Proc] The proc of the requested method. If the requested method is not being mocked + # the proc returned will raise when called. + def method(symbol) + return @mock_method if symbol == @expected_symbol + + # The requested method is not being tested, raise if it called. + proc do + raise "The method #{symbol} was unexpectedly called during the " \ + "test for #{@expected_symbol}." + end + end +end + +class MockSubscriberCredentials < Google::Cloud::Pubsub::V1::Credentials + def initialize(method_name) + @method_name = method_name + end + + def updater_proc + proc do + raise "The method `#{@method_name}` was trying to make a grpc request. This should not " \ + "happen since the grpc layer is being mocked." + end + end +end + +describe Google::Cloud::Pubsub::V1::SubscriberClient do + + describe 'create_subscription' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#create_subscription." + + it 'invokes create_subscription without error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + formatted_topic = Google::Cloud::Pubsub::V1::SubscriberClient.topic_path("[PROJECT]", "[TOPIC]") + + # Create expected grpc response + name_2 = "name2-1052831874" + topic_2 = "topic2-1139259102" + ack_deadline_seconds = 2135351438 + retain_acked_messages = false + expected_response = { + name: name_2, + topic: topic_2, + ack_deadline_seconds: ack_deadline_seconds, + retain_acked_messages: retain_acked_messages + } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Subscription) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::Subscription, request) + assert_equal(formatted_name, request.name) + assert_equal(formatted_topic, request.topic) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:create_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("create_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.create_subscription(formatted_name, formatted_topic) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.create_subscription(formatted_name, formatted_topic) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes create_subscription with error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + formatted_topic = Google::Cloud::Pubsub::V1::SubscriberClient.topic_path("[PROJECT]", "[TOPIC]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::Subscription, request) + assert_equal(formatted_name, request.name) + assert_equal(formatted_topic, request.topic) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:create_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("create_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.create_subscription(formatted_name, formatted_topic) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'get_subscription' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#get_subscription." + + it 'invokes get_subscription without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Create expected grpc response + name = "name3373707" + topic = "topic110546223" + ack_deadline_seconds = 2135351438 + retain_acked_messages = false + expected_response = { + name: name, + topic: topic, + ack_deadline_seconds: ack_deadline_seconds, + retain_acked_messages: retain_acked_messages + } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Subscription) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::GetSubscriptionRequest, request) + assert_equal(formatted_subscription, request.subscription) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:get_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("get_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.get_subscription(formatted_subscription) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.get_subscription(formatted_subscription) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes get_subscription with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::GetSubscriptionRequest, request) + assert_equal(formatted_subscription, request.subscription) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("get_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_subscription(formatted_subscription) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'update_subscription' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#update_subscription." + + it 'invokes update_subscription without error' do + # Create request parameters + ack_deadline_seconds = 42 + subscription = { ack_deadline_seconds: ack_deadline_seconds } + paths_element = "ack_deadline_seconds" + paths = [paths_element] + update_mask = { paths: paths } + + # Create expected grpc response + name = "name3373707" + topic = "topic110546223" + ack_deadline_seconds_2 = 921632575 + retain_acked_messages = false + expected_response = { + name: name, + topic: topic, + ack_deadline_seconds: ack_deadline_seconds_2, + retain_acked_messages: retain_acked_messages + } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Subscription) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateSubscriptionRequest, request) + assert_equal(Google::Gax::to_proto(subscription, Google::Pubsub::V1::Subscription), request.subscription) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:update_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("update_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.update_subscription(subscription, update_mask) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.update_subscription(subscription, update_mask) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes update_subscription with error' do + # Create request parameters + ack_deadline_seconds = 42 + subscription = { ack_deadline_seconds: ack_deadline_seconds } + paths_element = "ack_deadline_seconds" + paths = [paths_element] + update_mask = { paths: paths } + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateSubscriptionRequest, request) + assert_equal(Google::Gax::to_proto(subscription, Google::Pubsub::V1::Subscription), request.subscription) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:update_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("update_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.update_subscription(subscription, update_mask) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'list_subscriptions' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#list_subscriptions." + + it 'invokes list_subscriptions without error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + + # Create expected grpc response + next_page_token = "" + subscriptions_element = {} + subscriptions = [subscriptions_element] + expected_response = { next_page_token: next_page_token, subscriptions: subscriptions } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::ListSubscriptionsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListSubscriptionsRequest, request) + assert_equal(formatted_project, request.project) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:list_subscriptions, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("list_subscriptions") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.list_subscriptions(formatted_project) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.subscriptions.to_a, response.to_a) + end + end + end + + it 'invokes list_subscriptions with error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListSubscriptionsRequest, request) + assert_equal(formatted_project, request.project) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_subscriptions, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("list_subscriptions") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_subscriptions(formatted_project) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'delete_subscription' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#delete_subscription." + + it 'invokes delete_subscription without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteSubscriptionRequest, request) + assert_equal(formatted_subscription, request.subscription) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:delete_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("delete_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.delete_subscription(formatted_subscription) + + # Verify the response + assert_nil(response) + + # Call method with block + client.delete_subscription(formatted_subscription) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes delete_subscription with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteSubscriptionRequest, request) + assert_equal(formatted_subscription, request.subscription) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:delete_subscription, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("delete_subscription") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.delete_subscription(formatted_subscription) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'modify_ack_deadline' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#modify_ack_deadline." + + it 'invokes modify_ack_deadline without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + ack_ids = [] + ack_deadline_seconds = 0 + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ModifyAckDeadlineRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(ack_ids, request.ack_ids) + assert_equal(ack_deadline_seconds, request.ack_deadline_seconds) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:modify_ack_deadline, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("modify_ack_deadline") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.modify_ack_deadline( + formatted_subscription, + ack_ids, + ack_deadline_seconds + ) + + # Verify the response + assert_nil(response) + + # Call method with block + client.modify_ack_deadline( + formatted_subscription, + ack_ids, + ack_deadline_seconds + ) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes modify_ack_deadline with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + ack_ids = [] + ack_deadline_seconds = 0 + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ModifyAckDeadlineRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(ack_ids, request.ack_ids) + assert_equal(ack_deadline_seconds, request.ack_deadline_seconds) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:modify_ack_deadline, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("modify_ack_deadline") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.modify_ack_deadline( + formatted_subscription, + ack_ids, + ack_deadline_seconds + ) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'acknowledge' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#acknowledge." + + it 'invokes acknowledge without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + ack_ids = [] + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::AcknowledgeRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(ack_ids, request.ack_ids) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:acknowledge, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("acknowledge") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.acknowledge(formatted_subscription, ack_ids) + + # Verify the response + assert_nil(response) + + # Call method with block + client.acknowledge(formatted_subscription, ack_ids) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes acknowledge with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + ack_ids = [] + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::AcknowledgeRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(ack_ids, request.ack_ids) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:acknowledge, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("acknowledge") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.acknowledge(formatted_subscription, ack_ids) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'pull' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#pull." + + it 'invokes pull without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + max_messages = 0 + + # Create expected grpc response + expected_response = {} + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::PullResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::PullRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(max_messages, request.max_messages) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:pull, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("pull") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.pull(formatted_subscription, max_messages) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.pull(formatted_subscription, max_messages) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes pull with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + max_messages = 0 + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::PullRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(max_messages, request.max_messages) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:pull, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("pull") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.pull(formatted_subscription, max_messages) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'streaming_pull' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#streaming_pull." + + it 'invokes streaming_pull without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + stream_ack_deadline_seconds = 0 + request = { subscription: formatted_subscription, stream_ack_deadline_seconds: stream_ack_deadline_seconds } + + # Create expected grpc response + received_messages_element = {} + received_messages = [received_messages_element] + expected_response = { received_messages: received_messages } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::StreamingPullResponse) + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_instance_of(Google::Pubsub::V1::StreamingPullRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(stream_ack_deadline_seconds, request.stream_ack_deadline_seconds) + OpenStruct.new(execute: [expected_response]) + end + mock_stub = MockGrpcClientStub.new(:streaming_pull, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("streaming_pull") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.streaming_pull([request]) + + # Verify the response + assert_equal(1, response.count) + assert_equal(expected_response, response.first) + end + end + end + + it 'invokes streaming_pull with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + stream_ack_deadline_seconds = 0 + request = { subscription: formatted_subscription, stream_ack_deadline_seconds: stream_ack_deadline_seconds } + + # Mock Grpc layer + mock_method = proc do |requests| + request = requests.first + assert_instance_of(Google::Pubsub::V1::StreamingPullRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(stream_ack_deadline_seconds, request.stream_ack_deadline_seconds) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:streaming_pull, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("streaming_pull") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.streaming_pull([request]) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'modify_push_config' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#modify_push_config." + + it 'invokes modify_push_config without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + push_config = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ModifyPushConfigRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(Google::Gax::to_proto(push_config, Google::Pubsub::V1::PushConfig), request.push_config) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:modify_push_config, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("modify_push_config") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.modify_push_config(formatted_subscription, push_config) + + # Verify the response + assert_nil(response) + + # Call method with block + client.modify_push_config(formatted_subscription, push_config) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes modify_push_config with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + push_config = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ModifyPushConfigRequest, request) + assert_equal(formatted_subscription, request.subscription) + assert_equal(Google::Gax::to_proto(push_config, Google::Pubsub::V1::PushConfig), request.push_config) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:modify_push_config, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("modify_push_config") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.modify_push_config(formatted_subscription, push_config) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'list_snapshots' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#list_snapshots." + + it 'invokes list_snapshots without error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + + # Create expected grpc response + next_page_token = "" + snapshots_element = {} + snapshots = [snapshots_element] + expected_response = { next_page_token: next_page_token, snapshots: snapshots } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::ListSnapshotsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListSnapshotsRequest, request) + assert_equal(formatted_project, request.project) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:list_snapshots, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("list_snapshots") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.list_snapshots(formatted_project) + + # Verify the response + assert(response.instance_of?(Google::Gax::PagedEnumerable)) + assert_equal(expected_response, response.page.response) + assert_nil(response.next_page) + assert_equal(expected_response.snapshots.to_a, response.to_a) + end + end + end + + it 'invokes list_snapshots with error' do + # Create request parameters + formatted_project = Google::Cloud::Pubsub::V1::SubscriberClient.project_path("[PROJECT]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::ListSnapshotsRequest, request) + assert_equal(formatted_project, request.project) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:list_snapshots, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("list_snapshots") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.list_snapshots(formatted_project) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'create_snapshot' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#create_snapshot." + + it 'invokes create_snapshot without error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Create expected grpc response + name_2 = "name2-1052831874" + topic = "topic110546223" + expected_response = { name: name_2, topic: topic } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Snapshot) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::CreateSnapshotRequest, request) + assert_equal(formatted_name, request.name) + assert_equal(formatted_subscription, request.subscription) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:create_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("create_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.create_snapshot(formatted_name, formatted_subscription) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.create_snapshot(formatted_name, formatted_subscription) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes create_snapshot with error' do + # Create request parameters + formatted_name = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::CreateSnapshotRequest, request) + assert_equal(formatted_name, request.name) + assert_equal(formatted_subscription, request.subscription) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:create_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("create_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.create_snapshot(formatted_name, formatted_subscription) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'update_snapshot' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#update_snapshot." + + it 'invokes update_snapshot without error' do + # Create request parameters + seconds = 123456 + expire_time = { seconds: seconds } + snapshot = { expire_time: expire_time } + paths_element = "expire_time" + paths = [paths_element] + update_mask = { paths: paths } + + # Create expected grpc response + name = "name3373707" + topic = "topic110546223" + expected_response = { name: name, topic: topic } + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::Snapshot) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateSnapshotRequest, request) + assert_equal(Google::Gax::to_proto(snapshot, Google::Pubsub::V1::Snapshot), request.snapshot) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:update_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("update_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.update_snapshot(snapshot, update_mask) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.update_snapshot(snapshot, update_mask) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes update_snapshot with error' do + # Create request parameters + seconds = 123456 + expire_time = { seconds: seconds } + snapshot = { expire_time: expire_time } + paths_element = "expire_time" + paths = [paths_element] + update_mask = { paths: paths } + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::UpdateSnapshotRequest, request) + assert_equal(Google::Gax::to_proto(snapshot, Google::Pubsub::V1::Snapshot), request.snapshot) + assert_equal(Google::Gax::to_proto(update_mask, Google::Protobuf::FieldMask), request.update_mask) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:update_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("update_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.update_snapshot(snapshot, update_mask) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'delete_snapshot' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#delete_snapshot." + + it 'invokes delete_snapshot without error' do + # Create request parameters + formatted_snapshot = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteSnapshotRequest, request) + assert_equal(formatted_snapshot, request.snapshot) + OpenStruct.new(execute: nil) + end + mock_stub = MockGrpcClientStub.new(:delete_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("delete_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.delete_snapshot(formatted_snapshot) + + # Verify the response + assert_nil(response) + + # Call method with block + client.delete_snapshot(formatted_snapshot) do |response, operation| + # Verify the response + assert_nil(response) + refute_nil(operation) + end + end + end + end + + it 'invokes delete_snapshot with error' do + # Create request parameters + formatted_snapshot = Google::Cloud::Pubsub::V1::SubscriberClient.snapshot_path("[PROJECT]", "[SNAPSHOT]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::DeleteSnapshotRequest, request) + assert_equal(formatted_snapshot, request.snapshot) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:delete_snapshot, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("delete_snapshot") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.delete_snapshot(formatted_snapshot) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'seek' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#seek." + + it 'invokes seek without error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Create expected grpc response + expected_response = {} + expected_response = Google::Gax::to_proto(expected_response, Google::Pubsub::V1::SeekResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::SeekRequest, request) + assert_equal(formatted_subscription, request.subscription) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:seek, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("seek") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.seek(formatted_subscription) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.seek(formatted_subscription) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes seek with error' do + # Create request parameters + formatted_subscription = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Pubsub::V1::SeekRequest, request) + assert_equal(formatted_subscription, request.subscription) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:seek, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("seek") + + Google::Pubsub::V1::Subscriber::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.seek(formatted_subscription) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'set_iam_policy' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#set_iam_policy." + + it 'invokes set_iam_policy without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + policy = {} + + # Create expected grpc response + version = 351608024 + etag = "21" + expected_response = { version: version, etag: etag } + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::Policy) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::SetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(Google::Gax::to_proto(policy, Google::Iam::V1::Policy), request.policy) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:set_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("set_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.set_iam_policy(formatted_resource, policy) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.set_iam_policy(formatted_resource, policy) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes set_iam_policy with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + policy = {} + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::SetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(Google::Gax::to_proto(policy, Google::Iam::V1::Policy), request.policy) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:set_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("set_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.set_iam_policy(formatted_resource, policy) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'get_iam_policy' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#get_iam_policy." + + it 'invokes get_iam_policy without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Create expected grpc response + version = 351608024 + etag = "21" + expected_response = { version: version, etag: etag } + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::Policy) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::GetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:get_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("get_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.get_iam_policy(formatted_resource) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.get_iam_policy(formatted_resource) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes get_iam_policy with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::GetIamPolicyRequest, request) + assert_equal(formatted_resource, request.resource) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:get_iam_policy, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("get_iam_policy") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.get_iam_policy(formatted_resource) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end + + describe 'test_iam_permissions' do + custom_error = CustomTestError.new "Custom test error for Google::Cloud::Pubsub::V1::SubscriberClient#test_iam_permissions." + + it 'invokes test_iam_permissions without error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + permissions = [] + + # Create expected grpc response + expected_response = {} + expected_response = Google::Gax::to_proto(expected_response, Google::Iam::V1::TestIamPermissionsResponse) + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::TestIamPermissionsRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(permissions, request.permissions) + OpenStruct.new(execute: expected_response) + end + mock_stub = MockGrpcClientStub.new(:test_iam_permissions, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("test_iam_permissions") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + response = client.test_iam_permissions(formatted_resource, permissions) + + # Verify the response + assert_equal(expected_response, response) + + # Call method with block + client.test_iam_permissions(formatted_resource, permissions) do |response, operation| + # Verify the response + assert_equal(expected_response, response) + refute_nil(operation) + end + end + end + end + + it 'invokes test_iam_permissions with error' do + # Create request parameters + formatted_resource = Google::Cloud::Pubsub::V1::SubscriberClient.subscription_path("[PROJECT]", "[SUBSCRIPTION]") + permissions = [] + + # Mock Grpc layer + mock_method = proc do |request| + assert_instance_of(Google::Iam::V1::TestIamPermissionsRequest, request) + assert_equal(formatted_resource, request.resource) + assert_equal(permissions, request.permissions) + raise custom_error + end + mock_stub = MockGrpcClientStub.new(:test_iam_permissions, mock_method) + + # Mock auth layer + mock_credentials = MockSubscriberCredentials.new("test_iam_permissions") + + Google::Iam::V1::IAMPolicy::Stub.stub(:new, mock_stub) do + Google::Cloud::Pubsub::V1::Credentials.stub(:default, mock_credentials) do + client = Google::Cloud::Pubsub::Subscriber.new(version: :v1) + + # Call method + err = assert_raises Google::Gax::GaxError do + client.test_iam_permissions(formatted_resource, permissions) + end + + # Verify the GaxError wrapped the custom error that was raised. + assert_match(custom_error.message, err.message) + end + end + end + end +end \ No newline at end of file