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, :draft, :sold_out]
Class Method Summary collapse
- .create(options = {}) ⇒ Object
- .destroy(listing, 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
-
#add_variations(options) ⇒ Object
property_id = Etsy::Variation::PropertySet.find_property_by_name(“Dimensions”).fetch(“property_id”) scale = Etsy::Variation::PropertySet.qualifying_properties_for_property(“Dimensions”).detect {|qp| qp.fetch(“description”) == “Sizing Scale”} my_listing.add_variations( :variations => [ => property_id, “value” => “1 x 2”, “is_available” => true, “price” => 1.23, => property_id, “value” => “2 x 4”, “is_available” => true, “price” => 2.34 ], scale.fetch(“param”) => scale.fetch(“options”).fetch(“Inches”) ).
-
#admirers(options = {}) ⇒ Object
Return a list of users who have favorited this listing.
- #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.
- #is_supply ⇒ Object
-
#modified_at ⇒ Object
Time that this listing was last modified.
- #update_variations(options) ⇒ Object
- #variations ⇒ Object
Methods included from Model
included, #initialize, #result, #secret, #token
Class Method Details
.create(options = {}) ⇒ Object
52 53 54 55 |
# File 'lib/etsy/listing.rb', line 52 def self.create( = {}) .merge!(:require_secure => true) post("/listings", ) end |
.destroy(listing, options = {}) ⇒ Object
62 63 64 65 |
# File 'lib/etsy/listing.rb', line 62 def self.destroy(listing, = {}) .merge!(:require_secure => true) delete("/listings/#{listing.id}", ) end |
.find(*identifiers_and_options) ⇒ Object
75 76 77 |
# File 'lib/etsy/listing.rb', line 75 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)
119 120 121 122 |
# File 'lib/etsy/listing.rb', line 119 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, :draft, :sold_out 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)
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/etsy/listing.rb', line 95 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
57 58 59 60 |
# File 'lib/etsy/listing.rb', line 57 def self.update(listing, = {}) .merge!(:require_secure => true) put("/listings/#{listing.id}", ) end |
Instance Method Details
#add_variations(options) ⇒ Object
property_id = Etsy::Variation::PropertySet.find_property_by_name(“Dimensions”).fetch(“property_id”)
scale = Etsy::Variation::PropertySet.("Dimensions").detect {|qp| qp.fetch("description") == "Sizing Scale"}
my_listing.add_variations(
:variations => [
{"property_id" => property_id, "value" => "1 x 2", "is_available" => true, "price" => 1.23},
{"property_id" => property_id, "value" => "2 x 4", "is_available" => true, "price" => 2.34}
],
scale.fetch("param") => scale.fetch("options").fetch("Inches")
)
171 172 173 174 175 |
# File 'lib/etsy/listing.rb', line 171 def add_variations() [:variations] = JSON.dump(.delete(:variations)) [:require_secure] = true self.class.post("/listings/#{id}/variations", ) end |
#admirers(options = {}) ⇒ Object
Return a list of users who have favorited this listing
213 214 215 216 217 218 |
# File 'lib/etsy/listing.rb', line 213 def admirers( = {}) = .merge(:access_token => token, :access_secret => secret) if (token && secret) favorite_listings = FavoriteListing.find_all_listings_favored_by(id, ) user_ids = favorite_listings.map {|f| f.user_id }.uniq (user_ids.size > 0) ? Array(Etsy::User.find(user_ids, )) : [] end |
#black_and_white? ⇒ Boolean
183 184 185 |
# File 'lib/etsy/listing.rb', line 183 def black_and_white? is_black_and_white end |
#created_at ⇒ Object
Time that this listing was created
195 196 197 |
# File 'lib/etsy/listing.rb', line 195 def created_at Time.at(created) end |
#ending_at ⇒ Object
Time that this listing is ending (will be removed from store)
207 208 209 |
# File 'lib/etsy/listing.rb', line 207 def ending_at Time.at(ending) end |
#image ⇒ Object
The primary image for this listing.
132 133 134 |
# File 'lib/etsy/listing.rb', line 132 def image images.first end |
#images ⇒ Object
The collection of images associated with this listing.
126 127 128 |
# File 'lib/etsy/listing.rb', line 126 def images @images ||= Image.find_all_by_listing_id(id, oauth) end |
#is_supply ⇒ Object
220 221 222 |
# File 'lib/etsy/listing.rb', line 220 def is_supply !!@result.fetch("is_supply") end |
#modified_at ⇒ Object
Time that this listing was last modified
201 202 203 |
# File 'lib/etsy/listing.rb', line 201 def modified_at Time.at(modified) end |
#update_variations(options) ⇒ Object
177 178 179 180 181 |
# File 'lib/etsy/listing.rb', line 177 def update_variations() [:variations] = JSON.dump(.delete(:variations)) [:require_secure] = true self.class.put("/listings/#{id}/variations", ) end |
#variations ⇒ Object
136 137 138 |
# File 'lib/etsy/listing.rb', line 136 def variations self.class.get_all("/listings/#{id}/variations") end |