Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Damon Oehlman
committed
Sep 19, 2012
1 parent
f67a453
commit 51af335
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var debug = require('debug')('getit-gist'); | ||
|
||
module.exports = function(parts, original) { | ||
var endpoint; | ||
|
||
debug('running gist scheme remapper on: ' + original, parts); | ||
|
||
// map the endpoint to the gist first of all | ||
endpoint = 'https://raw.github.com/gist/' + parts.host; | ||
|
||
// if a pathname has been extracted from the original url, then append that to the request | ||
if (parts.pathname) { | ||
endpoint += '/' + parts.pathname.replace(/^\//, ''); | ||
} | ||
|
||
return endpoint; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var assert = require('assert'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
getit = require('../'), | ||
testfile = path.resolve(__dirname, 'test.txt'), | ||
testContent, | ||
opts = { | ||
cwd: __dirname | ||
}; | ||
|
||
describe('streamed download test', function() { | ||
before(function(done) { | ||
fs.readFile(path.resolve(__dirname, 'files/test.txt'), 'utf8', function(err, data) { | ||
if (! err) { | ||
testContent = data; | ||
} | ||
|
||
done(err); | ||
}); | ||
}); | ||
|
||
it('should be able to get a local file', function(done) { | ||
getit('files/test.txt', opts, function(err, data) { | ||
assert.ifError(err); | ||
assert.equal(data, testContent); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var assert = require('assert'), | ||
getit = require('../'), | ||
snippet1, snippet2; | ||
|
||
describe('gist scheme test', function() { | ||
before(function(done) { | ||
getit('https://raw.github.com/gist/3344823/gistfile1.md', function(err, content) { | ||
snippet1 = content; | ||
done(err); | ||
}); | ||
}); | ||
|
||
before(function(done) { | ||
getit('https://raw.github.com/gist/1261033/bridge-server.js', function(err, content) { | ||
snippet2 = content; | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('should get the first file by gist id only', function(done) { | ||
getit('gist://3344823', function(err, content) { | ||
assert.ifError(err); | ||
assert.equal(content, snippet1); | ||
|
||
done(err); | ||
}); | ||
}); | ||
|
||
it('should get a specified file when specified', function(done) { | ||
getit('gist://3344823/gistfile1.md', function(err, content) { | ||
assert.ifError(err); | ||
assert.equal(content, snippet1); | ||
|
||
done(err); | ||
}); | ||
}); | ||
|
||
it('should error when a non-existant file is requested', function(done) { | ||
getit('gist://3344823/gistfile1.error', function(err, content) { | ||
assert(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get a specified file when the gist has more than one file', function(done) { | ||
getit('gist://1261033/bridge-server.js', function(err, content) { | ||
assert.ifError(err); | ||
assert.equal(content, snippet2); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |