Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

begin coffee rewrite and add actual testing framework

  • Loading branch information...
commit 4b96bc6e54959a6eced949d7265e00dc223fbba1 1 parent d12ce80
@phated authored
View
4 Makefile
@@ -0,0 +1,4 @@
+test:
+ ./node_modules/mocha/bin/mocha
+
+.PHONY: test
View
2  index.js
@@ -0,0 +1,2 @@
+require('coffee-script');
+module.exports = require('./lib/gapi.coffee');
View
13 lib/config.coffee
@@ -0,0 +1,13 @@
+config =
+ api:
+ key: null
+ error: (err) ->
+ err.message += ['. Please define \'', err.arguments[0], '\' inside your arguments.'].join('') if err.type is 'non_object_property_load'
+ console.error err.message
+ requestOptions:
+ host: 'www.googleapis.com'
+ port: 443
+ path: ''
+ method: 'GET'
+
+module.exports = config
View
19 lib/config.js
@@ -1,19 +0,0 @@
-var config = {
- api : {
- key: null
- },
- error : function(err) {
- if(err.type === 'non_object_property_load') {
- err.message += ['. Please define \'', err.arguments[0], '\' inside your arguments.'].join('');
- }
- console.error(err.message);
- },
- requestOptions : {
- host: 'www.googleapis.com',
- port: 443,
- path: '',
- method: 'GET'
- }
-};
-
-module.exports = config;
View
22 lib/execute.coffee
@@ -0,0 +1,22 @@
+config = require('./config')
+https = require('https')
+
+module.exports =
+ execute: (callback) ->
+ output = ''
+
+ req = https.request config.requestOptions, (res) ->
+ res.on 'data', (data) ->
+ output += data
+ res.on 'end', ->
+ callback JSON.parse output
+ res.on 'close', ->
+ res.emit 'end'
+
+ req.end()
+ req.on 'error', (err) ->
+ callback err
+
+ return req
+
+#module.exports = restCall
View
28 lib/execute.js
@@ -1,28 +0,0 @@
-var config = require('./config')
- , https = require('https');
-
-var restCall = {};
-restCall.execute = function(callback){
- var output = '';
-
- var req = https.request(config.requestOptions, function(res) {
- res.on('data', function(data) {
- output += data;
- });
- res.on('end', function() {
- callback(JSON.parse(output));
- });
- res.on('close', function() {
- res.emit('end');
- });
- });
-
- req.end();
- req.on('error', function(err) {
- callback(err);
- });
-
- return req;
-};
-
-module.exports = restCall;
View
10 lib/gapi.coffee
@@ -0,0 +1,10 @@
+config = require('./config')
+
+module.exports =
+ server:
+ setApiKey: (apiKey) ->
+ config.api.key = apiKey
+ load: (apiName, apiVersion, callback) ->
+ apiToLoad = ['./',apiName,'/',apiVersion].join('')
+ this[apiName] = require(apiToLoad)
+ callback()
View
17 lib/gapi.js
@@ -1,17 +0,0 @@
-var config = require('./config');
-
-var init = function() {
- var gapi = {};
- gapi.server = {};
- gapi.server.setApiKey = function(apiKey) {
- config.api.key = apiKey;
- };
- gapi.server.load = function(apiName, apiVersion, callback) {
- var apiToLoad = ['./',apiName,'/',apiVersion].join('');
- this[apiName] = require(apiToLoad);
- callback();
- };
- return gapi;
-}
-
-module.exports = init();
View
10 package.json
@@ -5,12 +5,16 @@
"homepage":"http://github.com/phated/node-gapi",
"repository":"git://github.com/phated/node-gapi.git",
"author":"Phated <blaine@iceddev.com> (http://iceddev.com/)",
- "main":"./lib/gapi.js",
+ "main":"./index.js",
"scripts":{
- "test":"node ./tests/tests.js"
+ "test":"make test"
},
"dependencies":{
- "should":"*"
+ "coffee-script":"*"
+ },
+ "devDependencies":{
+ "should":"*",
+ "mocha":"*"
},
"engines":{
"node":">= 0.4.0"
View
4 test/mocha.opts
@@ -0,0 +1,4 @@
+--require coffee-script
+--require should
+--reporter spec
+--ui bdd
View
0  tests/plus/activities/get.js → test/plus/activities/get.js
File renamed without changes
View
0  tests/plus/activities/list.js → test/plus/activities/list.js
File renamed without changes
View
0  tests/plus/activities/search.js → test/plus/activities/search.js
File renamed without changes
View
0  tests/plus/comments/get.js → test/plus/comments/get.js
File renamed without changes
View
0  tests/plus/comments/list.js → test/plus/comments/list.js
File renamed without changes
View
0  tests/plus/people/get.js → test/plus/people/get.js
File renamed without changes
View
0  tests/plus/people/listByActivity.js → test/plus/people/listByActivity.js
File renamed without changes
View
0  tests/plus/people/search.js → test/plus/people/search.js
File renamed without changes
View
20 test/test.coffee
@@ -0,0 +1,20 @@
+describe 'requiring gapi module', ->
+ it 'should contain the server namespace', ->
+ gapi = require '../index'
+ gapi.should.have.property 'server'
+ describe 'server namespace', ->
+ it 'shoud contain the setApiKey function', ->
+ gapi.server.should.have.property 'setApiKey'
+ gapi.server.setApiKey.should.be.a 'function'
+ describe 'calling setApiKey', ->
+ it 'should set config.api.key to the value of first parameter', ->
+ gapi.server.setApiKey '1111'
+ config = require '../lib/config.coffee'
+ config.api.key.should.equal '1111'
+ it 'should contain the load function', ->
+ gapi.server.should.have.property 'load'
+ gapi.server.load.should.be.a 'function'
+ describe 'calling load with "plus" and "v1"', ->
+ it 'should add plus namespace to gapi.server', ->
+ gapi.server.load 'plus', 'v1', ->
+ gapi.server.should.have.property 'plus'
View
0  tests/tests.js → test/tests.js.old
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.