req.end()
], callback
+# send json
+# try parsing result as json, and fall back to returning string
json_request = (method, path, data, token, callback) ->
if data?
data = JSON.stringify data
try
callback null, JSON.parse(response)
catch error
- callback "Error: AF server returned invalid JSON for #{method} to #{path}: \"#{response}\""
+ # some api calls return plain text
+ callback null, response
json_get = (path, token, callback) ->
json_request 'GET', path, null, token, callback