Skip to content
Browse files

Add initial Gist version and Cakefile for building

  • Loading branch information...
1 parent 5205ed9 commit 68f2ec70f74df96c3fb575efbede674373fe3f81 @meritt committed Aug 13, 2011
Showing with 71 additions and 0 deletions.
  1. +16 −0 Cakefile
  2. +55 −0 src/gisty.coffee
View
16 Cakefile
@@ -0,0 +1,16 @@
+require.paths.unshift "#{__dirname}/node_modules"
+
+require.paths.unshift __dirname + '/lib'
+
+{print} = require 'sys'
+{spawn} = require 'child_process'
+
+build = (callback) ->
+ coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
+ coffee.stderr.on 'data', (data) ->
+ process.stderr.write data.toString()
+ coffee.stdout.on 'data', (data) ->
+ print data.toString()
+
+task 'build', 'Build lib/ from src/', ->
+ build()
View
55 src/gisty.coffee
@@ -0,0 +1,55 @@
+###
+ node-gisty 0.0.1
+ (c) 2011 Alexey Simonenko, Serenity LLC.
+ For all details and documentation:
+ http://github.com/meritt/node-gisty
+###
+
+xhr = require 'request'
+
+class Gisty
+ api = 'https://api.github.com'
+
+ constructor: (@login, @password) ->
+ @username = @login
+
+ setUsername: (username) ->
+ @username = username
+ @
+
+ fetch: (id, fn) ->
+ @scheme = '/gists/' + id
+ request @, fn
+
+ comments: (id, fn) ->
+ @scheme = '/gists/' + id + '/comments'
+ request @, fn
+
+ all: (fn) ->
+ @scheme = '/users/' + @username + '/gists'
+ request @, fn
+
+ public: (fn) ->
+ @scheme = '/gists/public'
+ request @, fn
+
+ starred: (fn) ->
+ @scheme = '/gists/starred'
+ request @, fn
+
+ request = (self, fn = ->) ->
+ options =
+ url: api + self.scheme,
+ headers:
+ Authorization: 'Basic ' + new Buffer(self.login + ':' + self.password).toString('base64')
+
+ xhr options, (error, request, body) ->
+ body = JSON.parse body
+ error = body if request.statusCode not in [200, 201, 204]
+
+ limit = if request.headers? then parseInt(request.headers['x-ratelimit-remaining']) > 0 else true
+ error = {message: 'Your limit is over'} if not error and not limit
+
+ fn.call self, error, body
+
+exports.Gisty = Gisty

0 comments on commit 68f2ec7

Please sign in to comment.
Something went wrong with that request. Please try again.