google-cloud-firestore 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +201 -0
  4. data/README.md +30 -0
  5. data/lib/google-cloud-firestore.rb +106 -0
  6. data/lib/google/cloud/firestore.rb +514 -0
  7. data/lib/google/cloud/firestore/batch.rb +462 -0
  8. data/lib/google/cloud/firestore/client.rb +449 -0
  9. data/lib/google/cloud/firestore/collection_reference.rb +249 -0
  10. data/lib/google/cloud/firestore/commit_response.rb +145 -0
  11. data/lib/google/cloud/firestore/convert.rb +561 -0
  12. data/lib/google/cloud/firestore/credentials.rb +35 -0
  13. data/lib/google/cloud/firestore/document_reference.rb +468 -0
  14. data/lib/google/cloud/firestore/document_snapshot.rb +324 -0
  15. data/lib/google/cloud/firestore/field_path.rb +216 -0
  16. data/lib/google/cloud/firestore/field_value.rb +113 -0
  17. data/lib/google/cloud/firestore/generate.rb +35 -0
  18. data/lib/google/cloud/firestore/query.rb +651 -0
  19. data/lib/google/cloud/firestore/service.rb +176 -0
  20. data/lib/google/cloud/firestore/transaction.rb +726 -0
  21. data/lib/google/cloud/firestore/v1beta1.rb +121 -0
  22. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +63 -0
  23. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +134 -0
  24. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +584 -0
  25. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +215 -0
  26. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +167 -0
  27. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +124 -0
  28. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +106 -0
  29. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +89 -0
  30. data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +83 -0
  31. data/lib/google/cloud/firestore/v1beta1/doc/overview.rb +53 -0
  32. data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +974 -0
  33. data/lib/google/cloud/firestore/v1beta1/firestore_client_config.json +100 -0
  34. data/lib/google/cloud/firestore/version.rb +22 -0
  35. data/lib/google/firestore/v1beta1/common_pb.rb +44 -0
  36. data/lib/google/firestore/v1beta1/document_pb.rb +49 -0
  37. data/lib/google/firestore/v1beta1/firestore_pb.rb +219 -0
  38. data/lib/google/firestore/v1beta1/firestore_services_pb.rb +87 -0
  39. data/lib/google/firestore/v1beta1/query_pb.rb +103 -0
  40. data/lib/google/firestore/v1beta1/write_pb.rb +73 -0
  41. metadata +251 -0
@@ -0,0 +1,106 @@
1
+ # Copyright 2017 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Google
16
+ module Protobuf
17
+ # A Timestamp represents a point in time independent of any time zone
18
+ # or calendar, represented as seconds and fractions of seconds at
19
+ # nanosecond resolution in UTC Epoch time. It is encoded using the
20
+ # Proleptic Gregorian Calendar which extends the Gregorian calendar
21
+ # backwards to year one. It is encoded assuming all minutes are 60
22
+ # seconds long, i.e. leap seconds are "smeared" so that no leap second
23
+ # table is needed for interpretation. Range is from
24
+ # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
25
+ # By restricting to that range, we ensure that we can convert to
26
+ # and from RFC 3339 date strings.
27
+ # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
28
+ #
29
+ # = Examples
30
+ #
31
+ # Example 1: Compute Timestamp from POSIX +time()+.
32
+ #
33
+ # Timestamp timestamp;
34
+ # timestamp.set_seconds(time(NULL));
35
+ # timestamp.set_nanos(0);
36
+ #
37
+ # Example 2: Compute Timestamp from POSIX +gettimeofday()+.
38
+ #
39
+ # struct timeval tv;
40
+ # gettimeofday(&tv, NULL);
41
+ #
42
+ # Timestamp timestamp;
43
+ # timestamp.set_seconds(tv.tv_sec);
44
+ # timestamp.set_nanos(tv.tv_usec * 1000);
45
+ #
46
+ # Example 3: Compute Timestamp from Win32 +GetSystemTimeAsFileTime()+.
47
+ #
48
+ # FILETIME ft;
49
+ # GetSystemTimeAsFileTime(&ft);
50
+ # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
51
+ #
52
+ # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
53
+ # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
54
+ # Timestamp timestamp;
55
+ # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
56
+ # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
57
+ #
58
+ # Example 4: Compute Timestamp from Java +System.currentTimeMillis()+.
59
+ #
60
+ # long millis = System.currentTimeMillis();
61
+ #
62
+ # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
63
+ # .setNanos((int) ((millis % 1000) * 1000000)).build();
64
+ #
65
+ #
66
+ # Example 5: Compute Timestamp from current time in Python.
67
+ #
68
+ # timestamp = Timestamp()
69
+ # timestamp.GetCurrentTime()
70
+ #
71
+ # = JSON Mapping
72
+ #
73
+ # In JSON format, the Timestamp type is encoded as a string in the
74
+ # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
75
+ # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
76
+ # where {year} is always expressed using four digits while {month}, {day},
77
+ # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
78
+ # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
79
+ # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
80
+ # is required, though only UTC (as indicated by "Z") is presently supported.
81
+ #
82
+ # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
83
+ # 01:30 UTC on January 15, 2017.
84
+ #
85
+ # In JavaScript, one can convert a Date object to this format using the
86
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
87
+ # method. In Python, a standard +datetime.datetime+ object can be converted
88
+ # to this format using [+strftime+](https://docs.python.org/2/library/time.html#time.strftime)
89
+ # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
90
+ # can use the Joda Time's [+ISODateTimeFormat.dateTime()+](
91
+ # http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime())
92
+ # to obtain a formatter capable of generating timestamps in this format.
93
+ # @!attribute [rw] seconds
94
+ # @return [Integer]
95
+ # Represents seconds of UTC time since Unix epoch
96
+ # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
97
+ # 9999-12-31T23:59:59Z inclusive.
98
+ # @!attribute [rw] nanos
99
+ # @return [Integer]
100
+ # Non-negative fractions of a second at nanosecond resolution. Negative
101
+ # second values with fractions must still have non-negative nanos values
102
+ # that count forward in time. Must be from 0 to 999,999,999
103
+ # inclusive.
104
+ class Timestamp; end
105
+ end
106
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright 2017 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Google
16
+ module Protobuf
17
+ # Wrapper message for +double+.
18
+ #
19
+ # The JSON representation for +DoubleValue+ is JSON number.
20
+ # @!attribute [rw] value
21
+ # @return [Float]
22
+ # The double value.
23
+ class DoubleValue; end
24
+
25
+ # Wrapper message for +float+.
26
+ #
27
+ # The JSON representation for +FloatValue+ is JSON number.
28
+ # @!attribute [rw] value
29
+ # @return [Float]
30
+ # The float value.
31
+ class FloatValue; end
32
+
33
+ # Wrapper message for +int64+.
34
+ #
35
+ # The JSON representation for +Int64Value+ is JSON string.
36
+ # @!attribute [rw] value
37
+ # @return [Integer]
38
+ # The int64 value.
39
+ class Int64Value; end
40
+
41
+ # Wrapper message for +uint64+.
42
+ #
43
+ # The JSON representation for +UInt64Value+ is JSON string.
44
+ # @!attribute [rw] value
45
+ # @return [Integer]
46
+ # The uint64 value.
47
+ class UInt64Value; end
48
+
49
+ # Wrapper message for +int32+.
50
+ #
51
+ # The JSON representation for +Int32Value+ is JSON number.
52
+ # @!attribute [rw] value
53
+ # @return [Integer]
54
+ # The int32 value.
55
+ class Int32Value; end
56
+
57
+ # Wrapper message for +uint32+.
58
+ #
59
+ # The JSON representation for +UInt32Value+ is JSON number.
60
+ # @!attribute [rw] value
61
+ # @return [Integer]
62
+ # The uint32 value.
63
+ class UInt32Value; end
64
+
65
+ # Wrapper message for +bool+.
66
+ #
67
+ # The JSON representation for +BoolValue+ is JSON +true+ and +false+.
68
+ # @!attribute [rw] value
69
+ # @return [true, false]
70
+ # The bool value.
71
+ class BoolValue; end
72
+
73
+ # Wrapper message for +string+.
74
+ #
75
+ # The JSON representation for +StringValue+ is JSON string.
76
+ # @!attribute [rw] value
77
+ # @return [String]
78
+ # The string value.
79
+ class StringValue; end
80
+
81
+ # Wrapper message for +bytes+.
82
+ #
83
+ # The JSON representation for +BytesValue+ is JSON string.
84
+ # @!attribute [rw] value
85
+ # @return [String]
86
+ # The bytes value.
87
+ class BytesValue; end
88
+ end
89
+ end
@@ -0,0 +1,83 @@
1
+ # Copyright 2017 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Google
16
+ module Rpc
17
+ # The +Status+ type defines a logical error model that is suitable for different
18
+ # programming environments, including REST APIs and RPC APIs. It is used by
19
+ # [gRPC](https://github.com/grpc). The error model is designed to be:
20
+ #
21
+ # * Simple to use and understand for most users
22
+ # * Flexible enough to meet unexpected needs
23
+ #
24
+ # = Overview
25
+ #
26
+ # The +Status+ message contains three pieces of data: error code, error message,
27
+ # and error details. The error code should be an enum value of
28
+ # {Google::Rpc::Code}, but it may accept additional error codes if needed. The
29
+ # error message should be a developer-facing English message that helps
30
+ # developers *understand* and *resolve* the error. If a localized user-facing
31
+ # error message is needed, put the localized message in the error details or
32
+ # localize it in the client. The optional error details may contain arbitrary
33
+ # information about the error. There is a predefined set of error detail types
34
+ # in the package +google.rpc+ that can be used for common error conditions.
35
+ #
36
+ # = Language mapping
37
+ #
38
+ # The +Status+ message is the logical representation of the error model, but it
39
+ # is not necessarily the actual wire format. When the +Status+ message is
40
+ # exposed in different client libraries and different wire protocols, it can be
41
+ # mapped differently. For example, it will likely be mapped to some exceptions
42
+ # in Java, but more likely mapped to some error codes in C.
43
+ #
44
+ # = Other uses
45
+ #
46
+ # The error model and the +Status+ message can be used in a variety of
47
+ # environments, either with or without APIs, to provide a
48
+ # consistent developer experience across different environments.
49
+ #
50
+ # Example uses of this error model include:
51
+ #
52
+ # * Partial errors. If a service needs to return partial errors to the client,
53
+ # it may embed the +Status+ in the normal response to indicate the partial
54
+ # errors.
55
+ #
56
+ # * Workflow errors. A typical workflow has multiple steps. Each step may
57
+ # have a +Status+ message for error reporting.
58
+ #
59
+ # * Batch operations. If a client uses batch request and batch response, the
60
+ # +Status+ message should be used directly inside batch response, one for
61
+ # each error sub-response.
62
+ #
63
+ # * Asynchronous operations. If an API call embeds asynchronous operation
64
+ # results in its response, the status of those operations should be
65
+ # represented directly using the +Status+ message.
66
+ #
67
+ # * Logging. If some API errors are stored in logs, the message +Status+ could
68
+ # be used directly after any stripping needed for security/privacy reasons.
69
+ # @!attribute [rw] code
70
+ # @return [Integer]
71
+ # The status code, which should be an enum value of {Google::Rpc::Code}.
72
+ # @!attribute [rw] message
73
+ # @return [String]
74
+ # A developer-facing error message, which should be in English. Any
75
+ # user-facing error message should be localized and sent in the
76
+ # {Google::Rpc::Status#details} field, or localized by the client.
77
+ # @!attribute [rw] details
78
+ # @return [Array<Google::Protobuf::Any>]
79
+ # A list of messages that carry the error details. There is a common set of
80
+ # message types for APIs to use.
81
+ class Status; end
82
+ end
83
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright 2017 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Google
16
+ module Cloud
17
+ # rubocop:disable LineLength
18
+
19
+ ##
20
+ # # Ruby Client for Google Cloud Firestore API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
21
+ #
22
+ # [Google Cloud Firestore API][Product Documentation]:
23
+ #
24
+ # - [Product Documentation][]
25
+ #
26
+ # ## Quick Start
27
+ # In order to use this library, you first need to go through the following
28
+ # steps:
29
+ #
30
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
31
+ # 2. [Enable the Google Cloud Firestore API.](https://console.cloud.google.com/apis/api/firestore)
32
+ # 3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
33
+ #
34
+ # ### Installation
35
+ # ```
36
+ # $ gem install google-cloud-firestore
37
+ # ```
38
+ #
39
+ # ### Next Steps
40
+ # - Read the [Google Cloud Firestore API Product documentation][Product Documentation]
41
+ # to learn more about the product and see How-to Guides.
42
+ # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
43
+ # to see the full list of Cloud APIs that we cover.
44
+ #
45
+ # [Product Documentation]: https://cloud.google.com/firestore
46
+ #
47
+ #
48
+ module Firestore
49
+ module V1beta1
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,974 @@
1
+ # Copyright 2017 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # EDITING INSTRUCTIONS
16
+ # This file was generated from the file
17
+ # https://github.com/googleapis/googleapis/blob/master/google/firestore/v1beta1/firestore.proto,
18
+ # and updates to that file get reflected here through a refresh process.
19
+ # For the short term, the refresh process will only be runnable by Google
20
+ # engineers.
21
+ #
22
+ # The only allowed edits are to method and file documentation. A 3-way
23
+ # merge preserves those additions if the generated source changes.
24
+
25
+ require "json"
26
+ require "pathname"
27
+
28
+ require "google/gax"
29
+
30
+ require "google/firestore/v1beta1/firestore_pb"
31
+ require "google/cloud/firestore/credentials"
32
+
33
+ module Google
34
+ module Cloud
35
+ module Firestore
36
+ module V1beta1
37
+ # The Cloud Firestore service.
38
+ #
39
+ # This service exposes several types of comparable timestamps:
40
+ #
41
+ # * +create_time+ - The time at which a document was created. Changes only
42
+ # when a document is deleted, then re-created. Increases in a strict
43
+ # monotonic fashion.
44
+ # * +update_time+ - The time at which a document was last updated. Changes
45
+ # every time a document is modified. Does not change when a write results
46
+ # in no modifications. Increases in a strict monotonic fashion.
47
+ # * +read_time+ - The time at which a particular state was observed. Used
48
+ # to denote a consistent snapshot of the database or the time at which a
49
+ # Document was observed to not exist.
50
+ # * +commit_time+ - The time at which the writes in a transaction were
51
+ # committed. Any read with an equal or greater +read_time+ is guaranteed
52
+ # to see the effects of the transaction.
53
+ #
54
+ # @!attribute [r] firestore_stub
55
+ # @return [Google::Firestore::V1beta1::Firestore::Stub]
56
+ class FirestoreClient
57
+ attr_reader :firestore_stub
58
+
59
+ # The default address of the service.
60
+ SERVICE_ADDRESS = "firestore.googleapis.com".freeze
61
+
62
+ # The default port of the service.
63
+ DEFAULT_SERVICE_PORT = 443
64
+
65
+ DEFAULT_TIMEOUT = 30
66
+
67
+ PAGE_DESCRIPTORS = {
68
+ "list_documents" => Google::Gax::PageDescriptor.new(
69
+ "page_token",
70
+ "next_page_token",
71
+ "documents"),
72
+ "list_collection_ids" => Google::Gax::PageDescriptor.new(
73
+ "page_token",
74
+ "next_page_token",
75
+ "collection_ids")
76
+ }.freeze
77
+
78
+ private_constant :PAGE_DESCRIPTORS
79
+
80
+ # The scopes needed to make gRPC calls to all of the methods defined in
81
+ # this service.
82
+ ALL_SCOPES = [
83
+ "https://www.googleapis.com/auth/cloud-platform",
84
+ "https://www.googleapis.com/auth/datastore"
85
+ ].freeze
86
+
87
+ DATABASE_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
88
+ "projects/{project}/databases/{database}"
89
+ )
90
+
91
+ private_constant :DATABASE_ROOT_PATH_TEMPLATE
92
+
93
+ DOCUMENT_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
94
+ "projects/{project}/databases/{database}/documents"
95
+ )
96
+
97
+ private_constant :DOCUMENT_ROOT_PATH_TEMPLATE
98
+
99
+ DOCUMENT_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
100
+ "projects/{project}/databases/{database}/documents/{document_path=**}"
101
+ )
102
+
103
+ private_constant :DOCUMENT_PATH_PATH_TEMPLATE
104
+
105
+ ANY_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
106
+ "projects/{project}/databases/{database}/documents/{document}/{any_path=**}"
107
+ )
108
+
109
+ private_constant :ANY_PATH_PATH_TEMPLATE
110
+
111
+ # Returns a fully-qualified database_root resource name string.
112
+ # @param project [String]
113
+ # @param database [String]
114
+ # @return [String]
115
+ def self.database_root_path project, database
116
+ DATABASE_ROOT_PATH_TEMPLATE.render(
117
+ :"project" => project,
118
+ :"database" => database
119
+ )
120
+ end
121
+
122
+ # Returns a fully-qualified document_root resource name string.
123
+ # @param project [String]
124
+ # @param database [String]
125
+ # @return [String]
126
+ def self.document_root_path project, database
127
+ DOCUMENT_ROOT_PATH_TEMPLATE.render(
128
+ :"project" => project,
129
+ :"database" => database
130
+ )
131
+ end
132
+
133
+ # Returns a fully-qualified document_path resource name string.
134
+ # @param project [String]
135
+ # @param database [String]
136
+ # @param document_path [String]
137
+ # @return [String]
138
+ def self.document_path_path project, database, document_path
139
+ DOCUMENT_PATH_PATH_TEMPLATE.render(
140
+ :"project" => project,
141
+ :"database" => database,
142
+ :"document_path" => document_path
143
+ )
144
+ end
145
+
146
+ # Returns a fully-qualified any_path resource name string.
147
+ # @param project [String]
148
+ # @param database [String]
149
+ # @param document [String]
150
+ # @param any_path [String]
151
+ # @return [String]
152
+ def self.any_path_path project, database, document, any_path
153
+ ANY_PATH_PATH_TEMPLATE.render(
154
+ :"project" => project,
155
+ :"database" => database,
156
+ :"document" => document,
157
+ :"any_path" => any_path
158
+ )
159
+ end
160
+
161
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
162
+ # Provides the means for authenticating requests made by the client. This parameter can
163
+ # be many types.
164
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
165
+ # authenticating requests made by this client.
166
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
167
+ # credentials for this client.
168
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
169
+ # credentials for this client.
170
+ # A `GRPC::Core::Channel` will be used to make calls through.
171
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
172
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
173
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
174
+ # metadata for requests, generally, to give OAuth credentials.
175
+ # @param scopes [Array<String>]
176
+ # The OAuth scopes for this service. This parameter is ignored if
177
+ # an updater_proc is supplied.
178
+ # @param client_config [Hash]
179
+ # A Hash for call options for each method. See
180
+ # Google::Gax#construct_settings for the structure of
181
+ # this data. Falls back to the default config if not specified
182
+ # or the specified config is missing data points.
183
+ # @param timeout [Numeric]
184
+ # The default timeout, in seconds, for calls made through this client.
185
+ def initialize \
186
+ service_path: SERVICE_ADDRESS,
187
+ port: DEFAULT_SERVICE_PORT,
188
+ channel: nil,
189
+ chan_creds: nil,
190
+ updater_proc: nil,
191
+ credentials: nil,
192
+ scopes: ALL_SCOPES,
193
+ client_config: {},
194
+ timeout: DEFAULT_TIMEOUT,
195
+ lib_name: nil,
196
+ lib_version: ""
197
+ # These require statements are intentionally placed here to initialize
198
+ # the gRPC module only when it's required.
199
+ # See https://github.com/googleapis/toolkit/issues/446
200
+ require "google/gax/grpc"
201
+ require "google/firestore/v1beta1/firestore_services_pb"
202
+
203
+ if channel || chan_creds || updater_proc
204
+ warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
205
+ "on 2017/09/08"
206
+ credentials ||= channel
207
+ credentials ||= chan_creds
208
+ credentials ||= updater_proc
209
+ end
210
+ if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT
211
+ warn "`service_path` and `port` parameters are deprecated and will be removed"
212
+ end
213
+
214
+ credentials ||= Google::Cloud::Firestore::Credentials.default
215
+
216
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
217
+ updater_proc = Google::Cloud::Firestore::Credentials.new(credentials).updater_proc
218
+ end
219
+ if credentials.is_a?(GRPC::Core::Channel)
220
+ channel = credentials
221
+ end
222
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
223
+ chan_creds = credentials
224
+ end
225
+ if credentials.is_a?(Proc)
226
+ updater_proc = credentials
227
+ end
228
+ if credentials.is_a?(Google::Auth::Credentials)
229
+ updater_proc = credentials.updater_proc
230
+ end
231
+
232
+ google_api_client = "gl-ruby/#{RUBY_VERSION}"
233
+ google_api_client << " #{lib_name}/#{lib_version}" if lib_name
234
+ google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
235
+ google_api_client << " grpc/#{GRPC::VERSION}"
236
+ google_api_client.freeze
237
+
238
+ headers = { :"x-goog-api-client" => google_api_client }
239
+ client_config_file = Pathname.new(__dir__).join(
240
+ "firestore_client_config.json"
241
+ )
242
+ defaults = client_config_file.open do |f|
243
+ Google::Gax.construct_settings(
244
+ "google.firestore.v1beta1.Firestore",
245
+ JSON.parse(f.read),
246
+ client_config,
247
+ Google::Gax::Grpc::STATUS_CODE_NAMES,
248
+ timeout,
249
+ page_descriptors: PAGE_DESCRIPTORS,
250
+ errors: Google::Gax::Grpc::API_ERRORS,
251
+ kwargs: headers
252
+ )
253
+ end
254
+ @firestore_stub = Google::Gax::Grpc.create_stub(
255
+ service_path,
256
+ port,
257
+ chan_creds: chan_creds,
258
+ channel: channel,
259
+ updater_proc: updater_proc,
260
+ scopes: scopes,
261
+ &Google::Firestore::V1beta1::Firestore::Stub.method(:new)
262
+ )
263
+
264
+ @get_document = Google::Gax.create_api_call(
265
+ @firestore_stub.method(:get_document),
266
+ defaults["get_document"]
267
+ )
268
+ @list_documents = Google::Gax.create_api_call(
269
+ @firestore_stub.method(:list_documents),
270
+ defaults["list_documents"]
271
+ )
272
+ @create_document = Google::Gax.create_api_call(
273
+ @firestore_stub.method(:create_document),
274
+ defaults["create_document"]
275
+ )
276
+ @update_document = Google::Gax.create_api_call(
277
+ @firestore_stub.method(:update_document),
278
+ defaults["update_document"]
279
+ )
280
+ @delete_document = Google::Gax.create_api_call(
281
+ @firestore_stub.method(:delete_document),
282
+ defaults["delete_document"]
283
+ )
284
+ @batch_get_documents = Google::Gax.create_api_call(
285
+ @firestore_stub.method(:batch_get_documents),
286
+ defaults["batch_get_documents"]
287
+ )
288
+ @begin_transaction = Google::Gax.create_api_call(
289
+ @firestore_stub.method(:begin_transaction),
290
+ defaults["begin_transaction"]
291
+ )
292
+ @commit = Google::Gax.create_api_call(
293
+ @firestore_stub.method(:commit),
294
+ defaults["commit"]
295
+ )
296
+ @rollback = Google::Gax.create_api_call(
297
+ @firestore_stub.method(:rollback),
298
+ defaults["rollback"]
299
+ )
300
+ @run_query = Google::Gax.create_api_call(
301
+ @firestore_stub.method(:run_query),
302
+ defaults["run_query"]
303
+ )
304
+ @write = Google::Gax.create_api_call(
305
+ @firestore_stub.method(:write),
306
+ defaults["write"]
307
+ )
308
+ @listen = Google::Gax.create_api_call(
309
+ @firestore_stub.method(:listen),
310
+ defaults["listen"]
311
+ )
312
+ @list_collection_ids = Google::Gax.create_api_call(
313
+ @firestore_stub.method(:list_collection_ids),
314
+ defaults["list_collection_ids"]
315
+ )
316
+ end
317
+
318
+ # Service calls
319
+
320
+ # Gets a single document.
321
+ #
322
+ # @param name [String]
323
+ # The resource name of the Document to get. In the format:
324
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
325
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
326
+ # The fields to return. If not set, returns all fields.
327
+ #
328
+ # If the document has a field that is not present in this mask, that field
329
+ # will not be returned in the response.
330
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
331
+ # can also be provided.
332
+ # @param transaction [String]
333
+ # Reads the document in a transaction.
334
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
335
+ # Reads the version of the document at the given time.
336
+ # This may not be older than 60 seconds.
337
+ # A hash of the same form as `Google::Protobuf::Timestamp`
338
+ # can also be provided.
339
+ # @param options [Google::Gax::CallOptions]
340
+ # Overrides the default settings for this call, e.g, timeout,
341
+ # retries, etc.
342
+ # @return [Google::Firestore::V1beta1::Document]
343
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
344
+ # @example
345
+ # require "google/cloud/firestore/v1beta1"
346
+ #
347
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
348
+ # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
349
+ # response = firestore_client.get_document(formatted_name)
350
+
351
+ def get_document \
352
+ name,
353
+ mask: nil,
354
+ transaction: nil,
355
+ read_time: nil,
356
+ options: nil
357
+ req = {
358
+ name: name,
359
+ mask: mask,
360
+ transaction: transaction,
361
+ read_time: read_time
362
+ }.delete_if { |_, v| v.nil? }
363
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::GetDocumentRequest)
364
+ @get_document.call(req, options)
365
+ end
366
+
367
+ # Lists documents.
368
+ #
369
+ # @param parent [String]
370
+ # The parent resource name. In the format:
371
+ # +projects/{project_id}/databases/{database_id}/documents+ or
372
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
373
+ # For example:
374
+ # +projects/my-project/databases/my-database/documents+ or
375
+ # +projects/my-project/databases/my-database/documents/chatrooms/my-chatroom+
376
+ # @param collection_id [String]
377
+ # The collection ID, relative to +parent+, to list. For example: +chatrooms+
378
+ # or +messages+.
379
+ # @param page_size [Integer]
380
+ # The maximum number of resources contained in the underlying API
381
+ # response. If page streaming is performed per-resource, this
382
+ # parameter does not affect the return value. If page streaming is
383
+ # performed per-page, this determines the maximum number of
384
+ # resources in a page.
385
+ # @param order_by [String]
386
+ # The order to sort results by. For example: +priority desc, name+.
387
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
388
+ # The fields to return. If not set, returns all fields.
389
+ #
390
+ # If a document has a field that is not present in this mask, that field
391
+ # will not be returned in the response.
392
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
393
+ # can also be provided.
394
+ # @param transaction [String]
395
+ # Reads documents in a transaction.
396
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
397
+ # Reads documents as they were at the given time.
398
+ # This may not be older than 60 seconds.
399
+ # A hash of the same form as `Google::Protobuf::Timestamp`
400
+ # can also be provided.
401
+ # @param show_missing [true, false]
402
+ # If the list should show missing documents. A missing document is a
403
+ # document that does not exist but has sub-documents. These documents will
404
+ # be returned with a key but will not have fields, {Google::Firestore::V1beta1::Document#create_time Document#create_time},
405
+ # or {Google::Firestore::V1beta1::Document#update_time Document#update_time} set.
406
+ #
407
+ # Requests with +show_missing+ may not specify +where+ or
408
+ # +order_by+.
409
+ # @param options [Google::Gax::CallOptions]
410
+ # Overrides the default settings for this call, e.g, timeout,
411
+ # retries, etc.
412
+ # @return [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
413
+ # An enumerable of Google::Firestore::V1beta1::Document instances.
414
+ # See Google::Gax::PagedEnumerable documentation for other
415
+ # operations such as per-page iteration or access to the response
416
+ # object.
417
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
418
+ # @example
419
+ # require "google/cloud/firestore/v1beta1"
420
+ #
421
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
422
+ # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
423
+ # collection_id = ''
424
+ #
425
+ # # Iterate over all results.
426
+ # firestore_client.list_documents(formatted_parent, collection_id).each do |element|
427
+ # # Process element.
428
+ # end
429
+ #
430
+ # # Or iterate over results one page at a time.
431
+ # firestore_client.list_documents(formatted_parent, collection_id).each_page do |page|
432
+ # # Process each page at a time.
433
+ # page.each do |element|
434
+ # # Process element.
435
+ # end
436
+ # end
437
+
438
+ def list_documents \
439
+ parent,
440
+ collection_id,
441
+ page_size: nil,
442
+ order_by: nil,
443
+ mask: nil,
444
+ transaction: nil,
445
+ read_time: nil,
446
+ show_missing: nil,
447
+ options: nil
448
+ req = {
449
+ parent: parent,
450
+ collection_id: collection_id,
451
+ page_size: page_size,
452
+ order_by: order_by,
453
+ mask: mask,
454
+ transaction: transaction,
455
+ read_time: read_time,
456
+ show_missing: show_missing
457
+ }.delete_if { |_, v| v.nil? }
458
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListDocumentsRequest)
459
+ @list_documents.call(req, options)
460
+ end
461
+
462
+ # Creates a new document.
463
+ #
464
+ # @param parent [String]
465
+ # The parent resource. For example:
466
+ # +projects/{project_id}/databases/{database_id}/documents+ or
467
+ # +projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}+
468
+ # @param collection_id [String]
469
+ # The collection ID, relative to +parent+, to list. For example: +chatrooms+.
470
+ # @param document_id [String]
471
+ # The client-assigned document ID to use for this document.
472
+ #
473
+ # Optional. If not specified, an ID will be assigned by the service.
474
+ # @param document [Google::Firestore::V1beta1::Document | Hash]
475
+ # The document to create. +name+ must not be set.
476
+ # A hash of the same form as `Google::Firestore::V1beta1::Document`
477
+ # can also be provided.
478
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
479
+ # The fields to return. If not set, returns all fields.
480
+ #
481
+ # If the document has a field that is not present in this mask, that field
482
+ # will not be returned in the response.
483
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
484
+ # can also be provided.
485
+ # @param options [Google::Gax::CallOptions]
486
+ # Overrides the default settings for this call, e.g, timeout,
487
+ # retries, etc.
488
+ # @return [Google::Firestore::V1beta1::Document]
489
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
490
+ # @example
491
+ # require "google/cloud/firestore/v1beta1"
492
+ #
493
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
494
+ # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
495
+ # collection_id = ''
496
+ # document_id = ''
497
+ # document = {}
498
+ # response = firestore_client.create_document(formatted_parent, collection_id, document_id, document)
499
+
500
+ def create_document \
501
+ parent,
502
+ collection_id,
503
+ document_id,
504
+ document,
505
+ mask: nil,
506
+ options: nil
507
+ req = {
508
+ parent: parent,
509
+ collection_id: collection_id,
510
+ document_id: document_id,
511
+ document: document,
512
+ mask: mask
513
+ }.delete_if { |_, v| v.nil? }
514
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CreateDocumentRequest)
515
+ @create_document.call(req, options)
516
+ end
517
+
518
+ # Updates or inserts a document.
519
+ #
520
+ # @param document [Google::Firestore::V1beta1::Document | Hash]
521
+ # The updated document.
522
+ # Creates the document if it does not already exist.
523
+ # A hash of the same form as `Google::Firestore::V1beta1::Document`
524
+ # can also be provided.
525
+ # @param update_mask [Google::Firestore::V1beta1::DocumentMask | Hash]
526
+ # The fields to update.
527
+ # None of the field paths in the mask may contain a reserved name.
528
+ #
529
+ # If the document exists on the server and has fields not referenced in the
530
+ # mask, they are left unchanged.
531
+ # Fields referenced in the mask, but not present in the input document, are
532
+ # deleted from the document on the server.
533
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
534
+ # can also be provided.
535
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
536
+ # The fields to return. If not set, returns all fields.
537
+ #
538
+ # If the document has a field that is not present in this mask, that field
539
+ # will not be returned in the response.
540
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
541
+ # can also be provided.
542
+ # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
543
+ # An optional precondition on the document.
544
+ # The request will fail if this is set and not met by the target document.
545
+ # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
546
+ # can also be provided.
547
+ # @param options [Google::Gax::CallOptions]
548
+ # Overrides the default settings for this call, e.g, timeout,
549
+ # retries, etc.
550
+ # @return [Google::Firestore::V1beta1::Document]
551
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
552
+ # @example
553
+ # require "google/cloud/firestore/v1beta1"
554
+ #
555
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
556
+ # document = {}
557
+ # update_mask = {}
558
+ # response = firestore_client.update_document(document, update_mask)
559
+
560
+ def update_document \
561
+ document,
562
+ update_mask,
563
+ mask: nil,
564
+ current_document: nil,
565
+ options: nil
566
+ req = {
567
+ document: document,
568
+ update_mask: update_mask,
569
+ mask: mask,
570
+ current_document: current_document
571
+ }.delete_if { |_, v| v.nil? }
572
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::UpdateDocumentRequest)
573
+ @update_document.call(req, options)
574
+ end
575
+
576
+ # Deletes a document.
577
+ #
578
+ # @param name [String]
579
+ # The resource name of the Document to delete. In the format:
580
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
581
+ # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
582
+ # An optional precondition on the document.
583
+ # The request will fail if this is set and not met by the target document.
584
+ # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
585
+ # can also be provided.
586
+ # @param options [Google::Gax::CallOptions]
587
+ # Overrides the default settings for this call, e.g, timeout,
588
+ # retries, etc.
589
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
590
+ # @example
591
+ # require "google/cloud/firestore/v1beta1"
592
+ #
593
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
594
+ # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
595
+ # firestore_client.delete_document(formatted_name)
596
+
597
+ def delete_document \
598
+ name,
599
+ current_document: nil,
600
+ options: nil
601
+ req = {
602
+ name: name,
603
+ current_document: current_document
604
+ }.delete_if { |_, v| v.nil? }
605
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::DeleteDocumentRequest)
606
+ @delete_document.call(req, options)
607
+ nil
608
+ end
609
+
610
+ # Gets multiple documents.
611
+ #
612
+ # Documents returned by this method are not guaranteed to be returned in the
613
+ # same order that they were requested.
614
+ #
615
+ # @param database [String]
616
+ # The database name. In the format:
617
+ # +projects/{project_id}/databases/{database_id}+.
618
+ # @param documents [Array<String>]
619
+ # The names of the documents to retrieve. In the format:
620
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
621
+ # The request will fail if any of the document is not a child resource of the
622
+ # given +database+. Duplicate names will be elided.
623
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
624
+ # The fields to return. If not set, returns all fields.
625
+ #
626
+ # If a document has a field that is not present in this mask, that field will
627
+ # not be returned in the response.
628
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
629
+ # can also be provided.
630
+ # @param transaction [String]
631
+ # Reads documents in a transaction.
632
+ # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
633
+ # Starts a new transaction and reads the documents.
634
+ # Defaults to a read-only transaction.
635
+ # The new transaction ID will be returned as the first response in the
636
+ # stream.
637
+ # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
638
+ # can also be provided.
639
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
640
+ # Reads documents as they were at the given time.
641
+ # This may not be older than 60 seconds.
642
+ # A hash of the same form as `Google::Protobuf::Timestamp`
643
+ # can also be provided.
644
+ # @param options [Google::Gax::CallOptions]
645
+ # Overrides the default settings for this call, e.g, timeout,
646
+ # retries, etc.
647
+ # @return [Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>]
648
+ # An enumerable of Google::Firestore::V1beta1::BatchGetDocumentsResponse instances.
649
+ #
650
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
651
+ # @example
652
+ # require "google/cloud/firestore/v1beta1"
653
+ #
654
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
655
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
656
+ # documents = []
657
+ # firestore_client.batch_get_documents(formatted_database, documents).each do |element|
658
+ # # Process element.
659
+ # end
660
+
661
+ def batch_get_documents \
662
+ database,
663
+ documents,
664
+ mask: nil,
665
+ transaction: nil,
666
+ new_transaction: nil,
667
+ read_time: nil,
668
+ options: nil
669
+ req = {
670
+ database: database,
671
+ documents: documents,
672
+ mask: mask,
673
+ transaction: transaction,
674
+ new_transaction: new_transaction,
675
+ read_time: read_time
676
+ }.delete_if { |_, v| v.nil? }
677
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BatchGetDocumentsRequest)
678
+ @batch_get_documents.call(req, options)
679
+ end
680
+
681
+ # Starts a new transaction.
682
+ #
683
+ # @param database [String]
684
+ # The database name. In the format:
685
+ # +projects/{project_id}/databases/{database_id}+.
686
+ # @param options_ [Google::Firestore::V1beta1::TransactionOptions | Hash]
687
+ # The options for the transaction.
688
+ # Defaults to a read-write transaction.
689
+ # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
690
+ # can also be provided.
691
+ # @param options [Google::Gax::CallOptions]
692
+ # Overrides the default settings for this call, e.g, timeout,
693
+ # retries, etc.
694
+ # @return [Google::Firestore::V1beta1::BeginTransactionResponse]
695
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
696
+ # @example
697
+ # require "google/cloud/firestore/v1beta1"
698
+ #
699
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
700
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
701
+ # response = firestore_client.begin_transaction(formatted_database)
702
+
703
+ def begin_transaction \
704
+ database,
705
+ options_: nil,
706
+ options: nil
707
+ req = {
708
+ database: database,
709
+ options: options_
710
+ }.delete_if { |_, v| v.nil? }
711
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BeginTransactionRequest)
712
+ @begin_transaction.call(req, options)
713
+ end
714
+
715
+ # Commits a transaction, while optionally updating documents.
716
+ #
717
+ # @param database [String]
718
+ # The database name. In the format:
719
+ # +projects/{project_id}/databases/{database_id}+.
720
+ # @param writes [Array<Google::Firestore::V1beta1::Write | Hash>]
721
+ # The writes to apply.
722
+ #
723
+ # Always executed atomically and in order.
724
+ # A hash of the same form as `Google::Firestore::V1beta1::Write`
725
+ # can also be provided.
726
+ # @param transaction [String]
727
+ # If set, applies all writes in this transaction, and commits it.
728
+ # @param options [Google::Gax::CallOptions]
729
+ # Overrides the default settings for this call, e.g, timeout,
730
+ # retries, etc.
731
+ # @return [Google::Firestore::V1beta1::CommitResponse]
732
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
733
+ # @example
734
+ # require "google/cloud/firestore/v1beta1"
735
+ #
736
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
737
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
738
+ # writes = []
739
+ # response = firestore_client.commit(formatted_database, writes)
740
+
741
+ def commit \
742
+ database,
743
+ writes,
744
+ transaction: nil,
745
+ options: nil
746
+ req = {
747
+ database: database,
748
+ writes: writes,
749
+ transaction: transaction
750
+ }.delete_if { |_, v| v.nil? }
751
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CommitRequest)
752
+ @commit.call(req, options)
753
+ end
754
+
755
+ # Rolls back a transaction.
756
+ #
757
+ # @param database [String]
758
+ # The database name. In the format:
759
+ # +projects/{project_id}/databases/{database_id}+.
760
+ # @param transaction [String]
761
+ # The transaction to roll back.
762
+ # @param options [Google::Gax::CallOptions]
763
+ # Overrides the default settings for this call, e.g, timeout,
764
+ # retries, etc.
765
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
766
+ # @example
767
+ # require "google/cloud/firestore/v1beta1"
768
+ #
769
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
770
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
771
+ # transaction = ''
772
+ # firestore_client.rollback(formatted_database, transaction)
773
+
774
+ def rollback \
775
+ database,
776
+ transaction,
777
+ options: nil
778
+ req = {
779
+ database: database,
780
+ transaction: transaction
781
+ }.delete_if { |_, v| v.nil? }
782
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RollbackRequest)
783
+ @rollback.call(req, options)
784
+ nil
785
+ end
786
+
787
+ # Runs a query.
788
+ #
789
+ # @param parent [String]
790
+ # The parent resource name. In the format:
791
+ # +projects/{project_id}/databases/{database_id}/documents+ or
792
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
793
+ # For example:
794
+ # +projects/my-project/databases/my-database/documents+ or
795
+ # +projects/my-project/databases/my-database/documents/chatrooms/my-chatroom+
796
+ # @param structured_query [Google::Firestore::V1beta1::StructuredQuery | Hash]
797
+ # A structured query.
798
+ # A hash of the same form as `Google::Firestore::V1beta1::StructuredQuery`
799
+ # can also be provided.
800
+ # @param transaction [String]
801
+ # Reads documents in a transaction.
802
+ # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
803
+ # Starts a new transaction and reads the documents.
804
+ # Defaults to a read-only transaction.
805
+ # The new transaction ID will be returned as the first response in the
806
+ # stream.
807
+ # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
808
+ # can also be provided.
809
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
810
+ # Reads documents as they were at the given time.
811
+ # This may not be older than 60 seconds.
812
+ # A hash of the same form as `Google::Protobuf::Timestamp`
813
+ # can also be provided.
814
+ # @param options [Google::Gax::CallOptions]
815
+ # Overrides the default settings for this call, e.g, timeout,
816
+ # retries, etc.
817
+ # @return [Enumerable<Google::Firestore::V1beta1::RunQueryResponse>]
818
+ # An enumerable of Google::Firestore::V1beta1::RunQueryResponse instances.
819
+ #
820
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
821
+ # @example
822
+ # require "google/cloud/firestore/v1beta1"
823
+ #
824
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
825
+ # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
826
+ # firestore_client.run_query(formatted_parent).each do |element|
827
+ # # Process element.
828
+ # end
829
+
830
+ def run_query \
831
+ parent,
832
+ structured_query: nil,
833
+ transaction: nil,
834
+ new_transaction: nil,
835
+ read_time: nil,
836
+ options: nil
837
+ req = {
838
+ parent: parent,
839
+ structured_query: structured_query,
840
+ transaction: transaction,
841
+ new_transaction: new_transaction,
842
+ read_time: read_time
843
+ }.delete_if { |_, v| v.nil? }
844
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RunQueryRequest)
845
+ @run_query.call(req, options)
846
+ end
847
+
848
+ # Streams batches of document updates and deletes, in order.
849
+ #
850
+ # @param reqs [Enumerable<Google::Firestore::V1beta1::WriteRequest>]
851
+ # The input requests.
852
+ # @param options [Google::Gax::CallOptions]
853
+ # Overrides the default settings for this call, e.g, timeout,
854
+ # retries, etc.
855
+ # @return [Enumerable<Google::Firestore::V1beta1::WriteResponse>]
856
+ # An enumerable of Google::Firestore::V1beta1::WriteResponse instances.
857
+ #
858
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
859
+ #
860
+ # @note
861
+ # EXPERIMENTAL:
862
+ # Streaming requests are still undergoing review.
863
+ # This method interface might change in the future.
864
+ #
865
+ # @example
866
+ # require "google/cloud/firestore/v1beta1"
867
+ #
868
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
869
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
870
+ # request = { database: formatted_database }
871
+ # requests = [request]
872
+ # firestore_client.write(requests).each do |element|
873
+ # # Process element.
874
+ # end
875
+
876
+ def write reqs, options: nil
877
+ request_protos = reqs.lazy.map do |req|
878
+ Google::Gax::to_proto(req, Google::Firestore::V1beta1::WriteRequest)
879
+ end
880
+ @write.call(request_protos, options)
881
+ end
882
+
883
+ # Listens to changes.
884
+ #
885
+ # @param reqs [Enumerable<Google::Firestore::V1beta1::ListenRequest>]
886
+ # The input requests.
887
+ # @param options [Google::Gax::CallOptions]
888
+ # Overrides the default settings for this call, e.g, timeout,
889
+ # retries, etc.
890
+ # @return [Enumerable<Google::Firestore::V1beta1::ListenResponse>]
891
+ # An enumerable of Google::Firestore::V1beta1::ListenResponse instances.
892
+ #
893
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
894
+ #
895
+ # @note
896
+ # EXPERIMENTAL:
897
+ # Streaming requests are still undergoing review.
898
+ # This method interface might change in the future.
899
+ #
900
+ # @example
901
+ # require "google/cloud/firestore/v1beta1"
902
+ #
903
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
904
+ # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
905
+ # request = { database: formatted_database }
906
+ # requests = [request]
907
+ # firestore_client.listen(requests).each do |element|
908
+ # # Process element.
909
+ # end
910
+
911
+ def listen reqs, options: nil
912
+ request_protos = reqs.lazy.map do |req|
913
+ Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListenRequest)
914
+ end
915
+ @listen.call(request_protos, options)
916
+ end
917
+
918
+ # Lists all the collection IDs underneath a document.
919
+ #
920
+ # @param parent [String]
921
+ # The parent document. In the format:
922
+ # +projects/{project_id}/databases/{database_id}/documents/{document_path}+.
923
+ # For example:
924
+ # +projects/my-project/databases/my-database/documents/chatrooms/my-chatroom+
925
+ # @param page_size [Integer]
926
+ # The maximum number of resources contained in the underlying API
927
+ # response. If page streaming is performed per-resource, this
928
+ # parameter does not affect the return value. If page streaming is
929
+ # performed per-page, this determines the maximum number of
930
+ # resources in a page.
931
+ # @param options [Google::Gax::CallOptions]
932
+ # Overrides the default settings for this call, e.g, timeout,
933
+ # retries, etc.
934
+ # @return [Google::Gax::PagedEnumerable<String>]
935
+ # An enumerable of String instances.
936
+ # See Google::Gax::PagedEnumerable documentation for other
937
+ # operations such as per-page iteration or access to the response
938
+ # object.
939
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
940
+ # @example
941
+ # require "google/cloud/firestore/v1beta1"
942
+ #
943
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
944
+ # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
945
+ #
946
+ # # Iterate over all results.
947
+ # firestore_client.list_collection_ids(formatted_parent).each do |element|
948
+ # # Process element.
949
+ # end
950
+ #
951
+ # # Or iterate over results one page at a time.
952
+ # firestore_client.list_collection_ids(formatted_parent).each_page do |page|
953
+ # # Process each page at a time.
954
+ # page.each do |element|
955
+ # # Process element.
956
+ # end
957
+ # end
958
+
959
+ def list_collection_ids \
960
+ parent,
961
+ page_size: nil,
962
+ options: nil
963
+ req = {
964
+ parent: parent,
965
+ page_size: page_size
966
+ }.delete_if { |_, v| v.nil? }
967
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListCollectionIdsRequest)
968
+ @list_collection_ids.call(req, options)
969
+ end
970
+ end
971
+ end
972
+ end
973
+ end
974
+ end