Class: Loqate::APIResult

Inherits:
Object
  • Object
show all
Defined in:
lib/loqate/api_result.rb

Overview

Generic response of a request to Loqate’s API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ APIResult

Instantiates a new API result

Parameters:

  • items (Array<Hash>)

    Array of hashes representing each item in the response body



14
15
16
# File 'lib/loqate/api_result.rb', line 14

def initialize(items)
  @items = items
end

Instance Attribute Details

#itemsArray<Hash> (readonly)

Array of hashes representing each item in the response body

Returns:

  • (Array<Hash>)


8
9
10
# File 'lib/loqate/api_result.rb', line 8

def items
  @items
end

Class Method Details

.error(status:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/loqate/api_result.rb', line 18

def self.error(status:)
  new(
    [
      {
        'Error' => '-2',
        'Description' => 'Something went wrong - please try again later',
        'Resolution' => 'Try again later',
        'Cause' => "Server returned response with #{status}"
      }
    ]
  )
end

Instance Method Details

#errors?Boolean

Whether the response contains errors

Returns:

  • (Boolean)

    true if the response has errors and false otherwise



35
36
37
# File 'lib/loqate/api_result.rb', line 35

def errors?
  !items.dig(0, 'Error').nil?
end