Class: SparkApi::Models::ListingCart

Inherits:
Base
  • Object
show all
Extended by:
Finders
Includes:
Concerns::Destroyable, Concerns::Savable
Defined in:
lib/spark_api/models/listing_cart.rb

Constant Summary

Constants included from Paginate

Paginate::DEFAULT_PAGE_SIZE

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finders

find, find_one, first, last

Methods included from Concerns::Savable

#create!, #params_for_save, #post_data, #save, #save!, #update!

Methods included from Concerns::Destroyable

#destroy, #destroy!, #destroyed?

Methods inherited from Base

connection, #connection, count, element_name, element_name=, first, get, #initialize, #load, #method_missing, #parse_id, #path, path, #persisted?, prefix, prefix=, #resource_uri, #respond_to?

Methods included from Paginate

#collect, #paginate, #per_page

Methods included from Dirty

#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes

Constructor Details

This class inherits a constructor from SparkApi::Models::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base

Class Method Details

.for(listings, arguments = {}) ⇒ Object



29
30
31
32
# File 'lib/spark_api/models/listing_cart.rb', line 29

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

.my(arguments = {}) ⇒ Object



34
35
36
# File 'lib/spark_api/models/listing_cart.rb', line 34

def self.my(arguments={})
  collect(connection.get("/my/#{self.element_name}", arguments))
end

.portal(arguments = {}) ⇒ Object



38
39
40
# File 'lib/spark_api/models/listing_cart.rb', line 38

def self.portal(arguments={})
    collect(connection.get("/#{self.element_name}/portal", arguments))
end

Instance Method Details

#add_listing(listing) ⇒ Object



17
18
19
20
21
# File 'lib/spark_api/models/listing_cart.rb', line 17

def add_listing(listing)
  id = listing.respond_to?(:Id) ? listing.Id : listing.to_s
  results = connection.post("#{self.class.path}/#{self.Id}", {"ListingIds" => [ listing ]})
  self.ListingCount = results.first["ListingCount"]
end

#ListingIds=(listing_ids) ⇒ Object



10
11
12
# File 'lib/spark_api/models/listing_cart.rb', line 10

def ListingIds=(listing_ids)
  attributes["ListingIds"] = Array(listing_ids)
end

#Name=(name) ⇒ Object



13
14
15
# File 'lib/spark_api/models/listing_cart.rb', line 13

def Name=(name)
  attributes["Name"] = name
end

#remove_listing(listing) ⇒ Object



23
24
25
26
27
# File 'lib/spark_api/models/listing_cart.rb', line 23

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