-
Notifications
You must be signed in to change notification settings - Fork 35
API Models
wlmcewen edited this page Nov 9, 2012
·
5 revisions
The client also provides ActiveModel-like interface for working with the api responses. Notably, the models use finder methods for searching, and similar instanciation and persistence also on supported services.
# Tip: mixin the models so you can use them without namespaces
include SparkApi::Models
puts SystemInfo.first.Name
# "Demo MLS"
Models that support searching extend the Finders module. This interface mimics the rails 2.x finder method.
listings = Listing.find(:all, :_filter => "ListPrice Gt 150000.0 And ListPrice Lt 200000.0", :_orderby => "-ListPrice")
puts "Top list price: $%.2f" % listings.first.ListPrice
# Top list price: $199999.99
There are behaviors that a model may implement based on what the API services support.
- Savable: model instances can be created, and/or updated.
- Destroyable: model instances can be deleted.