var P4NodeApi = require("./lib/p4nodeapi").P4NodeApi; var restify = require('restify'); var p4 = new P4NodeApi({ "user":"matt_attaway", "port":"workshop.perforce.com:1666" }); function respond(req, res, next) { res.send('hello ' + req.params.name); } var server = restify.createServer(); server.get('/hello/:name', respond); server.head('/hello/:name', respond); server.get('/user/:name', function (req, res, next) { p4.run(['user','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/users', function (req, res, next) { p4.run(['users'], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/group/:name', function (req, res, next) { p4.run(['group','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/groups', function (req, res, next) { p4.run(['groups'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/branch/:name', function (req, res, next) { p4.run(['branch','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/branches', function (req, res, next) { p4.run(['branches'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/client/:name', function (req, res, next) { p4.run(['client','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/clients', function (req, res, next) { p4.run(['clients'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/workspace/:name', function (req, res, next) { p4.run(['client','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/workspaces', function (req, res, next) { p4.run(['clients'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/label/:name', function (req, res, next) { p4.run(['label','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/labels', function (req, res, next) { p4.run(['labels'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/job/:name', function (req, res, next) { p4.run(['job','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/jobs', function (req, res, next) { p4.run(['jobs'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/depot/:name', function (req, res, next) { p4.run(['depot','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/depots', function (req, res, next) { p4.run(['depots'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/change/:name', function (req, res, next) { p4.run(['change','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/changes', function (req, res, next) { p4.run(['changes'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/changelist/:name', function (req, res, next) { p4.run(['change','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/changelists', function (req, res, next) { p4.run(['changes'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/stream/:name', function (req, res, next) { p4.run(['stream','-o', req.params.name], function(e,d) { console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.get('/streams', function (req, res, next) { p4.run(['streams'], function(e,d){ console.log("Error: \n",e); res.json( 200, JSON.parse(d)); }); }) server.listen(8080, function() { console.log('%s listening at %s', server.name, server.url); });
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 8551 | Matt Attaway |
Very rough draft of a node-based web service for Perforce This change adds queries for all the major Perforce metadata objects. It doesn't handle errors in any sort of reasonable manner; all of these commands are just in place to stress the p4nodeapi and help me test it. Far from production quality, but already pretty handy. |
||
#1 | 8548 | Matt Attaway |
Start of a simple node based REST API for Perforce using the p4nodeAPI To run this yourself build the p4nodeapi and then drop the resulting .node file into a directory called lib next to this app.js file. Please note I have no idea what I'm doing. Right now this actually will generate real results but I consider that a happy accident. |