class Yoti::RequestBuilder
Builder for {Request}
Public Class Methods
new()
click to toggle source
# File lib/yoti/http/request.rb, line 198 def initialize @headers = {} @query_params = {} end
Public Instance Methods
build()
click to toggle source
@return [Request]
# File lib/yoti/http/request.rb, line 288 def build request = Request.new request.base_url = @base_url request.endpoint = @endpoint request.query_params = @query_params request.http_method = @http_method request.payload = @payload @headers.map { |k, v| request.add_header(k, v) } request end
with_base_url(base_url)
click to toggle source
Sets the base URL
@param [String] base_url
@return [self]
# File lib/yoti/http/request.rb, line 210 def with_base_url(base_url) Validation.assert_is_a(String, base_url, 'base_url') @base_url = base_url self end
with_endpoint(endpoint)
click to toggle source
Sets the API endpoint for the request
@param [String] endpoint
@return [self]
# File lib/yoti/http/request.rb, line 266 def with_endpoint(endpoint) Validation.assert_is_a(String, endpoint, 'endpoint') @endpoint = endpoint self end
with_header(header, value)
click to toggle source
Adds a HTTP header to the request
@param [String] header @param [String] value
@return [self]
# File lib/yoti/http/request.rb, line 224 def with_header(header, value) Validation.assert_is_a(String, header, 'header') Validation.assert_is_a(String, value, 'value') @headers[header] = value self end
with_http_method(http_method)
click to toggle source
Sets the HTTP method
@param [String] http_method
@return [self]
# File lib/yoti/http/request.rb, line 253 def with_http_method(http_method) Validation.assert_is_a(String, http_method, 'http_method') @http_method = http_method self end
with_payload(payload)
click to toggle source
Sets the body sent with the request
@param [#to_json,String] payload
@return [self]
# File lib/yoti/http/request.rb, line 279 def with_payload(payload) Validation.assert_respond_to(:to_json, payload, 'payload') unless payload.is_a?(String) @payload = payload self end
with_query_param(key, value)
click to toggle source
Adds a query parameter to the request
@param [String] key @param [String] value
@return [self]
# File lib/yoti/http/request.rb, line 239 def with_query_param(key, value) Validation.assert_is_a(String, key, 'key') Validation.assert_is_a(String, value, 'value') @query_params[key] = value self end