gapic-common 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9019d4ed6928276ec36fa6e06dd95a3674a30ce24635a087e0ebde6abc43cd91
4
+ data.tar.gz: abaa4c9666268d28dff68a5e2b4379d11f3f442c4fc2a8034e77d226d6f82365
5
+ SHA512:
6
+ metadata.gz: b58787f5b5b86b8b146a5c2fed6e7a23f7d7dc1498f53a1a4d75163e51f498b0ccbab88bbdd84b8a3f669f1a218ba674f419758b88e4c7f3c5405e5669f9962b
7
+ data.tar.gz: a04f15b0d04aced9ad2d9918fb6a75305dea59f05b10985618590c3d85ff211bbb88c1ab5d2a64853721685dcf6919c53c546e0b11652eb39374a9d8dd17f844
data/.yardopts ADDED
@@ -0,0 +1,13 @@
1
+ --no-private
2
+ --title=GAPIC common library
3
+ --markup markdown
4
+ --markup-provider redcarpet
5
+ --main README.md
6
+
7
+ ./lib/**/*.rb
8
+ -
9
+ CONTRIBUTING.md
10
+ CHANGELOG.md
11
+ CODE_OF_CONDUCT.md
12
+ LICENSE
13
+ README.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # Release History
2
+
@@ -0,0 +1,43 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project,
4
+ and in the interest of fostering an open and welcoming community,
5
+ we pledge to respect all people who contribute through reporting issues,
6
+ posting feature requests, updating documentation,
7
+ submitting pull requests or patches, and other activities.
8
+
9
+ We are committed to making participation in this project
10
+ a harassment-free experience for everyone,
11
+ regardless of level of experience, gender, gender identity and expression,
12
+ sexual orientation, disability, personal appearance,
13
+ body size, race, ethnicity, age, religion, or nationality.
14
+
15
+ Examples of unacceptable behavior by participants include:
16
+
17
+ * The use of sexualized language or imagery
18
+ * Personal attacks
19
+ * Trolling or insulting/derogatory comments
20
+ * Public or private harassment
21
+ * Publishing other's private information,
22
+ such as physical or electronic
23
+ addresses, without explicit permission
24
+ * Other unethical or unprofessional conduct.
25
+
26
+ Project maintainers have the right and responsibility to remove, edit, or reject
27
+ comments, commits, code, wiki edits, issues, and other contributions
28
+ that are not aligned to this Code of Conduct.
29
+ By adopting this Code of Conduct,
30
+ project maintainers commit themselves to fairly and consistently
31
+ applying these principles to every aspect of managing this project.
32
+ Project maintainers who do not follow or enforce the Code of Conduct
33
+ may be permanently removed from the project team.
34
+
35
+ This code of conduct applies both within project spaces and in public spaces
36
+ when an individual is representing the project or its community.
37
+
38
+ Instances of abusive, harassing, or otherwise unacceptable behavior
39
+ may be reported by opening an issue
40
+ or contacting one or more of the project maintainers.
41
+
42
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
43
+ available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # How to Contribute
2
+
3
+ We'd love to accept your patches and contributions to this project. There are
4
+ just a few small guidelines you need to follow.
5
+
6
+ ## Contributor License Agreement
7
+
8
+ Contributions to this project must be accompanied by a Contributor License
9
+ Agreement. You (or your employer) retain the copyright to your contribution;
10
+ this simply gives us permission to use and redistribute your contributions as
11
+ part of the project. Head over to <https://cla.developers.google.com/> to see
12
+ your current agreements on file or to sign a new one.
13
+
14
+ You generally only need to submit a CLA once, so if you've already submitted one
15
+ (even if it was for a different project), you probably don't need to do it
16
+ again.
17
+
18
+ ## Code reviews
19
+
20
+ All submissions, including submissions by project members, require review. We
21
+ use GitHub pull requests for this purpose. Consult
22
+ [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23
+ information on using pull requests.
24
+
25
+ ## Community Guidelines
26
+
27
+ This project follows [Google's Open Source Community
28
+ Guidelines](https://opensource.google.com/conduct/).
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019 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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Google API Extensions for Ruby
2
+ ================================
3
+
4
+ Generated API Client common code (gapic-common) is a set of modules which aids
5
+ the development of APIs for clients and servers based on [gRPC][] and Google API
6
+ conventions.
7
+
8
+ Application code will rarely need to use most of the classes within this library
9
+ directly, but code generated automatically from the API definition files in
10
+ [Google APIs][] can use services such as page streaming to provide a more
11
+ convenient and idiomatic API surface to callers.
12
+
13
+ [gRPC]: http://grpc.io
14
+ [Google APIs]: https://github.com/googleapis/googleapis/
15
+
16
+ ## Supported Ruby Versions
17
+
18
+ This library is supported on Ruby 2.4+.
19
+
20
+ Google provides official support for Ruby versions that are actively supported
21
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
22
+ security maintenance, and not end of life. Currently, this means Ruby 2.4 and
23
+ later. Older versions of Ruby _may_ still work, but are unsupported and not
24
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
25
+ about the Ruby support schedule.
26
+
27
+ ## Contributing
28
+
29
+ Contributions to this library are always welcome and highly encouraged.
30
+
31
+ See the [CONTRIBUTING](CONTRIBUTING.md) documentation for more information on how to get started.
32
+
33
+ ## Versioning
34
+
35
+ This library is currently a **preview** with no guarantees of stability or support. Please get
36
+ involved and let us know if you find it useful and we'll work towards a stable version.
37
+
38
+ ## Disclaimer
39
+
40
+ This is not an official Google product.
data/RELEASING.md ADDED
@@ -0,0 +1,76 @@
1
+ # Releasing gapic-common
2
+
3
+ The Google Ruby GAX project uses [semantic versioning](http://semver.org). Replace the `<prev_version>` and `<version>` placeholders shown in the examples below with the appropriate numbers, e.g. `0.1.0` and `0.2.0`.
4
+
5
+ After all [pull requests](https://github.com/googleapis/gax-ruby/pulls) for a release have been merged and all [Travis builds](https://travis-ci.org/googleapis/gax-ruby) are green, you may create a release as follows:
6
+
7
+ 1. If you haven't already, switch to the master branch, ensure that you have no changes, and pull from origin.
8
+
9
+ ```sh
10
+ $ git checkout master
11
+ $ git status
12
+ $ git pull <remote> master --rebase
13
+ ```
14
+
15
+ 1. Build the gem locally. (Depending on your environment, you may need to `bundle exec` to rake commands; this will be shown.)
16
+
17
+ ```sh
18
+ $ bundle exec rake build
19
+ ```
20
+
21
+ 1. Install the gem locally.
22
+
23
+ ```sh
24
+ $ bundle exec rake install
25
+ ```
26
+
27
+ 1. Using IRB (not `rake console`!), manually test the gem that you installed in the previous step.
28
+
29
+ 1. Update the `CHANGELOG.md`. Write bullet-point lists of the major and minor changes. You can also add examples, fixes, thank yous, and anything else helpful or relevant. See google-cloud-node [v0.18.0](https://github.com/GoogleCloudPlatform/google-cloud-node/releases/tag/v0.18.0) for an example with all the bells and whistles.
30
+
31
+ 1. Edit `lib/gapic/version.rb` file, changing the value of `VERSION` to your new version number. This repo requires a PR for all changes so doing this in a branch is best.
32
+
33
+ 1. Run the tests, one last time.
34
+
35
+ ```sh
36
+ $ bundle update
37
+ $ bundle exec rake spec
38
+ ```
39
+
40
+ 1. Commit your changes. Copy and paste the significant points from your `CHANGELOG.md` edit as the description in your commit message.
41
+
42
+ ```sh
43
+ $ git commit -am "Release gapic-common <version> ..."
44
+ ```
45
+
46
+ 1. Tag the version after all changes have been merged.
47
+
48
+ ```sh
49
+ $ git tag gapic-common/v<version>
50
+ ```
51
+
52
+ 1. Push the tag.
53
+
54
+ ```sh
55
+ $ git push <remote> gapic-common/v<version>
56
+ ```
57
+
58
+ 1. Wait until the [Travis build](https://travis-ci.org/googleapis/gax-ruby) has passed for the tag.
59
+
60
+ 1. Push the gem to [RubyGems.org](https://rubygems.org/gems/google-cloud).
61
+
62
+ ```sh
63
+ $ gem push gapic-common-<version>.gem
64
+ ```
65
+
66
+ 1. On the [gax-ruby releases page](https://github.com/googleapis/gax-ruby/releases), click [Draft a new release](https://github.com/googleapis/gax-ruby/releases/new). Complete the form. Include the bullet-point lists of the major and minor changes from the gem's `CHANGELOG.md`. You can also add examples, fixes, thank yous, and anything else helpful or relevant.
67
+
68
+ 1. Click `Publish release`.
69
+
70
+ 1. Wait until the last tag build job has successfully completed on Travis. Then push your commits to the master branch. This will trigger another [Travis](https://travis-ci.org/googleapis/gax-ruby) build on master branch.
71
+
72
+ ```sh
73
+ $ git push <remote> master
74
+ ```
75
+
76
+ High fives all around!
@@ -0,0 +1,15 @@
1
+ # Copyright 2019 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
+ require "gapic/common"
@@ -0,0 +1,68 @@
1
+ # Copyright 2019 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
+ require "gapic/call_options/retry_policy"
16
+
17
+ module Gapic
18
+ ##
19
+ # Encapsulates the overridable settings for a particular RPC call.
20
+ #
21
+ # @!attribute [r] timeout
22
+ # @return [Numeric, nil]
23
+ # @!attribute [r] metadata
24
+ # @return [Hash]
25
+ # @!attribute [r] retry_policy
26
+ # @return [RetryPolicy, Object]
27
+ #
28
+ class CallOptions
29
+ attr_reader :timeout, :metadata, :retry_policy
30
+
31
+ ##
32
+ # Create a new Options object instance.
33
+ #
34
+ # @param timeout [Numeric] The client-side timeout for RPC calls.
35
+ # @param metadata [Hash] The request header params.
36
+ # @param retry_policy [Hash, RetryPolicy, Proc] The policy for error retry. A Hash can be provided to
37
+ # customize the policy object, using keys that match the arguments for {RetryPolicy.new}.
38
+ #
39
+ # A Proc object can also be provided. The Proc should accept an error as an argument, and return `true` if the
40
+ # error should be retried or `false` if not. If the error is to be retried, the Proc object must also block
41
+ # with an incremental delay before returning `true`.
42
+ #
43
+ def initialize timeout: nil, metadata: nil, retry_policy: nil
44
+ # Converts hash and nil to a policy object
45
+ retry_policy = RetryPolicy.new retry_policy.to_h if retry_policy.respond_to? :to_h
46
+
47
+ @timeout = timeout # allow to be nil so it can be overridden
48
+ @metadata = metadata.to_h # Ensure always hash, even for nil
49
+ @retry_policy = retry_policy
50
+ end
51
+
52
+ ##
53
+ # @private
54
+ # Apply default values to the options object. This does not replace user-provided values, it only overrides
55
+ # empty values.
56
+ #
57
+ # @param timeout [Numeric] The client-side timeout for RPC calls.
58
+ # @param metadata [Hash] the request header params.
59
+ # @param retry_policy [Hash] the policy for error retry.
60
+ # @param retry_policy [Hash] The policy for error retry. keys must match the arguments for
61
+ # {RetryPolicy.new}.
62
+ def apply_defaults timeout: nil, metadata: nil, retry_policy: nil
63
+ @timeout ||= timeout
64
+ @metadata = metadata.merge @metadata if metadata
65
+ @retry_policy.apply_defaults retry_policy if @retry_policy.respond_to? :apply_defaults
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,106 @@
1
+ # Copyright 2019 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 Gapic
16
+ class CallOptions
17
+ ##
18
+ # The policy for retrying failed RPC calls using an incremental backoff. A new object instance should be used for
19
+ # every RpcCall invocation.
20
+ #
21
+ # Only errors orginating from GRPC will be retried.
22
+ #
23
+ class RetryPolicy
24
+ ##
25
+ # Create new API Call RetryPolicy.
26
+ #
27
+ # @param initial_delay [Numeric] client-side timeout
28
+ # @param multiplier [Numeric] client-side timeout
29
+ # @param max_delay [Numeric] client-side timeout
30
+ #
31
+ def initialize retry_codes: nil, initial_delay: nil, multiplier: nil, max_delay: nil
32
+ @retry_codes = retry_codes
33
+ @initial_delay = initial_delay
34
+ @multiplier = multiplier
35
+ @max_delay = max_delay
36
+ @delay = nil
37
+ end
38
+
39
+ def retry_codes
40
+ @retry_codes || []
41
+ end
42
+
43
+ def initial_delay
44
+ @initial_delay || 1
45
+ end
46
+
47
+ def multiplier
48
+ @multiplier || 1.3
49
+ end
50
+
51
+ def max_delay
52
+ @max_delay || 15
53
+ end
54
+
55
+ ##
56
+ # The current delay value.
57
+ def delay
58
+ @delay || initial_delay
59
+ end
60
+
61
+ def call error
62
+ return false unless retry? error
63
+
64
+ delay!
65
+ increment_delay!
66
+
67
+ true
68
+ end
69
+
70
+ ##
71
+ # @private
72
+ # Apply default values to the policy object. This does not replace user-provided values, it only overrides empty
73
+ # values.
74
+ #
75
+ # @param retry_policy [Hash] The policy for error retry. keys must match the arguments for
76
+ # {RpcCall::RetryPolicy.new}.
77
+ def apply_defaults retry_policy
78
+ return unless retry_policy.is_a? Hash
79
+
80
+ @retry_codes ||= retry_policy[:retry_codes]
81
+ @initial_delay ||= retry_policy[:initial_delay]
82
+ @multiplier ||= retry_policy[:multiplier]
83
+ @max_delay ||= retry_policy[:max_delay]
84
+
85
+ self
86
+ end
87
+
88
+ private
89
+
90
+ def retry? error
91
+ error.is_a?(GRPC::BadStatus) && retry_codes.include?(error.code)
92
+ end
93
+
94
+ def delay!
95
+ # Call Kernel.sleep so we can stub it.
96
+ Kernel.sleep delay
97
+ end
98
+
99
+ ##
100
+ # Calculate and set the next delay value.
101
+ def increment_delay!
102
+ @delay = [delay * multiplier, max_delay].min
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright 2019 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
+ require "grpc/errors"
16
+ require "grpc/core/status_codes"
17
+
18
+ require "gapic/call_options"
19
+ require "gapic/headers"
20
+ require "gapic/operation"
21
+ require "gapic/paged_enumerable"
22
+ require "gapic/protobuf"
23
+ require "gapic/stream_input"
24
+ require "gapic/common/version"
25
+
26
+ # Gapic is Google's API client generator
27
+ module Gapic
28
+ # The gapic-common gem includes various common libraries for clients built
29
+ # with Gapic.
30
+ module Common
31
+ end
32
+ end