Class: FlexmlsApi::Models::ListingCart
- Inherits:
-
Base
- Object
- Base
- FlexmlsApi::Models::ListingCart
show all
- Extended by:
- Finders
- Defined in:
- lib/flexmls_api/models/listing_cart.rb
Constant Summary
Constants included
from Paginate
Paginate::DEFAULT_PAGE_SIZE
Instance Attribute Summary
Attributes inherited from Base
#attributes, #changed, #errors
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Finders
find, first, last
Methods inherited from Base
#connection, connection, count, element_name, element_name=, first, get, #initialize, #load, #method_missing, #parse_id, path, prefix, prefix=, #respond_to?
Methods included from Paginate
#collect, #paginate, #per_page
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class FlexmlsApi::Models::Base
Class Method Details
.for(listings, arguments = {}) ⇒ Object
26
27
28
29
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 26
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
31
32
33
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 31
def self.my(arguments={})
collect(connection.get("/my/#{self.element_name}", arguments))
end
|
.portal(arguments = {}) ⇒ Object
35
36
37
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 35
def self.portal(arguments={})
collect(connection.get("/#{self.element_name}/portal", arguments))
end
|
Instance Method Details
#add_listing(listing) ⇒ Object
14
15
16
17
18
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 14
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
|
#delete(args = {}) ⇒ Object
53
54
55
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 53
def delete(args={})
connection.delete("#{self.class.path}/#{self.Id}", args)
end
|
#ListingIds=(listing_ids) ⇒ Object
7
8
9
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 7
def ListingIds=(listing_ids)
attributes["ListingIds"] = Array(listing_ids)
end
|
#Name=(name) ⇒ Object
10
11
12
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 10
def Name=(name)
attributes["Name"] = name
end
|
#remove_listing(listing) ⇒ Object
20
21
22
23
24
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 20
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
|
#save(arguments = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 39
def save(arguments={})
begin
return save!(arguments)
rescue BadResourceRequest => e
rescue NotFound => e
FlexmlsApi.logger.error("Failed to save contact #{self}: #{e.message}")
end
false
end
|
#save!(arguments = {}) ⇒ Object
49
50
51
|
# File 'lib/flexmls_api/models/listing_cart.rb', line 49
def save!(arguments={})
attributes['Id'].nil? ? create!(arguments) : update!(arguments)
end
|