Class: Gapic::Presenters::Method::HttpBindingPresenter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gapic/presenters/method/http_binding_presenter.rb

Overview

A presenter for the Http Binding, used to generate code setting up gRPC transcoding

Instance Method Summary collapse

Constructor Details

#initialize(binding) ⇒ HttpBindingPresenter

Returns a new instance of HttpBindingPresenter.



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

def initialize binding
  @binding = binding
end

Instance Method Details

#bodyString

Returns The body specified for this binding or an empty string if not specified.

Returns:

  • (String)

    The body specified for this binding or an empty string if not specified.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#body?Boolean

Returns Whether the binding has a body specified.

Returns:

  • (Boolean)

    Whether the binding has a body specified.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#pathString

Returns A binding path or an empty string if not present.

Returns:

  • (String)

    A binding path or an empty string if not present.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#path?Boolean

Returns Whether a binding path is present and non-empty.

Returns:

  • (Boolean)

    Whether a binding path is present and non-empty.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#routing_params?Boolean

Returns Whether any routing params are present for this bindings.

Returns:

  • (Boolean)

    Whether any routing params are present for this bindings.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#routing_params_transcoder_field_binding_stringsArray<String>

The strings to initialize the bindings parameter when initializing a gapic http binding. The bindings parameter is an array of FieldBinding objects, All strings except for the last one have a comma at the end.

Returns:

  • (Array<String>)


71
72
73
74
75
76
77
78
79
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 71

def routing_params_transcoder_field_binding_strings
  return [] if routing_params_with_regexes.empty?
  match_init_strings = routing_params_with_regexes.map do |name, regex, preserve_slashes|
    "Gapic::Rest::GrpcTranscoder::HttpBinding::FieldBinding" \
      ".new(\"#{name}\", %r{#{regex}}, #{preserve_slashes}),"
  end
  match_init_strings << match_init_strings.pop.chop # remove the trailing comma for the last element
  match_init_strings
end

#routing_params_transcoder_matches_stringsArray<String>

The strings to initialize the matches parameter when initializing a grpc transcoder binding. The matches parameter is an array of arrays, so every string here is in a ruby array syntax. All strings except for the last one have a comma at the end.

Returns:

  • (Array<String>)


55
56
57
58
59
60
61
62
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 55

def routing_params_transcoder_matches_strings
  return [] if routing_params_with_regexes.empty?
  match_init_strings = routing_params_with_regexes.map do |name, regex, preserve_slashes|
    "[\"#{name}\", %r{#{regex}}, #{preserve_slashes}],"
  end
  match_init_strings << match_init_strings.pop.chop # remove the trailing comma for the last element
  match_init_strings
end

#uri_for_transcodingString

Performs a limited URI 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)

    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



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

def uri_for_transcoding
  return path unless routing_params?

  @binding.routing_params.reduce path do |uri, param|
    param_esc = Regexp.escape param
    uri.gsub(/{#{param_esc}[^}]*}/, "{#{param}}")
  end
end

#verbString

Returns The http verb for this binding.

Returns:

  • (String)

    The http verb for this binding.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#verb?Boolean

Returns Whether a http verb is present for this binding.

Returns:

  • (Boolean)

    Whether a http verb is present for this binding.



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body