Class: Gilt::Sale
- Inherits:
-
Object
- Object
- Gilt::Sale
- Defined in:
- lib/gilt/sale.rb
Overview
A Gilt Sale object, representing an active or upcoming “flash” sale.
Class Method Summary collapse
- .client(apikey, affid = nil) ⇒ Object
- .create(store, sale_key, apikey, affid = nil) ⇒ Object
- .product_client(apikey, affid = nil) ⇒ Object
Instance Method Summary collapse
- #begins ⇒ Object
- #description ⇒ Object
- #duration ⇒ Object
- #ended? ⇒ Boolean
- #ends ⇒ Object
- #images ⇒ Object
-
#initialize(sale_body, client = nil) ⇒ Sale
constructor
A new instance of Sale.
- #length ⇒ Object
- #name ⇒ Object
- #products ⇒ Object
- #sale ⇒ Object
- #sale_key ⇒ Object
- #sale_url ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(sale_body, client = nil) ⇒ Sale
Returns a new instance of Sale.
36 37 38 39 |
# File 'lib/gilt/sale.rb', line 36 def initialize(sale_body, client=nil) @sale = sale_body @client = client end |
Class Method Details
.client(apikey, affid = nil) ⇒ Object
24 25 26 |
# File 'lib/gilt/sale.rb', line 24 def self.client(apikey, affid=nil) Gilt::Client::Sales.new(apikey, affid) end |
.create(store, sale_key, apikey, affid = nil) ⇒ Object
32 33 34 |
# File 'lib/gilt/sale.rb', line 32 def self.create(store, sale_key, apikey, affid=nil) detail(:store => store, :sale_key => sale_key, :apikey => apikey, :affid => affid).first end |
Instance Method Details
#begins ⇒ Object
69 70 71 |
# File 'lib/gilt/sale.rb', line 69 def begins Time.parse @sale["begins"] end |
#description ⇒ Object
65 66 67 |
# File 'lib/gilt/sale.rb', line 65 def description @sale["description"] end |
#duration ⇒ Object
83 84 85 |
# File 'lib/gilt/sale.rb', line 83 def duration (ends - begins).ceil unless ends.nil? end |
#ended? ⇒ Boolean
78 79 80 81 |
# File 'lib/gilt/sale.rb', line 78 def ended? return false if ends.nil? ends < Time.now end |
#ends ⇒ Object
73 74 75 76 |
# File 'lib/gilt/sale.rb', line 73 def ends end_time = @sale["ends"] Time.parse end_time unless end_time.nil? end |
#images ⇒ Object
61 62 63 |
# File 'lib/gilt/sale.rb', line 61 def images @sale["image_urls"] end |
#length ⇒ Object
96 97 98 |
# File 'lib/gilt/sale.rb', line 96 def length return products.length end |
#name ⇒ Object
41 42 43 |
# File 'lib/gilt/sale.rb', line 41 def name @sale["name"] end |
#products ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/gilt/sale.rb', line 87 def products return @products unless @products.nil? resource = Gilt::Client::Products.resources[:detail] @products = (@sale["products"] || []).map do |product| id = resource.url.extract(product)["product_id"] Product.defer @client.detail(:product_id => id).perform end end |
#sale ⇒ Object
53 54 55 |
# File 'lib/gilt/sale.rb', line 53 def sale URI(@sale["sale"]) end |
#sale_key ⇒ Object
49 50 51 |
# File 'lib/gilt/sale.rb', line 49 def sale_key @sale["sale_key"] end |
#sale_url ⇒ Object
57 58 59 |
# File 'lib/gilt/sale.rb', line 57 def sale_url URI(@sale["sale_url"]) end |
#store ⇒ Object
45 46 47 |
# File 'lib/gilt/sale.rb', line 45 def store @sale["store"].intern end |