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

Direct Known Subclasses

PortalListingCart

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!, #update_attributes

Methods included from Concerns::Destroyable

#destroy, #destroy!, #destroyed?

Methods inherited from Base

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

Methods included from Paginate

#collect, #paginate, #per_page

Methods included from Dirty

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

Constructor Details

#initialize(attributes = {}) ⇒ ListingCart

Returns a new instance of ListingCart.



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

def initialize(attributes={})
  @contact_id = attributes.delete(:contact_id) if attributes[:contact_id]
  super(attributes)
end

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



52
53
54
55
# File 'lib/spark_api/models/listing_cart.rb', line 52

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



57
58
59
# File 'lib/spark_api/models/listing_cart.rb', line 57

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

.pathObject



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

def self.path
  if @contact_id
    "/contacts/#{@contact_id}/listingcarts"
  else
    super
  end
end

.portal(arguments = {}) ⇒ Object



61
62
63
# File 'lib/spark_api/models/listing_cart.rb', line 61

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

Instance Method Details

#add_listing(listing) ⇒ Object



40
41
42
43
44
# File 'lib/spark_api/models/listing_cart.rb', line 40

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

#deletable?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/spark_api/models/listing_cart.rb', line 65

def deletable?
  !attributes.has_key?("PortalCartType") || self.PortalCartType == "Custom"
end

#filterObject



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

def filter
  "ListingCart Eq '#{self.Id}'"
end

#ListingIds=(listing_ids) ⇒ Object



15
16
17
# File 'lib/spark_api/models/listing_cart.rb', line 15

def ListingIds=(listing_ids)
  write_attribute("ListingIds", Array(listing_ids))
end

#listings(args = {}) ⇒ Object



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

def listings(args = {})
  return [] if attributes["ListingIds"].nil?
  Listing.collect(connection.get("#{self.path}/#{self.Id}/listings", args))
end

#Name=(name) ⇒ Object



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

def Name=(name)
  write_attribute("Name", name)
end

#remove_listing(listing) ⇒ Object



46
47
48
49
50
# File 'lib/spark_api/models/listing_cart.rb', line 46

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