Skip to content

Instantly share code, notes, and snippets.

@aroop
Created January 14, 2013 23:18
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroop/4534473 to your computer and use it in GitHub Desktop.
Save aroop/4534473 to your computer and use it in GitHub Desktop.
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
#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