Created
January 14, 2013 23:18
-
-
Save aroop/4534473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.definition = | |
config: | |
adapter: | |
type: "rest" | |
name: "Agent" | |
extendModel: (Model) -> | |
_.extend Model::, | |
url: -> | |
"#{Alloy.CFG.environment_prefix}.windermere.com/service/v1/profile/#{@get('id')}" | |
parse: (record) -> | |
Ti.API.debug "In models/agents#extendModel.parse. Parameter received #{record}" | |
if typeof record == 'string' | |
record = JSON.parse(record) | |
record.status == "success" && record.data.result_list | |
record = record.data.result_list[0] | |
record | |
Model | |
extendCollection: (Collection) -> | |
_.extend Collection::, | |
url: -> | |
"#{Alloy.CFG.environment_prefix}.windermere.com/service/v1/profile/agents/search" | |
parse: (response) -> | |
Ti.API.debug "In models/agents#extendCollection.parse. Parameter received #{response}" | |
response = JSON.parse(response) | |
Ti.API.debug response.status == "success" | |
Ti.API.debug response.data.result_list | |
if response.status == "success" | |
response.data.result_list | |
else | |
"" | |
# This is the primary endpoint for searching listings. | |
# For search options refer to https://github.com/Windermere/wms_svc_listing/wiki/Listing-Search-Params | |
search: (options = {}) -> | |
Ti.API.debug options | |
Ti.API.debug "In models/agents#extendCollection.search. Parameters received #{options}" | |
@fetch(options) | |
Collection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Fetch Collection | |
agentCollection = Alloy.createCollection('Agent') | |
agentCollection.fetch() | |
#Fetch Model | |
agentModel = Alloy.createModel('Agent', id: 123) | |
agentModel.fetch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment