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.



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

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.



22
23
24
# File 'lib/minfraud/http_service/response.rb', line 22

def body
  @body
end

#statusFixnum? (readonly)

Response HTTP status code.

Returns:

  • (Fixnum, nil)


16
17
18
# File 'lib/minfraud/http_service/response.rb', line 16

def status
  @status
end

Instance Method Details

#codeSymbol?

Return the minFraud-specific response code.

Returns:

  • (Symbol, nil)


47
48
49
50
51
# File 'lib/minfraud/http_service/response.rb', line 47

def code
  return nil if body.nil?

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