Class: A2z::Responses::Offer

Inherits:
Object
  • Object
show all
Defined in:
lib/a2z/responses/offer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOffer

Returns a new instance of Offer.



9
10
11
12
13
14
# File 'lib/a2z/responses/offer.rb', line 9

def initialize
  @price = Money.new(0, 'USD')
  @amount_saved = Money.new(0, 'USD')
  @percentage_saved = 0
  @super_saver_shipping_eligible = false
end

Instance Attribute Details

#amount_savedObject

Returns the value of attribute amount_saved.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def amount_saved
  @amount_saved
end

#availabilityObject

Returns the value of attribute availability.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def availability
  @availability
end

#conditionObject

Returns the value of attribute condition.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def condition
  @condition
end

#listing_idObject

Returns the value of attribute listing_id.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def listing_id
  @listing_id
end

#percentage_savedObject

Returns the value of attribute percentage_saved.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def percentage_saved
  @percentage_saved
end

#priceObject

Returns the value of attribute price.



6
7
8
# File 'lib/a2z/responses/offer.rb', line 6

def price
  @price
end

Class Method Details

.from_response(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/a2z/responses/offer.rb', line 34

def self.from_response(data)
  new.tap do |offer|
    if (attributes = data['OfferAttributes'])
      offer.condition = attributes['Condition']
    end
    
    if (listing = data['OfferListing'])
      offer.listing_id = listing['OfferListingId']
      offer.price = Money.new(listing['Price']['Amount'].to_i, listing['Price']['CurrencyCode']) if listing['Price']
      offer.amount_saved = Money.new(listing['AmountSaved']['Amount'].to_i, listing['AmountSaved']['CurrencyCode']) if listing['AmountSaved']
      offer.percentage_saved = listing['PercentageSaved'].to_i
      offer.availability = listing['Availability']
      offer.super_saver_shipping_eligible = listing['IsEligibleForSuperSaverShipping'] == '1'
    end
    
    offer.freeze
  end
end

Instance Method Details

#super_saver_shipping_eligible=(value) ⇒ Object



26
27
28
# File 'lib/a2z/responses/offer.rb', line 26

def super_saver_shipping_eligible=(value)
  @super_saver_shipping_eligible = !!value
end

#super_saver_shipping_eligible?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/a2z/responses/offer.rb', line 30

def super_saver_shipping_eligible?
  @super_saver_shipping_eligible
end