Class: Gapic::Presenters::MethodRestPresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::MethodRestPresenter
- Defined in:
- lib/gapic/presenters/method_rest_presenter.rb
Overview
A presenter for rpc methods (REST submethods)
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#body? ⇒ Boolean
Whether method has body specified in proto.
-
#body_interpolated(request_obj_name = "request_pb") ⇒ String
Performs a limited version of grpc transcoding to create a string that will interpolate the values from the request object to create a request body at runtime.
-
#body_is_request_object? ⇒ Boolean
True if body contains full request object (
*in the annotation), false otherwise. -
#body_var_name ⇒ String
Name of the variable to use for storing the body result of the transcoding call Normally "body" but use "_body" for discarding the result for the calls that do not send body.
-
#doc_response_type ⇒ String
Full class name of the return type of the method (including LRO and Paged cases).
-
#initialize(main_method, api) ⇒ MethodRestPresenter
constructor
A new instance of MethodRestPresenter.
-
#name ⇒ String
Method name.
-
#nonstandard_lro? ⇒ Boolean
Whether this method uses nonstandard LROs.
-
#paged? ⇒ Boolean
Whether the REGAPIC method should be rendered as paged.
-
#path? ⇒ Boolean
Whether a method path is present and non-empty.
- #query_string_params ⇒ Array<String>
-
#query_string_params? ⇒ Boolean
Whether any query string parameters are present.
-
#query_string_params_var_name ⇒ String
Name of the variable to use for storing the query_string_params result of the transcoding call Normally "query_string_params" but use "_query_string_params" for discarding the result for the calls that do not sent query_string_params.
-
#request_type ⇒ String
Full class name of the request type.
-
#return_type ⇒ String
Full class name of the raw return type of the RPC.
-
#routing_params ⇒ Array<String>
The segment key names.
-
#routing_params? ⇒ Boolean
Whether any routing params are present.
-
#transcoding_helper_name ⇒ String
Name for the GRPC transcoding helper method.
-
#uri_interpolated(request_obj_name = "request_pb") ⇒ String
Performs a limited version of grpc transcoding to create a string that will interpolate the values from the request object to create a request URI at runtime.
-
#verb ⇒ Symbol
A http verb for this method.
-
#verb? ⇒ Boolean
Whether a http verb is present for this method.
Constructor Details
#initialize(main_method, api) ⇒ MethodRestPresenter
Returns a new instance of MethodRestPresenter.
32 33 34 35 36 37 38 39 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 32 def initialize main_method, api @api = api @main_method = main_method @proto_method = main_method.method @http = main_method.http @pagination = Gapic::Presenters::Method::RestPaginationInfo.new @proto_method, api end |
Instance Attribute Details
#pagination ⇒ Gapic::Presenters::Method::RestPaginationInfo (readonly)
26 27 28 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 26 def pagination @pagination end |
Instance Method Details
#body? ⇒ Boolean
Returns Whether method has body specified in proto.
79 80 81 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 79 def body? @http.body? end |
#body_interpolated(request_obj_name = "request_pb") ⇒ String
Performs a limited version of grpc transcoding to create a string that will interpolate the values from the request object to create a request body at runtime. Currently only supports either "*" for "the whole request object" or "value" for "request_object.value"
127 128 129 130 131 132 133 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 127 def body_interpolated request_obj_name = "request_pb" return "\"\"" unless body? return "#{request_obj_name}.to_json" if body_is_request_object? "#{request_obj_name}.#{body}.to_json" end |
#body_is_request_object? ⇒ Boolean
Returns True if body contains full request object (* in the annotation), false otherwise.
112 113 114 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 112 def body_is_request_object? body == "*" end |
#body_var_name ⇒ String
Name of the variable to use for storing the body result of the transcoding call Normally "body" but use "_body" for discarding the result for the calls that do not send body
105 106 107 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 105 def body_var_name body? ? "body" : "_body" end |
#doc_response_type ⇒ String
Full class name of the return type of the method (including LRO and Paged cases)
204 205 206 207 208 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 204 def doc_response_type return "::Gapic::Rest::PagedEnumerable<#{pagination.paged_element_doc_type}>" if paged? return "::Gapic::GenericLRO::Operation" if nonstandard_lro? return_type end |
#name ⇒ String
Method name
176 177 178 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 176 def name @main_method.name end |
#nonstandard_lro? ⇒ Boolean
Whether this method uses nonstandard LROs
224 225 226 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 224 def nonstandard_lro? @main_method.nonstandard_lro? end |
#paged? ⇒ Boolean
Whether the REGAPIC method should be rendered as paged
215 216 217 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 215 def paged? @pagination.paged? end |
#path? ⇒ Boolean
Returns Whether a method path is present and non-empty.
58 59 60 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 58 def path? @http.path? end |
#query_string_params ⇒ Array<String>
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 143 def query_string_params return [] if body_is_request_object? routing_params_set = routing_params.to_set @main_method.arguments .reject { |arg| routing_params_set.include? arg.name } .reject { |arg| body == arg.name } .reject(&:message?) .reject { |arg| arg.default_value_for_type.nil? } end |
#query_string_params? ⇒ Boolean
Returns whether any query string parameters are present.
138 139 140 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 138 def query_string_params? query_string_params.any? end |
#query_string_params_var_name ⇒ String
Name of the variable to use for storing the query_string_params result of the transcoding call Normally "query_string_params" but use "_query_string_params" for discarding the result for the calls that do not sent query_string_params
159 160 161 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 159 def query_string_params_var_name query_string_params? ? "query_string_params" : "_query_string_params" end |
#request_type ⇒ String
Full class name of the request type
185 186 187 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 185 def request_type @main_method.request_type end |
#return_type ⇒ String
Full class name of the raw return type of the RPC
194 195 196 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 194 def return_type @main_method.return_type end |
#routing_params ⇒ Array<String>
Returns The segment key names.
72 73 74 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 72 def routing_params @http.routing_params end |
#routing_params? ⇒ Boolean
Returns Whether any routing params are present.
65 66 67 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 65 def routing_params? @http.routing_params? end |
#transcoding_helper_name ⇒ String
Name for the GRPC transcoding helper method
167 168 169 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 167 def transcoding_helper_name "transcode_#{name}_request" end |
#uri_interpolated(request_obj_name = "request_pb") ⇒ String
Performs a limited version of grpc transcoding to create a string that will interpolate the values from the request object to create a request URI at runtime. Currently only supports "value" into "request_object.value"
91 92 93 94 95 96 97 98 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 91 def uri_interpolated request_obj_name = "request_pb" return path unless routing_params? routing_params.reduce path do |uri, param| param_esc = Regexp.escape param uri.gsub(/{#{param_esc}[^}]*}/, "\#{#{request_obj_name}.#{param}}") end end |
#verb ⇒ Symbol
Returns a http verb for this method.
51 52 53 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 51 def verb @http.verb end |
#verb? ⇒ Boolean
Returns Whether a http verb is present for this method.
44 45 46 |
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 44 def verb? @http.verb? end |