Class: Svpply::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/svpply/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Product

Returns a new instance of Product.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/svpply/product.rb', line 24

def initialize(hash)
  @id = hash["id"]
  @title = hash["page_title"]
  @price = hash["price"]
  @formatted_price = hash["formatted_price"]
  @currency_code = hash["currency_code"]
  @discount = hash["discount"]
  @discount_code = hash["discount_code"]
  @category = hash["category"]
  @categories = hash["categories"]
  @gender = hash["gender"]
  @image = hash["image"]
  @image_width = hash["image_width"]
  @image_height = hash["image_height"]
  @saves = hash["saves"]
  @notes = hash["notes"]
  @status_id = hash["status_id"]
  @url = hash["page_url"]
  @date_created = hash["date_created"]
  @date_updated = hash["date_updated"]
  @svpply_url = "https://svpply.com/item/#{@id}"
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



3
4
5
# File 'lib/svpply/product.rb', line 3

def categories
  @categories
end

#categoryObject (readonly)

Returns the value of attribute category.



3
4
5
# File 'lib/svpply/product.rb', line 3

def category
  @category
end

#currency_codeObject (readonly)

Returns the value of attribute currency_code.



3
4
5
# File 'lib/svpply/product.rb', line 3

def currency_code
  @currency_code
end

#date_createdObject (readonly)

Returns the value of attribute date_created.



3
4
5
# File 'lib/svpply/product.rb', line 3

def date_created
  @date_created
end

#date_updatedObject (readonly)

Returns the value of attribute date_updated.



3
4
5
# File 'lib/svpply/product.rb', line 3

def date_updated
  @date_updated
end

#discountObject (readonly)

Returns the value of attribute discount.



3
4
5
# File 'lib/svpply/product.rb', line 3

def discount
  @discount
end

#discount_codeObject (readonly)

Returns the value of attribute discount_code.



3
4
5
# File 'lib/svpply/product.rb', line 3

def discount_code
  @discount_code
end

#formatted_priceObject (readonly)

Returns the value of attribute formatted_price.



3
4
5
# File 'lib/svpply/product.rb', line 3

def formatted_price
  @formatted_price
end

#genderObject (readonly)

Returns the value of attribute gender.



3
4
5
# File 'lib/svpply/product.rb', line 3

def gender
  @gender
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/svpply/product.rb', line 3

def id
  @id
end

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/svpply/product.rb', line 3

def image
  @image
end

#image_heightObject (readonly)

Returns the value of attribute image_height.



3
4
5
# File 'lib/svpply/product.rb', line 3

def image_height
  @image_height
end

#image_widthObject (readonly)

Returns the value of attribute image_width.



3
4
5
# File 'lib/svpply/product.rb', line 3

def image_width
  @image_width
end

#notesObject (readonly)

Returns the value of attribute notes.



3
4
5
# File 'lib/svpply/product.rb', line 3

def notes
  @notes
end

#priceObject (readonly)

Returns the value of attribute price.



3
4
5
# File 'lib/svpply/product.rb', line 3

def price
  @price
end

#savesObject (readonly)

Returns the value of attribute saves.



3
4
5
# File 'lib/svpply/product.rb', line 3

def saves
  @saves
end

#status_idObject (readonly)

Returns the value of attribute status_id.



3
4
5
# File 'lib/svpply/product.rb', line 3

def status_id
  @status_id
end

#svpply_urlObject (readonly)

Returns the value of attribute svpply_url.



3
4
5
# File 'lib/svpply/product.rb', line 3

def svpply_url
  @svpply_url
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/svpply/product.rb', line 3

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/svpply/product.rb', line 3

def url
  @url
end

Class Method Details

.find(id) ⇒ Object



16
17
18
# File 'lib/svpply/product.rb', line 16

def self.find(id)
  new(Client.get_response("/products/#{id}.json")["product"])
end


20
21
22
# File 'lib/svpply/product.rb', line 20

def self.product_image_permalink(id, type='medium')
  "https://api.svpply.com/v1/products/#{id}/image?type=#{type}"
end

.products(attrs = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/svpply/product.rb', line 8

def self.products(attrs=nil)
  unless attrs.empty?
    ProductCollection.new(Client.get_response('/products/search.json', attrs)).products
   else
    ProductCollection.new(Client.get_response('/shop.json')).products
   end
end