Class: ShopsavvyDataApi::Offer

Inherits:
Object
  • Object
show all
Defined in:
lib/shopsavvy_data_api/models.rb

Overview

Product offer from a retailer

Direct Known Subclasses

OfferWithHistory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Offer

Returns a new instance of Offer.



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/shopsavvy_data_api/models.rb', line 130

def initialize(data)
  @id = data["id"]
  @retailer = data["retailer"]
  @price = data["price"]&.to_f
  @currency = data["currency"] || "USD"
  @availability = data["availability"]
  @condition = data["condition"]
  @URL = data["URL"]
  @seller = data["seller"]
  @timestamp = data["timestamp"]
  @history = (data["history"] || []).map { |entry| PriceHistoryEntry.new(entry) }
end

Instance Attribute Details

#availabilityObject (readonly)

Returns the value of attribute availability.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def availability
  @availability
end

#conditionObject (readonly)

Returns the value of attribute condition.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def condition
  @condition
end

#currencyObject (readonly)

Returns the value of attribute currency.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def currency
  @currency
end

#historyObject (readonly)

Returns the value of attribute history.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def history
  @history
end

#idObject (readonly)

Returns the value of attribute id.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def id
  @id
end

#priceObject (readonly)

Returns the value of attribute price.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def price
  @price
end

#retailerObject (readonly)

Returns the value of attribute retailer.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def retailer
  @retailer
end

#sellerObject (readonly)

Returns the value of attribute seller.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def seller
  @seller
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def timestamp
  @timestamp
end

#URLObject (readonly)

Returns the value of attribute URL.



127
128
129
# File 'lib/shopsavvy_data_api/models.rb', line 127

def URL
  @URL
end

Instance Method Details

#in_stock?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/shopsavvy_data_api/models.rb', line 173

def in_stock?
  availability == "in_stock"
end

#last_updatedObject

Deprecated.

Use ‘timestamp` instead



154
155
156
# File 'lib/shopsavvy_data_api/models.rb', line 154

def last_updated
  timestamp
end

#limited_stock?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/shopsavvy_data_api/models.rb', line 181

def limited_stock?
  availability == "limited_stock"
end

#new_condition?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/shopsavvy_data_api/models.rb', line 185

def new_condition?
  condition == "new"
end

#offer_idObject

Deprecated.

Use ‘id` instead



144
145
146
# File 'lib/shopsavvy_data_api/models.rb', line 144

def offer_id
  id
end

#out_of_stock?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/shopsavvy_data_api/models.rb', line 177

def out_of_stock?
  availability == "out_of_stock"
end

#refurbished_condition?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/shopsavvy_data_api/models.rb', line 193

def refurbished_condition?
  condition == "refurbished"
end

#to_hObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/shopsavvy_data_api/models.rb', line 158

def to_h
  {
    id: id,
    retailer: retailer,
    price: price,
    currency: currency,
    availability: availability,
    condition: condition,
    URL: URL,
    seller: seller,
    timestamp: timestamp,
    history: history.map(&:to_h)
  }
end

#urlObject

Deprecated.

Use ‘URL` instead



149
150
151
# File 'lib/shopsavvy_data_api/models.rb', line 149

def url
  URL
end

#used_condition?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/shopsavvy_data_api/models.rb', line 189

def used_condition?
  condition == "used"
end