Permalink
Browse files

Start on a model for Startups

  • Loading branch information...
1 parent 73e544e commit d26d71570576f8741188b28215d90901b3ad4aa1 @ebroder committed Mar 10, 2012
Showing with 30 additions and 0 deletions.
  1. +8 −0 lib/fetch.coffee
  2. +22 −0 models/startup.coffee
View
8 lib/fetch.coffee
@@ -0,0 +1,8 @@
+http = require('http')
+
+exports.get = (options, cb, error) ->
+ response = ""
+ return http.get options, (res) ->
+ res.on "error", error
+ res.on "data", (chunk) -> return response += chunk
+ res.on "end", -> return cb res.statusCode, response
View
22 models/startup.coffee
@@ -0,0 +1,22 @@
+fetch = require('../lib/fetch')
+Backbone = require('backbone')
+
+class Startup extends Backbone.Model
+ initialize: ->
+ if not this.has("this") or not this.has("that")
+ console.log('wtf, dude?')
+
+ fetchPair: (cb, error) ->
+ options =
+ host: "itsthisforthat.com"
+ path: "/api.php?json"
+ return fetch.get options,
+ ((code, resp) =>
+ if code != 200
+ return error new Error "Bad return code: #{code}"
+ try
+ this.set JSON.parse resp
+ return cb()
+ catch err
+ return error err),
+ error

0 comments on commit d26d715

Please sign in to comment.