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
-
#encrypted_connect_token ⇒ String
The URL token received from Yoti Connect.
-
#endpoint ⇒ String
The API endpoint for the request.
-
#http_method ⇒ String
The allowed methods are: GET, DELETE, POST, PUT, PATCH.
-
#payload ⇒ Hash
The body sent with the request.
Instance Method Summary collapse
-
#add_header(header, value) ⇒ Object
Adds a HTTP header to the request.
-
#body ⇒ Hash
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.
19 20 21 |
# File 'lib/yoti/http/request.rb', line 19 def initialize @headers = {} end |
Instance Attribute Details
#encrypted_connect_token ⇒ String
Returns the URL token received from Yoti Connect.
7 8 9 |
# File 'lib/yoti/http/request.rb', line 7 def encrypted_connect_token @encrypted_connect_token end |
#endpoint ⇒ String
Returns the API endpoint for the request.
14 15 16 |
# File 'lib/yoti/http/request.rb', line 14 def endpoint @endpoint end |
#http_method ⇒ String
The allowed methods are: GET, DELETE, POST, PUT, PATCH
11 12 13 |
# File 'lib/yoti/http/request.rb', line 11 def http_method @http_method end |
#payload ⇒ Hash
Returns the body sent with the request.
17 18 19 |
# File 'lib/yoti/http/request.rb', line 17 def payload @payload end |
Instance Method Details
#add_header(header, value) ⇒ Object
Adds a HTTP header to the request
24 25 26 |
# File 'lib/yoti/http/request.rb', line 24 def add_header(header, value) @headers[header] = value end |
#body ⇒ Hash
Makes a HTTP request after signing the headers
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yoti/http/request.rb', line 30 def body raise RequestError, 'The request requires a HTTP method.' unless @http_method raise RequestError, 'The payload needs to be a hash.' unless @payload.to_s.empty? || @payload.is_a?(Hash) 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, "Unsuccessful Yoti API call: #{res.}" unless res.code == '200' res.body end |