Class: Loqate::APIResult
- Inherits:
-
Object
- Object
- Loqate::APIResult
- Defined in:
- lib/loqate/api_result.rb
Overview
Generic response of a request to Loqate’s API
Instance Attribute Summary collapse
-
#items ⇒ Array<Hash>
readonly
Array of hashes representing each item in the response body.
Class Method Summary collapse
Instance Method Summary collapse
-
#errors? ⇒ Boolean
Whether the response contains errors.
-
#initialize(items) ⇒ APIResult
constructor
Instantiates a new API result.
Constructor Details
#initialize(items) ⇒ APIResult
Instantiates a new API result
14 15 16 |
# File 'lib/loqate/api_result.rb', line 14 def initialize(items) @items = items end |
Instance Attribute Details
#items ⇒ Array<Hash> (readonly)
Array of hashes representing each item in the response body
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
35 36 37 |
# File 'lib/loqate/api_result.rb', line 35 def errors? !items.dig(0, 'Error').nil? end |