Sha256: 15667e83c135b9422fe61e7a52257f19cabadc4f150e88dc28560a532de72e1a
Contents?: true
Size: 1.95 KB
Versions: 10
Compression:
Stored size: 1.95 KB
Contents
module SparkApi module Models class ListingCart < Base extend Finders include Concerns::Savable, Concerns::Destroyable self.element_name="listingcarts" def initialize(attributes={}) @contact_id = attributes.delete(:contact_id) if attributes[:contact_id] super(attributes) end def ListingIds=(listing_ids) write_attribute("ListingIds", Array(listing_ids)) end def Name=(name) write_attribute("Name", name) end def self.path if @contact_id "/contacts/#{@contact_id}/listingcarts" else super end end def filter "ListingCart Eq '#{self.Id}'" end def listings(args = {}) return [] if attributes["ListingIds"].nil? Listing.collect(connection.get("#{self.path}/#{self.Id}/listings", args)) end def add_listing(listing) ids = listing.respond_to?(:Id) ? listing.Id : listing results = connection.post("#{self.resource_uri}", {"ListingIds" => Array(ids)}) self.ListingCount = results.first["ListingCount"] end def remove_listing(listing) id = listing.respond_to?(:Id) ? listing.Id : listing.to_s results = connection.delete("#{self.class.path}/#{self.Id}/listings/#{id}") self.ListingCount = results.first["ListingCount"] end def self.for(listings,arguments={}) keys = Array(listings).map { |l| l.respond_to?(:Id) ? l.Id : l.to_s } collect(connection.get("/#{self.element_name}/for/#{keys.join(",")}", arguments)) end def self.my(arguments={}) collect(connection.get("/my/#{self.element_name}", arguments)) end def self.portal(arguments={}) collect(connection.get("/#{self.element_name}/portal", arguments)) end def deletable? !attributes.has_key?("PortalCartType") || self.PortalCartType == "Custom" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems