Class: AppleStoreInventoryChecker::ResultsList
- Inherits:
-
APIRequest
- Object
- APIRequest
- AppleStoreInventoryChecker::ResultsList
- Includes:
- Enumerable
- Defined in:
- lib/apple_store_inventory_checker/results_list.rb
Instance Attribute Summary collapse
-
#max_distance ⇒ Object
Returns the value of attribute max_distance.
-
#product_id ⇒ Object
Returns the value of attribute product_id.
-
#results ⇒ Object
Returns the value of attribute results.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(product_id, zip:, max_distance: 15.0) ⇒ ResultsList
constructor
A new instance of ResultsList.
- #refresh ⇒ Object
Constructor Details
#initialize(product_id, zip:, max_distance: 15.0) ⇒ ResultsList
Returns a new instance of ResultsList.
10 11 12 13 14 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 10 def initialize(product_id, zip:, max_distance: 15.0) @product_id = product_id @zip = zip @max_distance = max_distance end |
Instance Attribute Details
#max_distance ⇒ Object
Returns the value of attribute max_distance.
5 6 7 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 5 def max_distance @max_distance end |
#product_id ⇒ Object
Returns the value of attribute product_id.
6 7 8 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 6 def product_id @product_id end |
#results ⇒ Object
Returns the value of attribute results.
7 8 9 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 7 def results @results end |
#zip ⇒ Object
Returns the value of attribute zip.
8 9 10 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 8 def zip @zip end |
Instance Method Details
#each ⇒ Object
23 24 25 26 27 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 23 def each results.each do |result| yield(result) end end |
#refresh ⇒ Object
16 17 18 19 20 21 |
# File 'lib/apple_store_inventory_checker/results_list.rb', line 16 def refresh response = request(:get, query: { "parts.0" => @product_id, location: @zip }) raw_results = response.dig(:body, :stores) self.results = refresh_list_objects(raw_results, max_distance: @max_distance) self end |