Skip to content

Commit

Permalink
Merge pull request #147 from ryanhertz/rules
Browse files Browse the repository at this point in the history
added Rule model
  • Loading branch information
ryanhertz authored Jun 6, 2018
2 parents ee861d4 + 46c5321 commit b8efffb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.4.22
- added Rule model

v1.4.21
- added IncompleteListing model

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.21
1.4.22
1 change: 1 addition & 0 deletions lib/spark_api/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require 'spark_api/models/portal_listing_cart'
require 'spark_api/models/property_types'
require 'spark_api/models/rental_calendar'
require 'spark_api/models/rule'
require 'spark_api/models/saved_search'
require 'spark_api/models/search_template/quick_search'
require 'spark_api/models/shared_link'
Expand Down
14 changes: 14 additions & 0 deletions lib/spark_api/models/rule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module SparkApi
module Models
class Rule < Base

self.element_name="listings/rules"

def self.for_property_type(property_type, args={})
collect(connection.get("/listings/rules/propertytypes/#{property_type}", args))
end

end
end
end

39 changes: 39 additions & 0 deletions spec/fixtures/rules/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"D": {
"Success": true,
"Results": [
{
"Id": 25,
"ResourceUri": "/v1/listings/rules/25",
"PropertyType": "A",
"Domain": "StandardFields",
"Group": null,
"Field": "BathsTotal",
"Order": 1,
"Action": "SET_REQUIRED",
"Expression": "StandardStatus = 'Active'",
"ModificationTimestamp": "2018-05-07T19:03:07Z",
"CreatedTimestamp": "2017-12-20T19:00:30Z",
"ApprovalStatus": "Published",
"Editable": true,
"Status": "Fatal"
},
{
"Id": 370,
"ResourceUri": "/v1/listings/rules/370",
"PropertyType": "A",
"Domain": "StandardFields",
"Group": null,
"Field": "City",
"Order": 1,
"Action": "SET_REQUIRED",
"Expression": ".FALSE.",
"ModificationTimestamp": "2018-05-01T15:26:47Z",
"CreatedTimestamp": "2018-01-24T16:01:14Z",
"ApprovalStatus": "Published",
"Editable": true,
"Status": "Fatal"
}
]
}
}
18 changes: 18 additions & 0 deletions spec/unit/spark_api/models/rule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require './spec/spec_helper'

describe Rule do

describe 'for_property_type' do

on_get_it "should get documents for a listing" do
stub_auth_request
stub_api_get('/listings/rules/propertytypes/A','rules/get.json')

rules = Rule.for_property_type('A')
rules.should be_an(Array)
rules.length.should == 2
end

end

end

0 comments on commit b8efffb

Please sign in to comment.