Class: Gapic::Model::Method::HttpAnnotation

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/model/method/http_annotation.rb

Overview

The information used in the generation process that can be gathered from the google.api.http annotation. google.api.http is used in two distinct ways:

  • the rest libs use it as part of the transcoding to set up the REST call
  • both rest and grpc libs use it as a source of implicit routing headers

Instance Method Summary collapse

Constructor Details

#initialize(proto_method) ⇒ HttpAnnotation

Returns a new instance of HttpAnnotation.

Parameters:



33
34
35
# File 'lib/gapic/model/method/http_annotation.rb', line 33

def initialize proto_method
  @proto_method = proto_method
end

Instance Method Details

#bodyString

The body specified for the given method in proto or an empty string if not specified

Returns:

  • (String)


117
118
119
# File 'lib/gapic/model/method/http_annotation.rb', line 117

def body
  @proto_method.http&.body || ""
end

#body?Boolean

Whether method has body specified in proto

Returns:

  • (Boolean)


106
107
108
109
110
# File 'lib/gapic/model/method/http_annotation.rb', line 106

def body?
  return false if @proto_method.http.nil?

  !@proto_method.http.body.empty?
end

#pathString

A method path or an empty string if not present

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
84
# File 'lib/gapic/model/method/http_annotation.rb', line 75

def path
  return "" if @proto_method.http.nil?

  verb_path = [
    @proto_method.http.get, @proto_method.http.post, @proto_method.http.put,
    @proto_method.http.patch, @proto_method.http.delete
  ].find { |x| !x.empty? }

  verb_path || @proto_method.http.custom&.path || ""
end

#path?Boolean

Whether a method path is present and non-empty

Returns:

  • (Boolean)


67
68
69
# File 'lib/gapic/model/method/http_annotation.rb', line 67

def path?
  !path.empty?
end

#routing_paramsArray<String>

The segment key names.

Returns:

  • (Array<String>)


98
99
100
# File 'lib/gapic/model/method/http_annotation.rb', line 98

def routing_params
  Gapic::UriTemplate.parse_arguments path
end

#routing_params?Boolean

Whether any routing params are present

Returns:

  • (Boolean)


90
91
92
# File 'lib/gapic/model/method/http_annotation.rb', line 90

def routing_params?
  routing_params.any?
end

#verbSymbol, Nil

The http verb for this method

Returns:

  • (Symbol, Nil)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gapic/model/method/http_annotation.rb', line 49

def verb
  return nil if @proto_method.http.nil?

  method = {
    get:    @proto_method.http.get,
    post:   @proto_method.http.post,
    put:    @proto_method.http.put,
    patch:  @proto_method.http.patch,
    delete: @proto_method.http.delete
  }.find { |_, value| !value.empty? }

  method[0] unless method.nil?
end

#verb?Boolean

Whether a http verb is present for this method

Returns:

  • (Boolean)


41
42
43
# File 'lib/gapic/model/method/http_annotation.rb', line 41

def verb?
  !verb.nil?
end