Class: Minfraud::HTTPService::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/minfraud/http_service/response.rb

Overview

Response class for HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, locales, response, body) ⇒ Response

Returns a new instance of Response.

Parameters:

  • endpoint (Symbol, nil)

    endpoint name, like :score.

  • locales (Array<String>, nil)

    locales, like ["en"].

  • response (HTTP::Response)

    the response object.

  • body (String)

    the response body.

Raises:

  • (JSON::ParserError)

    if there was invalid JSON in the response.



35
36
37
38
39
40
41
42
43
44
# File 'lib/minfraud/http_service/response.rb', line 35

def initialize(endpoint, locales, response, body)
  @status = response.code

  @body = make_body(
    endpoint,
    locales,
    response,
    body,
  )
end

Instance Attribute Details

#bodyMinfraud::Model::Score, ... (readonly)

Response model.



24
25
26
# File 'lib/minfraud/http_service/response.rb', line 24

def body
  @body
end

#statusInteger? (readonly)

Response HTTP status code.

Returns:

  • (Integer, nil)


18
19
20
# File 'lib/minfraud/http_service/response.rb', line 18

def status
  @status
end

Instance Method Details

#codeSymbol?

Return the minFraud-specific response code.

Returns:

  • (Symbol, nil)


49
50
51
52
53
# File 'lib/minfraud/http_service/response.rb', line 49

def code
  return nil if body.nil?

  body.code.intern if body.respond_to?(:code) && body.code
end