Module: Requesting
Overview
Module in charge of constructing requests and saving responses
Instance Method Summary collapse
- #add_header(k, v) ⇒ Object
- #add_request_param(k, v) ⇒ Object
-
#client ⇒ Object
return Faraday client object so that it could be used directly or passed to another object.
- #headers ⇒ Object
- #params ⇒ Object
-
#parse_method(method) ⇒ Object
Utility Methods.
-
#reset_request ⇒ Object
clear out any previously built request state and set defaults.
-
#response ⇒ Object
getter for the latest response returned.
-
#send_request(method, url) ⇒ Object
send a request using method to url using whatever options have been built for the present request.
- #set_client(client) ⇒ Object
-
#set_request_body(obj) ⇒ Object
store the provided body in the request options being built overriding any previously provided object.
Methods included from ClientBuilding
#client_for_host, #connection_handlers, #use_oauth2_token, #with_oauth2_token
Instance Method Details
#add_header(k, v) ⇒ Object
145 146 147 |
# File 'lib/brine/requester.rb', line 145 def add_header(k, v) headers[k] = v end |
#add_request_param(k, v) ⇒ Object
153 154 155 |
# File 'lib/brine/requester.rb', line 153 def add_request_param(k, v) params[k] = v end |
#client ⇒ Object
return Faraday client object so that it could be used directly or passed to another object
112 113 114 115 |
# File 'lib/brine/requester.rb', line 112 def client @client ||= client_for_host(brine_root_url || 'http://localhost:8080', logging: ENV['BRINE_LOG_HTTP']) end |
#headers ⇒ Object
141 142 143 |
# File 'lib/brine/requester.rb', line 141 def headers @headers ||= {content_type: 'application/json'} end |
#params ⇒ Object
149 150 151 |
# File 'lib/brine/requester.rb', line 149 def params @params ||= {} end |
#parse_method(method) ⇒ Object
Utility Methods
Normalize an HTTP method passed from a specification into a form expected by the HTTP client library (lowercased symbol)
102 103 104 |
# File 'lib/brine/requester.rb', line 102 def parse_method(method) method.downcase.to_sym end |
#reset_request ⇒ Object
clear out any previously built request state and set defaults
118 119 120 |
# File 'lib/brine/requester.rb', line 118 def reset_request @params = @headers = @body = nil end |
#response ⇒ Object
getter for the latest response returned
137 138 139 |
# File 'lib/brine/requester.rb', line 137 def response @response end |
#send_request(method, url) ⇒ Object
send a request using method to url using whatever options have been built for the present request
130 131 132 133 134 |
# File 'lib/brine/requester.rb', line 130 def send_request(method, url) @response = client.run_request(method, url, @body, headers) do |req| req.params = params end end |
#set_client(client) ⇒ Object
106 107 108 |
# File 'lib/brine/requester.rb', line 106 def set_client(client) @client = client end |
#set_request_body(obj) ⇒ Object
store the provided body in the request options being built overriding any previously provided object
124 125 126 |
# File 'lib/brine/requester.rb', line 124 def set_request_body(obj) @body = obj end |