Class: Yoti::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/yoti/http/request.rb

Overview

Manage the API’s HTTPS requests

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

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_urlString

Returns the base URL.

Returns:

  • (String)

    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_tokenString

Deprecated.

will be removed in 2.0.0 - token is now provided with the endpoint

Returns the URL token received from Yoti Connect.

Returns:

  • (String)

    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

#endpointString

Returns the API endpoint for the request.

Returns:

  • (String)

    the API endpoint for the request



22
23
24
# File 'lib/yoti/http/request.rb', line 22

def endpoint
  @endpoint
end

#http_methodString

The allowed methods are: GET, DELETE, POST, PUT, PATCH

Returns:

  • (String)

    the HTTP method used for the request



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.

Returns:

  • (#to_json, String)

    the body sent with the request



25
26
27
# File 'lib/yoti/http/request.rb', line 25

def payload
  @payload
end

#query_paramsHash

Returns query params to add to the request.

Returns:

  • (Hash)

    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

.builderRequestBuilder

Returns:



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

Parameters:

  • header (String)
  • value (String)


44
45
46
# File 'lib/yoti/http/request.rb', line 44

def add_header(header, value)
  @headers[header] = value
end

#bodyString

Makes a HTTP request and returns the body after signing the headers

Returns:

  • (String)


71
72
73
# File 'lib/yoti/http/request.rb', line 71

def body
  execute.body
end

#executeHTTPResponse

Makes a HTTP request after signing the headers

Returns:

  • (HTTPResponse)

Raises:



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.message}", http_res) unless response_is_success(http_res)

  http_res
end