Class: Yoti::Request
- Inherits:
-
Object
- Object
- Yoti::Request
- Defined in:
- lib/yoti/http/request.rb
Overview
Manage the API’s HTTPS requests
Instance Attribute Summary collapse
-
#base_url ⇒ String
The base URL.
-
#encrypted_connect_token ⇒ String
deprecated
Deprecated.
will be removed in 2.0.0 - token is now provided with the endpoint
-
#endpoint ⇒ String
The API endpoint for the request.
-
#http_method ⇒ String
The allowed methods are: GET, DELETE, POST, PUT, PATCH.
-
#payload ⇒ #to_json, String
The body sent with the request.
-
#query_params ⇒ Hash
Query params to add to the request.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_header(header, value) ⇒ Object
Adds a HTTP header to the request.
-
#body ⇒ String
Makes a HTTP request and returns the body after signing the headers.
-
#execute ⇒ HTTPResponse
Makes a HTTP request after signing the headers.
-
#initialize ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
27 28 29 |
# File 'lib/yoti/http/request.rb', line 27 def initialize @headers = {} end |
Instance Attribute Details
#base_url ⇒ String
Returns the base URL.
78 79 80 |
# File 'lib/yoti/http/request.rb', line 78 def base_url @base_url ||= Yoti.configuration.api_endpoint end |
#encrypted_connect_token ⇒ String
will be removed in 2.0.0 - token is now provided with the endpoint
Returns the URL token received from Yoti Connect.
9 10 11 |
# File 'lib/yoti/http/request.rb', line 9 def encrypted_connect_token @encrypted_connect_token end |
#endpoint ⇒ String
Returns the API endpoint for the request.
22 23 24 |
# File 'lib/yoti/http/request.rb', line 22 def endpoint @endpoint end |
#http_method ⇒ String
The allowed methods are: GET, DELETE, POST, PUT, PATCH
19 20 21 |
# File 'lib/yoti/http/request.rb', line 19 def http_method @http_method end |
#payload ⇒ #to_json, String
Returns the body sent with the request.
25 26 27 |
# File 'lib/yoti/http/request.rb', line 25 def payload @payload end |
#query_params ⇒ Hash
Returns query params to add to the request.
15 16 17 |
# File 'lib/yoti/http/request.rb', line 15 def query_params @query_params end |
Class Method Details
.builder ⇒ RequestBuilder
34 35 36 |
# File 'lib/yoti/http/request.rb', line 34 def self.builder RequestBuilder.new end |
Instance Method Details
#add_header(header, value) ⇒ Object
Adds a HTTP header to the request
44 45 46 |
# File 'lib/yoti/http/request.rb', line 44 def add_header(header, value) @headers[header] = value end |
#body ⇒ String
Makes a HTTP request and returns the body after signing the headers
71 72 73 |
# File 'lib/yoti/http/request.rb', line 71 def body execute.body end |
#execute ⇒ HTTPResponse
Makes a HTTP request after signing the headers
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/yoti/http/request.rb', line 53 def execute raise RequestError, 'The request requires a HTTP method.' unless @http_method http_res = Net::HTTP.start(uri.hostname, Yoti.configuration.api_port, use_ssl: https_uri?) do |http| signed_request = SignedRequest.new(unsigned_request, path, @payload).sign http.request(signed_request) end raise RequestError.new("Unsuccessful Yoti API call: #{http_res.}", http_res) unless response_is_success(http_res) http_res end |