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:



37
38
39
40
41
42
43
44
45
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 37

def initialize main_method, api
  @main_method = main_method
  @http_bindings = main_method.http_bindings
  @compute_pagination =
    if @main_method.service.special_compute_behavior?
      Gapic::Presenters::Method::RestPaginationInfo.new main_method.method, api
    end
  @type = "method"
end

Instance Attribute Details

#compute_paginationGapic::Presenters::Method::RestPaginationInfo (readonly)



26
27
28
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 26

def compute_pagination
  @compute_pagination
end

#http_bindingsObject (readonly)

Returns the value of attribute http_bindings.



28
29
30
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 28

def http_bindings
  @http_bindings
end

#typeString (readonly)

Returns String representation of this presenter type.

Returns:

  • (String)

    String representation of this presenter type.



31
32
33
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 31

def type
  @type
end

Instance Method Details

#can_generate_rest?Boolean

Whether this method can be generated in REST clients Only methods with http bindings can be generated, and additionally only unary methods are currently supported.

Returns:

  • (Boolean)


155
156
157
158
159
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 155

def can_generate_rest?
  [:normal, :server].include?(@main_method.kind) &&
    http_bindings.first&.verb? &&
    http_bindings.first&.path?
end

#doc_response_typeString

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

Returns:

  • (String)


95
96
97
98
99
100
101
102
103
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 95

def doc_response_type
  return "::Gapic::Operation" if lro?
  if paged?
    elem_type = compute_pagination&.paged_element_doc_type || @main_method.paged_response_type
    return "::Gapic::Rest::PagedEnumerable<#{elem_type}>"
  end
  return "::Gapic::GenericLRO::Operation" if nonstandard_lro?
  return_type
end

#grpc_full_nameString

Fully qualified proto name of the method (namespace.PascalCase)

Returns:

  • (String)


67
68
69
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 67

def grpc_full_name
  @main_method.grpc.full_name
end

#is_deprecated?Boolean

Returns Whether the method is marked as deprecated.

Returns:

  • (Boolean)

    Whether the method is marked as deprecated.



173
174
175
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 173

def is_deprecated?
  @main_method.is_deprecated?
end

#lro?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 125

def lro?
  @main_method.lro?
end

#nameString

Method name

Returns:

  • (String)


61
62
63
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 61

def name
  @main_method.name
end

#nonstandard_lro?Boolean

Whether this method uses nonstandard LROs

Returns:

  • (Boolean)


134
135
136
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 134

def nonstandard_lro?
  @main_method.nonstandard_lro?
end

#nonstandard_lro_clientGapic::Presenters::Service::LroClientPresenter?

The presenter for the nonstandard LRO client of the kind this method uses

Returns:

  • (Gapic::Presenters::Service::LroClientPresenter, nil)


143
144
145
146
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 143

def nonstandard_lro_client
  return unless nonstandard_lro?
  @main_method.service.rest.nonstandard_lros.find { |model| model.service == @main_method.lro.service_full_name }
end

#paged?Boolean

Whether the REGAPIC method should be rendered as paged

Returns:

  • (Boolean)


121
122
123
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 121

def paged?
  compute_pagination ? compute_pagination.paged? : @main_method.paged?
end

#paged_response_repeated_field_nameString

Returns The name of the repeated field in paginated responses.

Returns:

  • (String)

    The name of the repeated field in paginated responses



108
109
110
111
112
113
114
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 108

def paged_response_repeated_field_name
  if compute_pagination
    compute_pagination.response_repeated_field_name
  else
    @main_method.paged_response_repeated_field_name
  end
end

#request_typeString

Full class name of the request type

Returns:

  • (String)


76
77
78
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 76

def request_type
  @main_method.request_type
end

#return_typeString

Full class name of the raw return type of the RPC

Returns:

  • (String)


85
86
87
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 85

def return_type
  @main_method.return_type
end

#server_streaming?Boolean

Whether this method is a server-streaming method

Returns:

  • (Boolean)


166
167
168
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 166

def server_streaming?
  @main_method.server_streaming?
end

#transcoding_helper_nameString

Name for the GRPC transcoding helper method

Returns:

  • (String)


52
53
54
# File 'lib/gapic/presenters/method_rest_presenter.rb', line 52

def transcoding_helper_name
  "transcode_#{name}_request"
end