Class: Gapic::Model::Method::HttpAnnotation
- Inherits:
-
Object
- Object
- Gapic::Model::Method::HttpAnnotation
- 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
-
#body ⇒ String
The body specified for the given method in proto or an empty string if not specified.
-
#body? ⇒ Boolean
Whether method has body specified in proto.
-
#initialize(proto_method) ⇒ HttpAnnotation
constructor
A new instance of HttpAnnotation.
-
#path ⇒ String
A method path or an empty string if not present.
-
#path? ⇒ Boolean
Whether a method path is present and non-empty.
-
#routing_params ⇒ Array<String>
The segment key names.
-
#routing_params? ⇒ Boolean
Whether any routing params are present.
-
#verb ⇒ Symbol, Nil
The http verb for this method.
-
#verb? ⇒ Boolean
Whether a http verb is present for this method.
Constructor Details
#initialize(proto_method) ⇒ HttpAnnotation
Returns a new instance of HttpAnnotation.
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
#body ⇒ String
The body specified for the given method in proto or an empty string if not specified
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
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 |
#path ⇒ String
A method path or an empty string if not present
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
67 68 69 |
# File 'lib/gapic/model/method/http_annotation.rb', line 67 def path? !path.empty? end |
#routing_params ⇒ Array<String>
The segment key names.
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
90 91 92 |
# File 'lib/gapic/model/method/http_annotation.rb', line 90 def routing_params? routing_params.any? end |
#verb ⇒ Symbol, Nil
The http verb for this method
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
41 42 43 |
# File 'lib/gapic/model/method/http_annotation.rb', line 41 def verb? !verb.nil? end |