Skip to content

Commit

Permalink
Working version for npm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Yoder committed Nov 22, 2011
1 parent 32e131b commit 475cab6
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 6,382 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ log
*.log
tmp
node_modules
.*
npm_debug.log
.*
38 changes: 2 additions & 36 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@ run = (command) ->
child


task 'docs', 'generate the inline documentation', ->
command = {
line: [
'rm -r docs'
'node_modules/docco/bin/docco lib/*.js lib/surf/*.js'
].join(' && '),
}
run command

task 'test', 'run all the specs', ->
commands = {
server: {
line: "node_modules/rephraser/bin/rephraser spec/rephraser.conf",
line: "node_modules/rephraser/bin/rephraser test/rephraser.conf",
handler: (data) ->
sys.print data
# we're assuming here that output to stdout
Expand All @@ -31,34 +22,9 @@ task 'test', 'run all the specs', ->
commands.server.child.kill()
},
specs: {
line: "node_modules/vows/bin/vows --spec spec/*.js",
line: "node_modules/vows/bin/vows --spec test/*.js",
}
}
exec "mkdir log ; mkdir log/specs",(error,stdin,stdout) ->
commands.server.child = run commands.server

task 'bundle', 'Generate the browser bundle for chat.js', (options)->
fs = require 'fs'
path = require 'path'
browserify = require 'browserify'
module = path.join __dirname, 'lib', 'surf'
bundle = path.join __dirname, 'spec', 'browser', 'surf.js'

src = browserify({
# filter : require('uglify-js')
require: {
# 'surf': module
}
}).require(module).bundle()

buffer = new Buffer [
'var Surf = (function () {'
src
'; return require("./surf.js")'
'})()'
].join '';

fs.writeFile bundle, buffer, (err) ->
throw err if err;

console.log bundle + ' written (' + buffer.length + ' bytes)'
12 changes: 6 additions & 6 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Introduction

Surf is an HTTP client library that makes writing clients fun and easy.
Shred is an HTTP client library that makes writing clients fun and easy.

// we'll omit this part in future examples
var Surf = require("surf")
, surfer = Surf.new()
var Shred = require("shred")
, shred = Shred.new()
;

surfer.get({
shred.get({
url: "http://shark.com/",
headers: {
accept: "application/json"
Expand All @@ -19,11 +19,11 @@ Surf is an HTTP client library that makes writing clients fun and easy.
}
});

The response was JSON, but Surf handles that for you because we specified `application/json` in the `Accept` header. So we're able to access it via `response.body.json`.
The response was JSON, but Shred handles that for you because we specified `application/json` in the `Accept` header. So we're able to access it via `response.body.json`.

Here's another example:

surfer.post({
shred.post({
url: home.sessions.url
headers: {
accept: shark.types["1.0"].session,
Expand Down
186 changes: 0 additions & 186 deletions docs/docco.css

This file was deleted.

13 changes: 0 additions & 13 deletions examples/simple.js

This file was deleted.

14 changes: 7 additions & 7 deletions lib/shred.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ var _ = require("underscore")
;

var Modules = {
Request: require("./surf/request"),
Response: require("./surf/response")
Request: require("./shred/request"),
Response: require("./shred/response")
}

var Surf = function(options) {
var Shred = function(options) {
options = (options||{});
this.defaults = options.defaults||{};
this.log = options.logger||(new Ax({ level: "info" }));
};

_.extend(Surf, Modules);
_.extend(Shred, Modules);

var Methods = {
request: function(options) {
return new Surf.Request(this, _.defaults(options,this.defaults));
return new Shred.Request(this, _.defaults(options,this.defaults));
}
};

Expand All @@ -28,6 +28,6 @@ var Methods = {
};
});

_.extend(Surf.prototype, Methods);
_.extend(Shred.prototype, Methods);

module.exports = Surf;
module.exports = Shred;
6 changes: 3 additions & 3 deletions lib/shred/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ _.extend(Request.prototype,{
var headers = _(request.headers).reduce(function(array,value,key){
array.push("\t" + key + ": " + value); return array;
},[]).join("\n");
var summary = ["<Surf Request> ", request.method.toUpperCase(),
var summary = ["<Shred Request> ", request.method.toUpperCase(),
request.url].join(" ")
return [ summary, "- Headers:", headers].join("\n");
},
Expand Down Expand Up @@ -195,7 +195,7 @@ var Private = {

request.query = options.query||options.parameters;
request.method = options.method;
request.setHeader("User-Agent","Surf for Node.js, Version 0.1.0");
request.setHeader("User-Agent","Shred for Node.js, Version 0.1.0");
request.setHeaders(options.headers);
if (options.body||options.content) {
request.content = options.body||options.content;
Expand All @@ -205,7 +205,7 @@ var Private = {
},
createRequest: function(request) {
var timeout
, surfer = request.client
, shred = request.client
;

request.log.debug("Creating request ..");
Expand Down
2 changes: 1 addition & 1 deletion lib/shred/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Response.prototype = {
var headers = _(response.headers).reduce(function(array,value,key){
array.push("\t" + key + ": " + value); return array;
},[]).join("\n");
var summary = ["<Surf Response> ", response.status].join(" ")
var summary = ["<Shred Response> ", response.status].join(" ")
return [ summary, "- Headers:", headers].join("\n");
}
};
Expand Down
Loading

0 comments on commit 475cab6

Please sign in to comment.