Skip to content
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"

Finders

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

Concerns

There are behaviors that a model may implement based on what the API services support.

  1. Savable: model instances can be created, and/or updated.
  2. Destroyable: model instances can be deleted.
Clone this wiki locally