Skip to content

Commit

Permalink
Added a create function.
Browse files Browse the repository at this point in the history
  • Loading branch information
sabman committed Sep 13, 2011
1 parent ef7b666 commit 077861c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.DS_Store
26 changes: 13 additions & 13 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ io.sockets.on 'connection', (socket) ->
chat_data = {user: record, conversation: message}
socket.broadcast.send JSON.stringify(chat_data) # forwards message to all the clients except the one that emitted the "broadcast" event

socket.on 'addUser', (message) ->
# post the data to SpacialDB and
socket.on 'addUser', (message) ->
input =
geometry: { type: "Point", coordinates: [message.lng, message.lat]}
properties: { name : message.name, location: message.location, email: message.email, clientId: clientId}
post_url = "https://api.spacialdb.com/1/users/shoaib_burq/layers/characters?key=#{lyr_config_characters.acl.post}"
Character.create input, (new_record) ->
new_rec = JSON.parse(new_record)
Character.find {id: new_rec.id}, (record) ->
socket.broadcast.emit 'newUser', JSON.stringify(record)


Character =
create: (attrs, callback) ->
# post the data to SpacialDB
post_url = "#{lyr_config_characters.api_url}?key=#{lyr_config_characters.acl.post}"
req =
method: "POST", uri: post_url, body: JSON.stringify(input)
method: "POST", uri: post_url, body: JSON.stringify(attrs)
headers: { "Content-Type": "application/json" }
request req, (error, response, body) ->
if error
console.log error
else
rec = JSON.parse(body)
Character.find {id: rec.id}, (record) ->
socket.broadcast.emit 'newUser', JSON.stringify(record)


Character =

create: (attrs, callback) ->
#...
return body

delete: (id, callback) ->
url = "#{lyr_config_characters.api_url}/#{id}?key=#{lyr_config_characters.acl.delete}"
Expand Down

0 comments on commit 077861c

Please sign in to comment.