-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
support | ||
test | ||
examples | ||
*.sock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
0.0.1 / 2010-01-03 | ||
================== | ||
|
||
* Initial release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
test: | ||
@./node_modules/.bin/mocha \ | ||
--require should \ | ||
--reporter spec | ||
|
||
.PHONY: test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
# get | ||
|
||
Get stuff | ||
|
||
## License | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2012 Charlie Rudenstål <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* get | ||
* Copyright(c) 2012 Charlie Rudenstål <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
var get = require('../'); | ||
get(process.argv, function(err, r) { | ||
console.log(r); | ||
//process.stdout.write(r + '\n'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require('streamline').register({ | ||
fibers: false, | ||
cache: true, | ||
verbose: true | ||
}); | ||
|
||
module.exports = require('./lib/get'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* get | ||
* Copyright(c) 2012 Charlie Rudenstål <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
module.exports = get; | ||
|
||
function get(args, _) { | ||
|
||
// Remove first argument: engine executing this app 'node' | ||
args.shift(); | ||
|
||
// Remove second argument: name/alias of this executable | ||
args.shift(); | ||
|
||
// Get source name, ie tvnu | ||
var name = args.shift(); | ||
|
||
try { | ||
// Prepare helpers | ||
var helpers = {}; | ||
helpers.request = require('request'); | ||
helpers.json = require('../lib/helpers/json'); | ||
|
||
// Get source | ||
var source = require('../sources/' + name); | ||
|
||
// Call action in source, call index if it doesn't exist | ||
action = action in source ? action : 'index'; | ||
|
||
// Get source action, default to index if it doesn't exist | ||
var action = args.shift(); | ||
if(action in source == false) { | ||
args.unshift(action); // probably a param if not a valid action. leave args alone. | ||
action = 'index'; | ||
} | ||
|
||
// Get source parameter | ||
var param = args.join(' '); | ||
|
||
// Call source with action and parameter | ||
var respon = source[action].apply_(_, helpers, [param]); | ||
|
||
// Autoresolve if this is a response from the | ||
// get helper that hasn't been resolved | ||
if(typeof respon === 'object' && 'get' in respon) respon = respon.get(); | ||
|
||
} catch(e) { | ||
console.log(e); | ||
} | ||
|
||
return respon; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var request = require('request'); | ||
module.exports = function(url, _) { | ||
var r = JSON.parse(request(url, _).body); | ||
return { | ||
get: function(keyORmapFunc) { | ||
if(typeof keyORmapFunc == 'string') { | ||
r = r[keyORmapFunc] || []; | ||
return this; | ||
} | ||
else if(typeof keyORmapFunc == 'function') { | ||
r = r.map(keyORmapFunc); | ||
r = r.filter(function(x) { | ||
return x !== null && | ||
x !== undefined && | ||
(typeof x !== 'object' || Object.keys(x).length !== 0) // don't include empty objects/arrays | ||
}); | ||
return this; | ||
} | ||
return r; | ||
}, | ||
getEach: function(key) { | ||
if(typeof key == 'string' || typeof key == 'number') { | ||
return this.get(function(x) { | ||
return x[key] || {}; | ||
}); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.