Class: Etsy::Listing
Constant Summary collapse
- STATES =
%w(active removed sold_out expired edit draft private unavailable)
- VALID_STATES =
TODO: re-check valid states
[:active, :draft, :expired, :featured, :inactive, :sold, :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
-
#category ⇒ Object
Listing category name.
-
#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.
-
#original_created_at ⇒ Object
Time that this listing was originally created.
- #receipts ⇒ Object
-
#taxonomy_attributes(options = {}) ⇒ Object
Returns the taxonomy defined attributes for the listing.
- #transactions ⇒ Object
- #update_variations(options) ⇒ Object
- #variations(options = {}) ⇒ Object
Methods included from Model
included, #initialize, #result, #secret, #token
Class Method Details
.create(options = {}) ⇒ Object
68 69 70 71 |
# File 'lib/etsy/listing.rb', line 68 def self.create( = {}) .merge!(:require_secure => true) post("/listings", ) end |
.destroy(listing, options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/etsy/listing.rb', line 78 def self.destroy(listing, = {}) .merge!(:require_secure => true) delete("/listings/#{listing.id}", ) end |
.find(*identifiers_and_options) ⇒ Object
91 92 93 |
# File 'lib/etsy/listing.rb', line 91 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)
135 136 137 138 |
# File 'lib/etsy/listing.rb', line 135 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)
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/etsy/listing.rb', line 111 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
73 74 75 76 |
# File 'lib/etsy/listing.rb', line 73 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")
)
202 203 204 205 206 |
# File 'lib/etsy/listing.rb', line 202 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
249 250 251 252 253 254 |
# File 'lib/etsy/listing.rb', line 249 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
214 215 216 |
# File 'lib/etsy/listing.rb', line 214 def black_and_white? is_black_and_white end |
#category ⇒ Object
Listing category name
154 155 156 157 |
# File 'lib/etsy/listing.rb', line 154 def category path = category_path.join('/') @category ||= Category.find(path) end |
#created_at ⇒ Object
Time that this listing was created
226 227 228 |
# File 'lib/etsy/listing.rb', line 226 def created_at Time.at(created) end |
#ending_at ⇒ Object
Time that this listing is ending (will be removed from store)
243 244 245 |
# File 'lib/etsy/listing.rb', line 243 def ending_at Time.at(ending) end |
#image ⇒ Object
The primary image for this listing.
148 149 150 |
# File 'lib/etsy/listing.rb', line 148 def image images.first end |
#images ⇒ Object
The collection of images associated with this listing.
142 143 144 |
# File 'lib/etsy/listing.rb', line 142 def images @images ||= listing_images end |
#is_supply ⇒ Object
256 257 258 |
# File 'lib/etsy/listing.rb', line 256 def is_supply @result.fetch('is_supply') == 'true' end |
#modified_at ⇒ Object
Time that this listing was last modified
237 238 239 |
# File 'lib/etsy/listing.rb', line 237 def modified_at Time.at(modified) end |
#original_created_at ⇒ Object
Time that this listing was originally created
231 232 233 |
# File 'lib/etsy/listing.rb', line 231 def original_created_at Time.at(original_created) end |
#receipts ⇒ Object
64 65 66 |
# File 'lib/etsy/listing.rb', line 64 def receipts transactions.map{|t|t.receipt} end |
#taxonomy_attributes(options = {}) ⇒ Object
Returns the taxonomy defined attributes for the listing
161 162 163 164 |
# File 'lib/etsy/listing.rb', line 161 def taxonomy_attributes(={}) .merge!(:require_secure => true) self.class.get_all("/listings/#{id}/attributes", oauth.merge()) end |
#transactions ⇒ Object
60 61 62 |
# File 'lib/etsy/listing.rb', line 60 def transactions @transactions ||= Transaction.find_all_by_listing_id(id, oauth) end |
#update_variations(options) ⇒ Object
208 209 210 211 212 |
# File 'lib/etsy/listing.rb', line 208 def update_variations() [:variations] = JSON.dump(.delete(:variations)) [:require_secure] = true self.class.put("/listings/#{id}/variations", ) end |
#variations(options = {}) ⇒ Object
166 167 168 169 |
# File 'lib/etsy/listing.rb', line 166 def variations(={}) .merge!(:require_secure => true) self.class.get_all("/listings/#{id}/variations", oauth.merge()) end |