Class: HttpClientGenerator::Resource
- Inherits:
-
Object
- Object
- HttpClientGenerator::Resource
- Defined in:
- lib/http_client_generator/resource.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#req_plugs ⇒ Object
readonly
Returns the value of attribute req_plugs.
-
#resp_plugs ⇒ Object
readonly
Returns the value of attribute resp_plugs.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(verb:, content_type:, name:, base:, req_plugs:, resp_plugs:) ⇒ Resource
constructor
A new instance of Resource.
- #perform_request(url_helper, url_options, body, rest_args) ⇒ Object
Constructor Details
#initialize(verb:, content_type:, name:, base:, req_plugs:, resp_plugs:) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 13 14 15 16 |
# File 'lib/http_client_generator/resource.rb', line 9 def initialize(verb:, content_type:, name:, base:, req_plugs:, resp_plugs:) @verb = verb @base = base @content_type = content_type @name = name @req_plugs = req_plugs @resp_plugs = resp_plugs end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def base @base end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def content_type @content_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def name @name end |
#req_plugs ⇒ Object (readonly)
Returns the value of attribute req_plugs.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def req_plugs @req_plugs end |
#resp_plugs ⇒ Object (readonly)
Returns the value of attribute resp_plugs.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def resp_plugs @resp_plugs end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
7 8 9 |
# File 'lib/http_client_generator/resource.rb', line 7 def verb @verb end |
Instance Method Details
#perform_request(url_helper, url_options, body, rest_args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/http_client_generator/resource.rb', line 18 def perform_request(url_helper, , body, rest_args) request = prepare_request(url_helper, , body, rest_args) request_attributes = [request.verb, request.url] if request.body request.body = request.body.to_json if request.json? request_attributes << { body: request.body } end request.response_body = HTTP[request.current_headers].public_send(*request_attributes).to_s process_response(request) rescue HTTP::Error => e request.raise_error(e) end |