Class: Etsy::Listing
Overview
Listing
Represents a single Etsy listing. Has the following attributes:
[id] The unique identifier for this listing [title] The title of this listing [description] This listing's full description [view_count] The number of times this listing has been viewed [url] The full URL to this listing's detail page [price] The price of this listing item [currency] The currency that the seller is using for this listing item [quantity] The number of items available for sale [tags] An array of tags that the seller has used for this listing [materials] Any array of materials that was used in the production of this item [state] The current state of the item [hue] The hue of the listing's primary image (HSV color). [saturation] The saturation of the listing's primary image (HSV color). [brightness] The value of the listing's primary image (HSV color). [black_and_white?] True if the listing's primary image is in black & white.
Additionally, the following queries on this item are available:
[active?] Is this listing active? [removed?] Has this listing been removed? [sold_out?] Is this listing sold out? [expired?] Has this listing expired? [alchemy?] Is this listing an Alchemy item? (i.e. requested by an Etsy user)
Constant Summary collapse
- STATES =
%w(active removed sold_out expired alchemy)- VALID_STATES =
[:active, :expired, :inactive, :sold, :featured]
Class Method Summary collapse
- .create(options = {}) ⇒ Object
-
.find(*identifiers_and_options) ⇒ Object
Retrieve one or more listings by ID:.
-
.find_all_active_by_category(category, options = {}) ⇒ Object
Retrieve active listings for a given category.
-
.find_all_by_shop_id(shop_id, options = {}) ⇒ Object
Retrieve listings for a given shop.
- .update(listing, options = {}) ⇒ Object
Instance Method Summary collapse
- #black_and_white? ⇒ Boolean
-
#created_at ⇒ Object
Time that this listing was created.
-
#ending_at ⇒ Object
Time that this listing is ending (will be removed from store).
-
#image ⇒ Object
The primary image for this listing.
-
#images ⇒ Object
The collection of images associated with this listing.
-
#modified_at ⇒ Object
Time that this listing was last modified.
Methods included from Model
included, #initialize, #result, #secret, #token
Class Method Details
.create(options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/etsy/listing.rb', line 50 def self.create( = {}) .merge!(:require_secure => true) post("/listings", ) end |
.find(*identifiers_and_options) ⇒ Object
Retrieve one or more listings by ID:
Etsy::Listing.find(123)
You can find multiple listings by passing an array of identifiers:
Etsy::Listing.find([123, 456])
68 69 70 |
# File 'lib/etsy/listing.rb', line 68 def self.find(*) find_one_or_more('listings', ) end |
.find_all_active_by_category(category, options = {}) ⇒ Object
Retrieve active listings for a given category. By default, pulls back the first 25 active listings. Defaults can be overridden using :limit, :offset, and :state
options = { :limit => 25, :offset => 100, :token => 'toke', :secret => 'secret' } Etsy::Listing.find_all_active_by_category("accessories", options)
112 113 114 115 |
# File 'lib/etsy/listing.rb', line 112 def self.find_all_active_by_category(category, = {}) [:category] = category get_all("/listings/active", ) end |
.find_all_by_shop_id(shop_id, options = {}) ⇒ Object
Retrieve listings for a given shop. By default, pulls back the first 25 active listings. Defaults can be overridden using :limit, :offset, and :state
Available states are :active, :expired, :inactive, :sold, and :featured where :featured is a subset of the others.
options = { :state => :expired, :limit => 100, :offset => 100, :token => 'toke', :secret => 'secret' } Etsy::Listing.find_all_by_shop_id(123, options)
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/etsy/listing.rb', line 88 def self.find_all_by_shop_id(shop_id, = {}) state = .delete(:state) || :active raise(ArgumentError, self.(state)) unless valid?(state) if state == :sold sold_listings(shop_id, ) else get_all("/shops/#{shop_id}/listings/#{state}", ) end end |
.update(listing, options = {}) ⇒ Object
55 56 57 58 |
# File 'lib/etsy/listing.rb', line 55 def self.update(listing, = {}) .merge!(:require_secure => true) put("/listings/#{listing.id}", ) end |
Instance Method Details
#black_and_white? ⇒ Boolean
129 130 131 |
# File 'lib/etsy/listing.rb', line 129 def black_and_white? is_black_and_white end |
#created_at ⇒ Object
Time that this listing was created
141 142 143 |
# File 'lib/etsy/listing.rb', line 141 def created_at Time.at(created) end |
#ending_at ⇒ Object
Time that this listing is ending (will be removed from store)
153 154 155 |
# File 'lib/etsy/listing.rb', line 153 def ending_at Time.at(ending) end |
#image ⇒ Object
The primary image for this listing.
125 126 127 |
# File 'lib/etsy/listing.rb', line 125 def image images.first end |
#images ⇒ Object
The collection of images associated with this listing.
119 120 121 |
# File 'lib/etsy/listing.rb', line 119 def images @images ||= Image.find_all_by_listing_id(id) end |
#modified_at ⇒ Object
Time that this listing was last modified
147 148 149 |
# File 'lib/etsy/listing.rb', line 147 def modified_at Time.at(modified) end |