Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add payload timestamp api - closes issue #18

  • Loading branch information...
commit 6c792b06cb87a48255b988e29c191a55453f70d9 1 parent fb97e27
@zaach zaach authored
View
7 client/client.js
@@ -145,6 +145,13 @@ GombotClient.prototype = {
args.path = this.path + '/v1/payload';
authRequest(args, cb);
+ },
+ getTimestamp: function(args, cb) {
+ args = mergeArgs(args, this);
+ args.method = 'get';
+ args.path = this.path + '/v1/payload/timestamp';
+
+ authRequest(args, cb);
}
};
View
3  lib/api/v1/payload.js
@@ -32,7 +32,7 @@ module.exports = [
response: {
success: B(),
payload: S().required(),
- updated: N()
+ updated: N().required()
}
}
}
@@ -53,7 +53,6 @@ function get(request) {
var id = request.session.id;
db.getPayload(id, function(err, doc) {
if (err) return request.reply(Hapi.Error.internal("Could not retreive payload: " + err));
- console.log(doc);
request.reply({
success: true,
payload: doc.payload,
View
32 lib/api/v1/payload/timestamp.js
@@ -0,0 +1,32 @@
+var Hapi = require('hapi');
+var db = require('../../../db.js');
+
+var B = Hapi.Types.Boolean;
+var S = Hapi.Types.String;
+var N = Hapi.Types.Number;
+
+module.exports = {
+ method: 'GET',
+ handler: handler,
+ auth: {
+ mode: 'hawk'
+ },
+ config: {
+ description: 'Retreive last update time of user credentials',
+ response: {
+ success: B(),
+ updated: N().required()
+ }
+ }
+};
+
+function handler(request) {
+ var id = request.session.id;
+ db.getPayload(id, function(err, doc) {
+ if (err) return request.reply(Hapi.Error.internal("Could not retreive payload update time: " + err));
+ request.reply({
+ success: true,
+ updated: doc.timestamp
+ });
+ });
+}
View
71 test/api.v1.payload.timestamp.js
@@ -0,0 +1,71 @@
+const
+should = require('should'),
+runner = require('./lib/runner.js'),
+Client = require('../client/client.js');
+
+var servers;
+var client;
+
+var test_user = 'foo@payload.com';
+var test_pass = 'bar';
+
+describe('the servers', function() {
+ it('should start up', function(done) {
+ runner(function(err, r) {
+ should.not.exist(err);
+ should.exist(r);
+ servers = r;
+ client = new Client('http://' + servers.host + ':' + servers.port);
+ done();
+ });
+ });
+});
+
+function createAccount(email, pass, cb) {
+ client.account({
+ email: email,
+ pass: pass
+ }, function(err, r) {
+ if (err) cb(err);
+ cb(null, client.key);
+ });
+}
+
+describe("/api/v1/payload/timestamp", function() {
+ it ('should store payload', function(done) {
+ createAccount(test_user, test_pass, function() {
+ try {
+ client.storePayload({
+ payload: 'foo'
+ }, function(err, r) {
+ should.not.exist(err);
+ should.exist(r);
+ done();
+ });
+ } catch (e) {
+ done(e);
+ }
+ });
+ });
+ it ('should get payload timestamp', function(done) {
+ try {
+ client.getTimestamp({}, function(err, r) {
+ should.not.exist(err);
+ should.exist(r);
+ should.exist(r.updated);
+ done();
+ });
+ } catch (e) {
+ done(e);
+ }
+ });
+});
+
+describe('the servers', function() {
+ it('should stop', function(done) {
+ servers.stop(function(err) {
+ should.not.exist(err);
+ done();
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.