gapic-generator 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/lib/gapic/generator/version.rb +1 -1
  4. data/lib/gapic/generators/default_generator.rb +3 -1
  5. data/lib/gapic/generators/default_generator_parameters.rb +6 -2
  6. data/lib/gapic/grpc_service_config/{service_config.rb → config.rb} +2 -2
  7. data/lib/gapic/grpc_service_config/parser.rb +8 -8
  8. data/lib/gapic/model/method/http_annotation.rb +123 -0
  9. data/lib/gapic/model/method/lro.rb +160 -0
  10. data/lib/gapic/model/method/routing.rb +263 -0
  11. data/lib/gapic/model/mixins.rb +181 -0
  12. data/lib/gapic/model/model_error.rb +26 -0
  13. data/lib/gapic/model/service/nonstandard_lro_provider.rb +293 -0
  14. data/lib/gapic/model.rb +22 -0
  15. data/lib/gapic/path_pattern/pattern.rb +46 -0
  16. data/lib/gapic/path_pattern/segment.rb +97 -9
  17. data/lib/gapic/presenters/gem_presenter.rb +46 -3
  18. data/lib/gapic/presenters/{service_config_presenter.rb → grpc_service_config_presenter.rb} +1 -1
  19. data/lib/gapic/presenters/method/rest_pagination_info.rb +246 -0
  20. data/lib/gapic/presenters/method_presenter.rb +56 -5
  21. data/lib/gapic/presenters/method_rest_presenter.rb +99 -48
  22. data/lib/gapic/presenters/resource_presenter.rb +8 -0
  23. data/lib/gapic/presenters/service/lro_client_presenter.rb +90 -0
  24. data/lib/gapic/presenters/service_presenter.rb +236 -3
  25. data/lib/gapic/presenters/service_rest_presenter.rb +117 -10
  26. data/lib/gapic/presenters/snippet_presenter.rb +2 -1
  27. data/lib/gapic/presenters.rb +3 -1
  28. data/lib/gapic/schema/api.rb +61 -2
  29. data/lib/gapic/schema/loader.rb +4 -1
  30. data/lib/gapic/schema/service_config_parser.rb +118 -0
  31. data/lib/gapic/schema/wrappers.rb +149 -0
  32. data/lib/google/api/auth.pb.rb +75 -0
  33. data/lib/google/api/backend.pb.rb +59 -0
  34. data/lib/google/api/billing.pb.rb +53 -0
  35. data/lib/google/api/context.pb.rb +47 -0
  36. data/lib/google/api/control.pb.rb +38 -0
  37. data/lib/google/api/documentation.pb.rb +56 -0
  38. data/lib/google/api/endpoint.pb.rb +42 -0
  39. data/lib/google/api/label.pb.rb +49 -0
  40. data/lib/google/api/launch_stage.pb.rb +37 -0
  41. data/lib/google/api/log.pb.rb +47 -0
  42. data/lib/google/api/logging.pb.rb +48 -0
  43. data/lib/google/api/metric.pb.rb +90 -0
  44. data/lib/google/api/monitored_resource.pb.rb +68 -0
  45. data/lib/google/api/monitoring.pb.rb +48 -0
  46. data/lib/google/api/quota.pb.rb +63 -0
  47. data/lib/google/api/routing.pb.rb +58 -0
  48. data/lib/google/api/service.pb.rb +90 -0
  49. data/lib/google/api/source_info.pb.rb +44 -0
  50. data/lib/google/api/system_parameter.pb.rb +51 -0
  51. data/lib/google/api/usage.pb.rb +47 -0
  52. data/lib/google/cloud/extended_operations.pb.rb +57 -0
  53. data/lib/google/protobuf/any.pb.rb +1 -1
  54. data/lib/google/protobuf/api.pb.rb +69 -0
  55. data/lib/google/protobuf/descriptor.pb.rb +1 -1
  56. data/lib/google/protobuf/duration.pb.rb +41 -0
  57. data/lib/google/protobuf/source_context.pb.rb +39 -0
  58. data/lib/google/protobuf/struct.pb.rb +65 -0
  59. data/lib/google/protobuf/type.pb.rb +128 -0
  60. data/lib/google/protobuf/wrappers.pb.rb +80 -0
  61. data/templates/default/gem/yardopts.erb +1 -1
  62. data/templates/default/lib/_package.erb +4 -0
  63. data/templates/default/lib/_service.erb +6 -0
  64. data/templates/default/lib/rest/_rest.erb +0 -2
  65. data/templates/default/service/client/_client.erb +37 -27
  66. data/templates/default/service/client/_config.erb +13 -14
  67. data/templates/default/service/client/_nonstandard_lro.erb +57 -0
  68. data/templates/default/service/client/_paths.erb +1 -1
  69. data/templates/default/service/client/_self_configure_defaults.erb +2 -2
  70. data/templates/default/service/client/method/_def.erb +2 -0
  71. data/templates/default/service/client/method/def/_options_defaults.erb +4 -9
  72. data/templates/default/service/client/method/def/_response.erb +2 -0
  73. data/templates/default/service/client/method/def/_response_nonstandard_lro.erb +23 -0
  74. data/templates/default/service/client/method/def/_routing_params.erb +36 -0
  75. data/templates/default/service/client/method/docs/_deprecated.erb +5 -0
  76. data/templates/default/service/client/method/docs/_snippets.erb +6 -0
  77. data/templates/default/service/nonstandard_lro.erb +6 -0
  78. data/templates/default/service/rest/client/_client.erb +45 -27
  79. data/templates/default/service/rest/client/_config.erb +48 -0
  80. data/templates/default/service/rest/client/method/_def.erb +1 -1
  81. data/templates/default/service/rest/client/method/def/_options_defaults.erb +5 -2
  82. data/templates/default/service/rest/client/method/def/_response.erb +8 -0
  83. data/templates/default/service/rest/client/method/def/_response_nonstandard_lro.erb +23 -0
  84. data/templates/default/service/rest/client/method/def/_response_normal.erb +4 -15
  85. data/templates/default/service/rest/client/method/def/_response_paged.erb +7 -0
  86. data/templates/default/service/rest/client/method/docs/_result.erb +3 -3
  87. data/templates/default/service/rest/service_stub/_service_stub.erb +25 -0
  88. data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/_def.erb +4 -1
  89. data/templates/default/service/rest/{grpc_transcoding/method → service_stub/grpc_transcoding_method}/def/_query_string_param.erb +0 -0
  90. data/templates/default/service/rest/service_stub/method/_def.erb +20 -0
  91. data/templates/default/service/rest/service_stub/method/def/_request.erb +2 -0
  92. data/templates/default/service/rest/service_stub/method/def/_response.erb +17 -0
  93. data/templates/default/service/rest/service_stub.erb +6 -0
  94. data/templates/default/service/rest/test/client.erb +1 -1
  95. data/templates/default/service/test/client_paths.erb +1 -1
  96. data/templates/default/service/test/method/_assert_response.erb +3 -0
  97. metadata +74 -11
  98. data/templates/default/service/rest/client/_requires.erb +0 -1
  99. data/templates/default/service/rest/grpc_transcoding/_grpc_transcoding.erb +0 -9
@@ -2,6 +2,13 @@
2
2
  <% @requires = capture do %>
3
3
  <%= render partial: "service/client/requires", locals: { service: service} -%>
4
4
  require "<%= service.proto_service_require %>"
5
+ <%- if service.subclients? -%>
6
+ <%- service.subclients.each do |subclient| -%>
7
+ <%- unless subclient.client_class_name == "Operations" -%>
8
+ require "<%= subclient.require_str %>"
9
+ <%- end -%>
10
+ <%- end -%>
11
+ <%- end -%>
5
12
  <% end %>
6
13
  ##
7
14
  # Client for the <%= service.name %> service.
@@ -23,14 +30,17 @@ class <%= service.client_name %>
23
30
  #
24
31
  # See {<%= service.client_name_full %>::Configuration}
25
32
  # for a description of the configuration fields.
33
+ <%- if service.is_deprecated? -%>
26
34
  #
27
- # ## Example
35
+ # @deprecated This service is deprecated and may be removed in the next major version update.
36
+ <%- end -%>
28
37
  #
29
- # To modify the configuration for all <%= service.name %> clients:
38
+ # @example
30
39
  #
31
- # <%= service.client_name_full %>.configure do |config|
32
- # config.timeout = 10.0
33
- # end
40
+ # # Modify the configuration for all <%= service.name %> clients
41
+ # <%= service.client_name_full %>.configure do |config|
42
+ # config.timeout = 10.0
43
+ # end
34
44
  #
35
45
  # @yield [config] Configure the <%= service.client_name %> client.
36
46
  # @yieldparam config [<%= service.client_name %>::Configuration]
@@ -64,19 +74,15 @@ class <%= service.client_name %>
64
74
  ##
65
75
  # Create a new <%= service.name %> client object.
66
76
  #
67
- # ## Examples
77
+ # @example
68
78
  #
69
- # To create a new <%= service.name %> client with the default
70
- # configuration:
79
+ # # Create a client using the default configuration
80
+ # client = <%= service.client_name_full %>.new
71
81
  #
72
- # client = <%= service.client_name_full %>.new
73
- #
74
- # To create a new <%= service.name %> client with a custom
75
- # configuration:
76
- #
77
- # client = <%= service.client_name_full %>.new do |config|
78
- # config.timeout = 10.0
79
- # end
82
+ # # Create a client using a custom configuration
83
+ # client = <%= service.client_name_full %>.new do |config|
84
+ # config.timeout = 10.0
85
+ # end
80
86
  #
81
87
  # @yield [config] Configure the <%= service.name %> client.
82
88
  # @yieldparam config [<%= service.client_name %>::Configuration]
@@ -97,10 +103,9 @@ class <%= service.client_name %>
97
103
  # Create credentials
98
104
  credentials = @config.credentials
99
105
  <%- unless service.generic_endpoint? -%>
100
- # Use self-signed JWT if the scope and endpoint are unchanged from default,
106
+ # Use self-signed JWT if the endpoint is unchanged from default,
101
107
  # but only if the default endpoint does not have a region prefix.
102
- enable_self_signed_jwt = @config.scope == <%= service.client_name %>.configure.scope &&
103
- @config.endpoint == <%= service.client_name %>.configure.endpoint &&
108
+ enable_self_signed_jwt = @config.endpoint == <%= service.client_name %>.configure.endpoint &&
104
109
  !@config.endpoint.split(".").first.include?("-")
105
110
  credentials ||= Credentials.default scope: @config.scope,
106
111
  enable_self_signed_jwt: enable_self_signed_jwt
@@ -111,12 +116,15 @@ class <%= service.client_name %>
111
116
  @quota_project_id = @config.quota_project
112
117
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
113
118
 
114
- <%- if service.lro? -%>
115
- <%= service.lro_client_ivar %> = <%= service.operations_name %>.new do |config|
119
+ <%- if service.subclients? -%>
120
+ <%- service.subclients.each do |subclient| -%>
121
+ @<%= subclient.client_var_name %> = <%= subclient.client_class_name %>.new do |config|
116
122
  config.credentials = credentials
123
+ config.quota_project = @quota_project_id
117
124
  config.endpoint = @config.endpoint
118
125
  end
119
126
 
127
+ <%- end -%>
120
128
  <%- end -%>
121
129
  @<%= service.stub_name %> = ::Gapic::ServiceStub.new(
122
130
  <%= service.proto_service_stub_name_full %>,
@@ -127,20 +135,22 @@ class <%= service.client_name %>
127
135
  )
128
136
  end
129
137
 
130
- <%- if service.lro? -%>
138
+ <%- if service.subclients? -%>
139
+ <%- service.subclients.each do |subclient| -%>
131
140
  ##
132
- # Get the associated client for long-running operations.
141
+ # Get the associated client for <%= subclient.service_description %>.
133
142
  #
134
- # @return [<%= service.operations_name_full %>]
143
+ # @return [<%= subclient.client_class_docname %>]
135
144
  #
136
- attr_reader :<%= service.lro_client_var %>
145
+ attr_reader :<%= subclient.client_var_name %>
137
146
 
138
- <%- end -%>
147
+ <%- end -%>
148
+ <%- end -%>
139
149
  # Service calls
140
150
  <%- service.methods.each do |method| -%>
141
151
 
142
152
  <%= indent_tail render(partial: "service/client/method/def", locals: { method: method }), 2 %>
143
- <%- end %>
153
+ <%- end -%>
144
154
 
145
155
  <%= indent_tail render(partial: "service/client/config", locals: { service: service }), 2 %>
146
156
  end
@@ -14,22 +14,21 @@
14
14
  # on construction.
15
15
  #
16
16
  <%- unless method_service.methods.empty? -%>
17
- # # Examples
17
+ # @example
18
18
  #
19
- # To modify the global config, setting the timeout for <%= method_service.methods.first.name %>
20
- # to 20 seconds, and all remaining timeouts to 10 seconds:
19
+ # # Modify the global config, setting the timeout for
20
+ # # <%= method_service.methods.first.name %> to 20 seconds,
21
+ # # and all remaining timeouts to 10 seconds.
22
+ # <%= service.client_name_full %>.configure do |config|
23
+ # config.timeout = 10.0
24
+ # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
25
+ # end
21
26
  #
22
- # <%= service.client_name_full %>.configure do |config|
23
- # config.timeout = 10.0
24
- # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
25
- # end
26
- #
27
- # To apply the above configuration only to a new client:
28
- #
29
- # client = <%= service.client_name_full %>.new do |config|
30
- # config.timeout = 10.0
31
- # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
32
- # end
27
+ # # Apply the above configuration only to a new client.
28
+ # client = <%= service.client_name_full %>.new do |config|
29
+ # config.timeout = 10.0
30
+ # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
31
+ # end
33
32
  #
34
33
  <%- end -%>
35
34
  # @!attribute [rw] endpoint
@@ -0,0 +1,57 @@
1
+ <%- assert_locals service -%>
2
+ <% @requires = capture do %>
3
+ require "gapic/operation/retry_policy"
4
+ require "gapic/generic_lro/operation"
5
+ <% end %>
6
+
7
+ # A module containing nonstandard lro helpers
8
+ module <%= service.nonstandard_lro_name %>
9
+ class << self
10
+ ##
11
+ # Creates a Generic LRO operation object that wraps the nonstandard
12
+ # long-running operation specific to this service.
13
+ #
14
+ # @param operation [Object] The long-running operation object that is returned by the initial method call.
15
+ #
16
+ # @param client [<%= service.usable_service_presenter.client_name_full %>] The client that handles the polling for the longrunning operation.
17
+ #
18
+ # @param request_values [Map<String, String>] The values that are to be copied from the request that
19
+ # triggered the longrunning operation, into the request that polls for the longrunning operation.
20
+ # The format is `name of the request field -> value`
21
+ #
22
+ # @param options [Gapic::CallOptions] call options for this operation
23
+ #
24
+ # @return [Gapic::GenericLRO::Operation]
25
+ #
26
+ def create_operation operation:, client:, request_values:, options:
27
+ Gapic::GenericLRO::Operation.new(operation,
28
+ client: client,
29
+ polling_method_name: "<%= service.nonstandard_lro_polling_method_name %>",
30
+ request_values: request_values,
31
+ operation_status_field: "<%= service.nonstandard_lro.operation_status_field %>",
32
+ <%- if service.nonstandard_lro.operation_name_field -%>
33
+ operation_name_field: "<%= service.nonstandard_lro.operation_name_field %>",
34
+ <%- end -%>
35
+ <%- if service.nonstandard_lro.operation_err_code_field -%>
36
+ operation_err_code_field: "<%= service.nonstandard_lro.operation_err_code_field %>",
37
+ <%- end -%>
38
+ <%- if service.nonstandard_lro.operation_err_msg_field -%>
39
+ operation_err_msg_field: "<%= service.nonstandard_lro.operation_err_msg_field %>",
40
+ <%- end -%>
41
+ <%- if service.nonstandard_lro.operation_response_fields.any? -%>
42
+ operation_copy_fields: {
43
+ <%- service.nonstandard_lro.operation_response_fields.each_with_index do |(field_from, field_to), i| -%>
44
+ <%- if i == service.nonstandard_lro.operation_response_fields.length - 1 -%>
45
+ "<%= field_to %>" => "<%= field_from %>"
46
+ <%- else -%>
47
+ "<%= field_to %>" => "<%= field_from %>",
48
+ <%- end -%>
49
+ <%- end -%>
50
+ },
51
+ <%- else -%>
52
+ operation_copy_fields: {},
53
+ <%- end -%>
54
+ options: options)
55
+ end
56
+ end
57
+ end
@@ -1,7 +1,7 @@
1
1
  <%- assert_locals service -%>
2
2
  # Path helper methods for the <%= service.name %> API.
3
3
  module Paths
4
- <%- service.references.each do |resource| -%>
4
+ <%- service.deduped_references.each do |resource| -%>
5
5
  <%= indent render(partial: "service/client/resource", locals: { resource: resource }), 2 %>
6
6
 
7
7
  <%- end %>
@@ -6,7 +6,7 @@
6
6
  default_config.timeout = <%= format_number service.grpc_service_config.timeout_seconds %>
7
7
  <%- end -%>
8
8
  <%- if service.grpc_service_config.retry_policy -%>
9
- default_config.retry_policy = <%= indent_tail service.service_config_presenter.retry_policy_fields, 2 %>
9
+ default_config.retry_policy = <%= indent_tail service.grpc_service_config_presenter.retry_policy_fields, 2 %>
10
10
  <%- end -%>
11
11
  <%- end -%>
12
12
  <%- method_service.methods.each do |method| -%>
@@ -16,7 +16,7 @@
16
16
  default_config.rpcs.<%= method.name %>.timeout = <%= format_number method.grpc_service_config.timeout_seconds %>
17
17
  <%- end -%>
18
18
  <%- if method.grpc_service_config.retry_policy -%>
19
- default_config.rpcs.<%= method.name %>.retry_policy =<%= indent_tail method.service_config_presenter.retry_policy_fields, 2 %>
19
+ default_config.rpcs.<%= method.name %>.retry_policy =<%= indent_tail method.grpc_service_config_presenter.retry_policy_fields, 2 %>
20
20
  <%- end -%>
21
21
  <%- end -%>
22
22
  <%- end -%>
@@ -4,12 +4,14 @@
4
4
  <%= indent method.doc_description, "# " %>
5
5
  #
6
6
  <%- end -%>
7
+ <%= render partial: "service/client/method/docs/deprecated", locals: { method: method } -%>
7
8
  <%= render partial: "service/client/method/docs/request", locals: { method: method } -%>
8
9
  #
9
10
  <%= render partial: "service/client/method/docs/response", locals: { method: method } -%>
10
11
  #
11
12
  <%= render partial: "service/client/method/docs/error", locals: { method: method } -%>
12
13
  #
14
+ <%= render partial: "service/client/method/docs/snippets", locals: { method: method } -%>
13
15
  <%= render partial: "service/client/method/docs/samples", locals: { method: method } -%>
14
16
  def <%= method.name %> request, options = nil
15
17
  <%= indent render(partial: "service/client/method/def/request", locals: { method: method }), 2 %>
@@ -12,18 +12,13 @@ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
12
12
  metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
13
13
  <%- if method.routing_params? && !method.client_streaming? -%>
14
14
 
15
- header_params = {
16
- <%- method.routing_params.each_with_index do |routing_param, index| -%>
17
- <%- comma = index == method.routing_params.count - 1 ? "" : "," -%>
18
- "<%= routing_param %>" => request.<%= routing_param %><%= comma %>
19
- <%- end -%>
20
- }
21
- request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
22
- metadata[:"x-goog-request-params"] ||= request_params_header
15
+ <%= render partial: "service/client/method/def/routing_params", locals: { method: method } -%>
23
16
  <%- end -%>
24
17
 
25
18
  options.apply_defaults timeout: @config.rpcs.<%= method.name %>.timeout,
26
19
  metadata: metadata,
27
20
  retry_policy: @config.rpcs.<%= method.name %>.retry_policy
28
- options.apply_defaults metadata: @config.metadata,
21
+
22
+ options.apply_defaults timeout: @config.timeout,
23
+ metadata: @config.metadata,
29
24
  retry_policy: @config.retry_policy
@@ -1,6 +1,8 @@
1
1
  <%- assert_locals method -%>
2
2
  <%- if method.paged? -%>
3
3
  <%= render partial: "service/client/method/def/response_paged", locals: { method: method } -%>
4
+ <%- elsif method.rest.nonstandard_lro? -%>
5
+ <%= render partial: "service/client/method/def/response_nonstandard_lro", locals: { method: method } -%>
4
6
  <%- else -%>
5
7
  <%= render partial: "service/client/method/def/response_normal", locals: { method: method } -%>
6
8
  <%- end -%>
@@ -0,0 +1,23 @@
1
+ <%- assert_locals method -%>
2
+ @<%= method.service.stub_name %>.call_rpc :<%= method.name %>, request, options: options do |result, response|
3
+ result = <%= method.nonstandard_lro_client.helper_type %>.create_operation(
4
+ operation: result,
5
+ client: <%= method.nonstandard_lro_client.client_var_name %>,
6
+ <%- if method.lro.operation_request_fields.any? -%>
7
+ request_values: {
8
+ <%- method.lro.operation_request_fields.each_with_index do |(field_from, field_to), i| -%>
9
+ <%- if i == method.lro.operation_request_fields.length - 1 -%>
10
+ "<%= field_to %>" => request.<%= field_from %>
11
+ <%- else -%>
12
+ "<%= field_to %>" => request.<%= field_from %>,
13
+ <%- end -%>
14
+ <%- end -%>
15
+ },
16
+ <%- else -%>
17
+ request_values: {},
18
+ <%- end -%>
19
+ options: options
20
+ )
21
+ yield result, response if block_given?
22
+ return result
23
+ end
@@ -0,0 +1,36 @@
1
+ <%- assert_locals method -%>
2
+ header_params = {}
3
+ <%- if method.routing.explicit_params? -%>
4
+ <%- method.routing.explicit_params.each do |key_name, routing_infos| -%>
5
+ <%- routing_infos.each do |routing_info| -%>
6
+ <%- if routing_info.pattern_matching_not_needed? -%>
7
+ if request.<%= routing_info.field.gsub(".", "&.") %> && !request.<%= routing_info.field %>.empty?
8
+ header_params["<%= key_name %>"] = request.<%= routing_info.field %>
9
+ end
10
+ <%- elsif routing_info.value_is_full_field? -%>
11
+ if request.<%= routing_info.field.gsub(".", "&.") %> &&
12
+ %r{<%= routing_info.field_regex_str %>}.match?(request.<%= routing_info.field %>)
13
+ header_params["<%= key_name %>"] = request.<%= routing_info.field %>
14
+ end
15
+ <%- else -%>
16
+ if request.<%= routing_info.field.gsub(".", "&.") %>
17
+ regex_match = %r{<%= routing_info.field_full_regex_str %>}.match request.<%= routing_info.field %>
18
+ if regex_match
19
+ header_params["<%= key_name %>"] = regex_match["<%= key_name %>".to_s]
20
+ end
21
+ end
22
+ <%- end -%>
23
+ <%- end -%>
24
+ <%- end -%>
25
+
26
+ request_params_header = URI.encode_www_form header_params
27
+ <%- else -%>
28
+ <%- method.routing_params.each_with_index do |routing_param, index| -%>
29
+ if request.<%= routing_param.gsub(".", "&.") %>
30
+ header_params["<%= routing_param %>"] = request.<%= routing_param %>
31
+ end
32
+ <%- end -%>
33
+
34
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
35
+ <%- end -%>
36
+ metadata[:"x-goog-request-params"] ||= request_params_header
@@ -0,0 +1,5 @@
1
+ <%- assert_locals method -%>
2
+ <%- if method.is_deprecated? -%>
3
+ # @deprecated This method is deprecated and may be removed in the next major version update.
4
+ #
5
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ <%- assert_locals method -%>
2
+ <%- if method.generate_yardoc_snippets? -%>
3
+ # @example Basic example
4
+ <%= indent render(partial: "snippets/snippet/structure", locals: { snippet: method.snippet }), "# " %>
5
+ #
6
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ <%- assert_locals service -%>
2
+ <%= render partial: "service/client/nonstandard_lro",
3
+ layout: "layouts/ruby",
4
+ locals: { service: service,
5
+ namespace: service.methods_rest_bindings? ? service.rest.service_name_full : service.service_name_full }
6
+ %>
@@ -1,7 +1,15 @@
1
1
  <%- assert_locals service -%>
2
2
  <% @requires = capture do %>
3
- <%= render partial: "service/client/requires", locals: { service: service} -%>
4
- require "<%= service.proto_service_require %>"
3
+ <%= render partial: "service/client/requires", locals: { service: service} -%>
4
+ require "<%= service.proto_service_require %>"
5
+ require "<%= service.rest.service_stub_require %>"
6
+ <%- if service.subclients? -%>
7
+ <%- service.subclients.each do |subclient| -%>
8
+ <%- unless subclient.client_class_name == "Operations" -%>
9
+ require "<%= subclient.require_str %>"
10
+ <%- end -%>
11
+ <%- end -%>
12
+ <%- end -%>
5
13
  <% end %>
6
14
  ##
7
15
  # REST client for the <%= service.name %> service.
@@ -11,11 +19,10 @@
11
19
  #
12
20
  <%- end -%>
13
21
  class <%= service.rest.client_name %>
14
- include <%= service.rest.transcoding_helper_name %>
15
22
  <%- if service.paths? -%>
16
23
  include <%= service.paths_name %>
17
- <%- end -%>
18
24
 
25
+ <%- end -%>
19
26
  # @private
20
27
  attr_reader :<%= service.stub_name %>
21
28
 
@@ -25,13 +32,12 @@ class <%= service.rest.client_name %>
25
32
  # See {<%= service.rest.client_name_full %>::Configuration}
26
33
  # for a description of the configuration fields.
27
34
  #
28
- # ## Example
35
+ # @example
29
36
  #
30
- # To modify the configuration for all <%= service.name %> clients:
31
- #
32
- # <%= service.rest.client_name_full %>.configure do |config|
33
- # config.timeout = 10.0
34
- # end
37
+ # # Modify the configuration for all <%= service.name %> clients
38
+ # <%= service.rest.client_name_full %>.configure do |config|
39
+ # config.timeout = 10.0
40
+ # end
35
41
  #
36
42
  # @yield [config] Configure the <%= service.rest.client_name %> client.
37
43
  # @yieldparam config [<%= service.rest.client_name %>::Configuration]
@@ -65,28 +71,20 @@ class <%= service.rest.client_name %>
65
71
  ##
66
72
  # Create a new <%= service.name %> REST client object.
67
73
  #
68
- # ## Examples
69
- #
70
- # To create a new <%= service.name %> REST client with the default
71
- # configuration:
74
+ # @example
72
75
  #
73
- # client = <%= service.rest.client_name_full %>.new
76
+ # # Create a client using the default configuration
77
+ # client = <%= service.rest.client_name_full %>.new
74
78
  #
75
- # To create a new <%= service.name %> REST client with a custom
76
- # configuration:
77
- #
78
- # client = <%= service.rest.client_name_full %>.new do |config|
79
- # config.timeout = 10.0
80
- # end
79
+ # # Create a client using a custom configuration
80
+ # client = <%= service.rest.client_name_full %>.new do |config|
81
+ # config.timeout = 10.0
82
+ # end
81
83
  #
82
84
  # @yield [config] Configure the <%= service.name %> client.
83
85
  # @yieldparam config [<%= service.rest.client_name %>::Configuration]
84
86
  #
85
87
  def initialize
86
- # These require statements are intentionally placed here to initialize
87
- # the REST modules only when it's required.
88
- require "gapic/rest"
89
-
90
88
  # Create the configuration object
91
89
  @config = Configuration.new <%= service.rest.client_name %>.configure
92
90
 
@@ -102,14 +100,34 @@ class <%= service.rest.client_name %>
102
100
  end
103
101
  <%- end -%>
104
102
 
105
- @client_stub = ::Gapic::Rest::ClientStub.new endpoint: @config.endpoint, credentials: credentials
103
+ <%- if service.subclients? -%>
104
+ <%- service.subclients.each do |subclient| -%>
105
+ @<%= subclient.client_var_name %> = <%= subclient.client_class_name %>.new do |config|
106
+ config.credentials = credentials
107
+ config.endpoint = @config.endpoint
108
+ end
109
+
110
+ <%- end -%>
111
+ <%- end -%>
112
+ @<%= service.stub_name %> = <%= service.rest.service_stub_name_full %>.new endpoint: @config.endpoint, credentials: credentials
106
113
  end
107
114
 
115
+ <%- if service.subclients? -%>
116
+ <%- service.subclients.each do |subclient| -%>
117
+ ##
118
+ # Get the associated client for <%= subclient.service_description %>.
119
+ #
120
+ # @return [<%= subclient.client_class_docname %>]
121
+ #
122
+ attr_reader :<%= subclient.client_var_name %>
123
+
124
+ <%- end -%>
125
+ <%- end -%>
108
126
  # Service calls
109
127
  <%- service.methods.each do |method| -%>
110
128
 
111
129
  <%= indent_tail render(partial: "service/rest/client/method/def", locals: { method: method }), 2 %>
112
- <%- end %>
130
+ <%- end -%>
113
131
 
114
132
  <%= indent_tail render(partial: "service/rest/client/config", locals: { service: service }), 2 %>
115
133
  end
@@ -51,6 +51,9 @@
51
51
  # @!attribute [rw] timeout
52
52
  # The call timeout in seconds.
53
53
  # @return [::Numeric]
54
+ # @!attribute [rw] metadata
55
+ # Additional REST headers to be sent with the call.
56
+ # @return [::Hash{::Symbol=>::String}]
54
57
  #
55
58
  class Configuration
56
59
  extend ::Gapic::Config
@@ -64,6 +67,7 @@ class Configuration
64
67
  config_attr :lib_name, nil, ::String, nil
65
68
  config_attr :lib_version, nil, ::String, nil
66
69
  config_attr :timeout, nil, ::Numeric, nil
70
+ config_attr :metadata, nil, ::Hash, nil
67
71
 
68
72
  # @private
69
73
  def initialize parent_config = nil
@@ -71,4 +75,48 @@ class Configuration
71
75
 
72
76
  yield self if block_given?
73
77
  end
78
+
79
+ ##
80
+ # Configurations for individual RPCs
81
+ # @return [Rpcs]
82
+ #
83
+ def rpcs
84
+ @rpcs ||= begin
85
+ parent_rpcs = nil
86
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
87
+ Rpcs.new parent_rpcs
88
+ end
89
+ end
90
+
91
+ ##
92
+ # Configuration RPC class for the <%= service.name %> API.
93
+ #
94
+ # Includes fields providing the configuration for each RPC in this service.
95
+ # Each configuration object is of type `Gapic::Config::Method` and includes
96
+ # the following configuration fields:
97
+ #
98
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
99
+ #
100
+ # there is one other field (`retry_policy`) that can be set
101
+ # but is currently not supported for REST Gapic libraries.
102
+ #
103
+ class Rpcs
104
+ <%- method_service.methods.each do |method| -%>
105
+ ##
106
+ # RPC-specific configuration for `<%= method.name %>`
107
+ # @return [::Gapic::Config::Method]
108
+ #
109
+ attr_reader :<%= method.name %>
110
+ <%- end -%>
111
+
112
+ # @private
113
+ def initialize parent_rpcs = nil
114
+ <%- method_service.methods.each do |method| -%>
115
+ <%= method.name %>_config = parent_rpcs.<%= method.name %> if parent_rpcs.respond_to? :<%= method.name %>
116
+ @<%= method.name %> = ::Gapic::Config::Method.new <%= method.name %>_config
117
+ <%- end -%>
118
+
119
+ yield self if block_given?
120
+ end
121
+ end
74
122
  end
@@ -13,6 +13,6 @@ def <%= method.name %> request, options = nil
13
13
 
14
14
  <%= indent render(partial: "service/rest/client/method/def/options_defaults", locals: { method: method }), 2 %>
15
15
 
16
- <%= indent render(partial: "service/rest/client/method/def/response_normal", locals: { method: method }), 2 %>
16
+ <%= indent render(partial: "service/rest/client/method/def/response", locals: { method: method }), 2 %>
17
17
  <%= render partial: "service/rest/client/method/def/rescue", locals: { method: method } -%>
18
18
  end
@@ -3,7 +3,7 @@
3
3
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
4
4
 
5
5
  # Customize the options with defaults
6
- call_metadata = {}
6
+ call_metadata = @config.rpcs.<%= method.name %>.metadata.to_h
7
7
 
8
8
  # Set x-goog-api-client header
9
9
  call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
@@ -11,5 +11,8 @@ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
11
11
  gapic_version: ::<%= method.service.gem.version_name_full %>,
12
12
  transports_version_send: [:rest]
13
13
 
14
- options.apply_defaults timeout: @config.timeout,
14
+ options.apply_defaults timeout: @config.rpcs.<%= method.name %>.timeout,
15
15
  metadata: call_metadata
16
+
17
+ options.apply_defaults timeout: @config.timeout,
18
+ metadata: @config.metadata
@@ -0,0 +1,8 @@
1
+ <%- assert_locals method -%>
2
+ <%- if method.rest.paged? -%>
3
+ <%= render partial: "service/rest/client/method/def/response_paged", locals: { method: method } -%>
4
+ <%- elsif method.rest.nonstandard_lro? -%>
5
+ <%= render partial: "service/rest/client/method/def/response_nonstandard_lro", locals: { method: method } -%>
6
+ <%- else -%>
7
+ <%= render partial: "service/rest/client/method/def/response_normal", locals: { method: method } -%>
8
+ <%- end -%>
@@ -0,0 +1,23 @@
1
+ <%- assert_locals method -%>
2
+ @<%= method.service.stub_name %>.<%= method.name %> request, options do |result, response|
3
+ result = <%= method.nonstandard_lro_client.helper_type %>.create_operation(
4
+ operation: result,
5
+ client: <%= method.nonstandard_lro_client.client_var_name %>,
6
+ <%- if method.lro.operation_request_fields.any? -%>
7
+ request_values: {
8
+ <%- method.lro.operation_request_fields.each_with_index do |(field_from, field_to), i| -%>
9
+ <%- if i == method.lro.operation_request_fields.length - 1 -%>
10
+ "<%= field_to %>" => request.<%= field_from %>
11
+ <%- else -%>
12
+ "<%= field_to %>" => request.<%= field_from %>,
13
+ <%- end -%>
14
+ <%- end -%>
15
+ },
16
+ <%- else -%>
17
+ request_values: {},
18
+ <%- end -%>
19
+ options: options
20
+ )
21
+ yield result, response if block_given?
22
+ return result
23
+ end
@@ -1,17 +1,6 @@
1
1
  <%- assert_locals method -%>
2
2
 
3
- uri, <%= method.rest.body_var_name %>, <%= method.rest.query_string_params_var_name %> = <%= method.rest.transcoding_helper_name %> request
4
- response = @client_stub.make_<%= method.rest.verb %>_request(
5
- uri: uri,
6
- <%- if method.rest.body? -%>
7
- body: body,
8
- <%- end -%>
9
- <%- if method.rest.query_string_params? -%>
10
- params: query_string_params,
11
- <%- end -%>
12
- options: options
13
- )
14
- result = <%= method.return_type %>.decode_json response.body, ignore_unknown_fields: true
15
-
16
- yield result, response if block_given?
17
- result
3
+ @<%= method.service.stub_name %>.<%= method.name %> request, options do |result, response|
4
+ yield result, response if block_given?
5
+ return result
6
+ end