Class: ShopsavvyDataApi::ProductSearchResult
- Inherits:
-
Object
- Object
- ShopsavvyDataApi::ProductSearchResult
- Defined in:
- lib/shopsavvy_data_api/models.rb
Overview
Product search result with pagination
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#pagination ⇒ Object
readonly
Returns the value of attribute pagination.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #credits_remaining ⇒ Object
- #credits_used ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(response_data) ⇒ ProductSearchResult
constructor
A new instance of ProductSearchResult.
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(response_data) ⇒ ProductSearchResult
Returns a new instance of ProductSearchResult.
452 453 454 455 456 457 |
# File 'lib/shopsavvy_data_api/models.rb', line 452 def initialize(response_data) @success = response_data["success"] @meta = response_data["meta"] ? APIMeta.new(response_data["meta"]) : nil @pagination = response_data["pagination"] ? PaginationInfo.new(response_data["pagination"]) : nil @data = (response_data["data"] || []).map { |item| ProductDetails.new(item) } end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
450 451 452 |
# File 'lib/shopsavvy_data_api/models.rb', line 450 def data @data end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
450 451 452 |
# File 'lib/shopsavvy_data_api/models.rb', line 450 def @meta end |
#pagination ⇒ Object (readonly)
Returns the value of attribute pagination.
450 451 452 |
# File 'lib/shopsavvy_data_api/models.rb', line 450 def pagination @pagination end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
450 451 452 |
# File 'lib/shopsavvy_data_api/models.rb', line 450 def success @success end |
Instance Method Details
#credits_remaining ⇒ Object
463 464 465 |
# File 'lib/shopsavvy_data_api/models.rb', line 463 def credits_remaining &.credits_remaining || 0 end |
#credits_used ⇒ Object
459 460 461 |
# File 'lib/shopsavvy_data_api/models.rb', line 459 def credits_used &.credits_used || 0 end |
#failure? ⇒ Boolean
471 472 473 |
# File 'lib/shopsavvy_data_api/models.rb', line 471 def failure? !success? end |
#success? ⇒ Boolean
467 468 469 |
# File 'lib/shopsavvy_data_api/models.rb', line 467 def success? success == true end |
#to_h ⇒ Object
475 476 477 478 479 480 481 482 |
# File 'lib/shopsavvy_data_api/models.rb', line 475 def to_h { success: success, data: data.map(&:to_h), pagination: pagination&.to_h, meta: &.to_h } end |