Class: Gapic::Presenters::MethodRestPresenter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(main_method, api) ⇒ MethodRestPresenter

Returns a new instance of MethodRestPresenter.

Parameters:



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

#paginationGapic::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.

Returns:

  • (Boolean)

    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"

Parameters:

  • request_obj_name (String) (defaults to: "request_pb")

    the name of the request object for the interpolation defaults to "request_pb"

Returns:

  • (String)

    A string to interpolate values from the request object into body



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.

Returns:

  • (Boolean)

    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_nameString

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

Returns:

  • (String)


105
106
107
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 105

def body_var_name
  body? ? "body" : "_body"
end

#doc_response_typeString

Full class name of the return type of the method (including LRO and Paged cases)

Returns:

  • (String)


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

#nameString

Method name

Returns:

  • (String)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

    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_paramsArray<String>

Returns:

  • (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.

Returns:

  • (Boolean)

    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_nameString

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

Returns:

  • (String)


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_typeString

Full class name of the request type

Returns:

  • (String)


185
186
187
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 185

def request_type
  @main_method.request_type
end

#return_typeString

Full class name of the raw return type of the RPC

Returns:

  • (String)


194
195
196
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 194

def return_type
  @main_method.return_type
end

#routing_paramsArray<String>

Returns The segment key names.

Returns:

  • (Array<String>)

    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.

Returns:

  • (Boolean)

    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_nameString

Name for the GRPC transcoding helper method

Returns:

  • (String)


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"

Parameters:

  • request_obj_name (String) (defaults to: "request_pb")

    the name of the request object for the interpolation defaults to "request_pb"

Returns:

  • (String)

    A string to interpolate values from the request object into URI



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

#verbSymbol

Returns a http verb for this method.

Returns:

  • (Symbol)

    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.

Returns:

  • (Boolean)

    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