Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed Jun 14, 2012
0 parents commit 1c91a1e
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
@@ -0,0 +1,20 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log

*.sublime-project
*.sublime-workspace

test/config.coffee
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js

node_js:
- 0.6
8 changes: 8 additions & 0 deletions Makefile
@@ -0,0 +1,8 @@
REPORTER = spec

test:
@./node_modules/mocha/bin/mocha \
--reporter $(REPORTER) \
test/*.coffee

.PHONY: test
4 changes: 4 additions & 0 deletions README.md
@@ -0,0 +1,4 @@
node-quizlet
============

Node.js Quizlet API interface
2 changes: 2 additions & 0 deletions index.js
@@ -0,0 +1,2 @@
require('coffee-script')
module.exports = require('./lib/')
35 changes: 35 additions & 0 deletions lib/index.coffee
@@ -0,0 +1,35 @@
querystring = require 'querystring'

request = require 'superagent'
oauth = require('oauth').OAuth

baseURL = 'https://api.quizlet.com/2.0/'

class QuizletAPI
###
Interface to the Quizlet API.
###

get: (resource, params, cb) ->
###
Gets the given resource.
###
cb {}

getUser: (username, cb) ->
@get "users/#{username}", {}, cb

exports.Public = class QuizletPublic extends QuizletAPI

constructor: (@clientId) ->
###
Creates a new Quizlet API interface instance.
###

get: (resource, params, cb) ->
params.client_id = @clientId
request.get(baseURL + resource + '?' + querystring.stringify(params)).end (res) ->
cb res.body

exports.Authed = class QuizletAuthed extends QuizletAPI

18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{
"name": "quizlet",
"description": "Quizlet Node.js API interface",
"author": "Ian Macalinao <ianmacalinao@gmail.com>",
"version": "0.0.1",
"scripts": {
"test": "make test"
},
"dependencies": {
"superagent": "*",
"coffee-script": "*",
"oauth": "*"
},
"devDependencies": {
"mocha": "*",
"should": "*"
}
}
2 changes: 2 additions & 0 deletions test/config_sample.coffee
@@ -0,0 +1,2 @@
module.exports =
clientId: 'YOUR-CLIENT-ID'
4 changes: 4 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,4 @@
--require should
--reporter spec
--ui bdd
--compilers coffee:coffee-script
12 changes: 12 additions & 0 deletions test/tests.coffee
@@ -0,0 +1,12 @@
Quizlet = require '../lib/index'
config = require './config'

describe 'QuizletPublic', ->
describe '#getUser', ->
beforeEach ->
@api = new Quizlet.Public config.clientId

it 'should get the details of a user', (done) ->
@api.getUser 'simplyianm', (user) ->
user.username.should.equal 'simplyianm'
done()

0 comments on commit 1c91a1e

Please sign in to comment.