Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vinli

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinli - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

lib/event.js

42

lib/app.js
var Utils = require('./utils');
var Device = require('./device');
var Joi = require('joi');
var Hoek = require('hoek');
exports.addDevice = function(_options) {
Joi.assert(_options, Joi.object().keys({
id: Joi.string(),
caseId: Joi.string()
}).xor('id', 'caseId').required());
module.exports = function(client) {
return {
addDevice: function(_options) {
Joi.assert(_options, Joi.object().keys({
id: Joi.string(),
caseId: Joi.string()
}).xor('id', 'caseId').required());
return Utils.request.post('platform', 'devices', {
device: _options
}).then(function(resp) {
return new Device({ id: resp.device.id, caseId: _options.caseId });
});
};
return client.post('platform', 'devices', {
device: _options
}).then(function(resp) {
return new client.Device({ id: resp.device.id, caseId: _options.caseId });
});
},
exports.devices = function(_options) {
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options);
Joi.assert(_options || {}, Utils.paginationOptions);
devices: function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options);
Joi.assert(_options || {}, Utils.paginationOptions);
return Utils.request.get('platform', 'devices', _options).then(function(resp) {
resp.devices = resp.devices.map(function(v) { return new Device(v); });
return Utils.listResponse(resp, 'devices', exports.devices);
});
return client.get('platform', 'devices', _options).then(function(resp) {
resp.devices = resp.devices.map(function(v) { return new client.Device(v); });
return Utils.listResponse(resp, 'devices', self.devices);
});
}
};
};

@@ -1,27 +0,25 @@

var Utils = require('./utils');
var extend = require('extend');
var yarp = require('yarp');
var Auth = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Auth = { };
Auth.exchange = function(authCode, redirectUri, clientId, clientSecret) {
return yarp({
url: Utils.request.buildUrl('auth', 'oauth/token', {}, true),
method: 'POST',
json: {
grant_type: 'authorization_code',
code: authCode,
redirect_uri: redirectUri
},
auth: {
user: clientId,
pass: clientSecret
}
}).then(function(resp) {
return resp.access_token;
});
};
Auth.exchange = function(authCode, redirectUri, clientId, clientSecret) {
return yarp({
url: client.buildUrl('auth', 'oauth/token', {}, true),
method: 'POST',
json: {
grant_type: 'authorization_code',
code: authCode,
redirect_uri: redirectUri
},
auth: {
user: clientId,
pass: clientSecret
}
}).then(function(resp) {
return resp.access_token;
});
};
module.exports = Auth;
return Auth;
};
var Hoek = require('hoek');
var Joi = require('joi');
var Utils = require('./utils');
var yarp = require('yarp');
var URL = require('url');

@@ -12,26 +13,149 @@ var defaultOptions = {

module.exports = function(_options) {
var groupPrefix = {
platform: 'platform',
auth: 'auth',
telemetry: 'telemetry',
event: 'events',
rule: 'rules',
trip: 'trips',
safety: 'safety'
};
var Client = function(_options) {
Joi.assert(_options, Joi.object({
hostBase: Joi.string().regex(/^[-_\.\da-zA-Z]+$/),
protocol: Joi.string().allow([ 'http', 'https' ]),
port: Joi.number().integer().min(1),
apiVersion: Joi.string().allow([ 'v1' ]),
appId: Joi.string(),
secretKey: Joi.string(),
accessToken: Joi.string(),
serviceOrigins: Joi.object({
platform: Joi.string().uri().required(),
auth: Joi.string().uri().required(),
telemetry: Joi.string().uri().required(),
event: Joi.string().uri().required(),
rule: Joi.string().uri().required(),
trip: Joi.string().uri().required(),
safety: Joi.string().uri().required()
}).optional()
}).required()
.and('appId', 'secretKey')
.xor('appId', 'accessToken')
.nand('hostBase', 'serviceOrigins')
.nand('protocol', 'serviceOrigins')
.nand('port', 'serviceOrigins'));
this.options = Hoek.applyToDefaults(defaultOptions, _options);
Joi.assert(this.options, Joi.object({
hostBase: Joi.string().required().regex(/^[-_\.\da-zA-Z]+$/),
protocol: Joi.string().required().allow([ 'http', 'https' ]),
port: Joi.number().integer().required().min(1),
apiVersion: Joi.string().required(),
appId: Joi.string().required(),
secretKey: Joi.string().required()
}).required());
if (this.options.accessToken) {
this.authHeaders = {
authorization: 'Bearer ' + this.options.accessToken
};
} else {
this.authHeaders = {
authorization: 'Basic ' + (new Buffer(this.options.appId + ':' + this.options.secretKey, 'utf8')).toString('base64')
};
}
Utils.request.options = this.options;
this.App = require('./app')(this);
this.User = require('./user')(this);
this.Auth = require('./auth')(this);
this.Device = require('./device')(this);
this.Vehicle = require('./vehicle')(this);
this.Trip = require('./trip')(this);
this.Event = require('./event')(this);
this.Subscription = require('./subscription')(this);
this.Rule = require('./rule')(this);
};
return {
App: require('./app'),
Device: require('./device'),
Vehicle: require('./vehicle'),
Trip: require('./trip'),
User: require('./user'),
Rule: require('./rule'),
EmergencyContact: require('./emergency_contact'),
Auth: require('./auth')
};
Client.prototype.originForGroup = function(group) {
if (this.options.serviceOrigins) {
return this.options.serviceOrigins[group];
}
return URL.format({
protocol: this.options.protocol,
hostname: groupPrefix[group] + this.options.hostBase,
port: this.options.port
});
};
Client.prototype.buildUrl = function(_group, _path, _query, _skipPrefix) {
return URL.resolve(
this.originForGroup(_group),
URL.format({
pathname: (_skipPrefix ? '' : ('/api/' + this.options.apiVersion)) + '/' + _path,
query: _query
})
);
};
Client.prototype.getRaw = function(url) {
return yarp({
url: url,
headers: this.authHeaders
});
};
Client.prototype.authGet = function(_path, _accessToken) {
return yarp({
url: this.buildUrl('auth', _path, { access_token: _accessToken }, true)
});
};
Client.prototype.get = function(_group, _path, _query) {
return this.getRaw(this.buildUrl(_group, _path, _query));
};
Client.prototype.post = function(_group, _path, _payload, _skipPrefix) {
return yarp({
url: this.buildUrl(_group, _path, {}, _skipPrefix),
method: 'POST',
json: _payload,
headers: this.authHeaders
});
};
Client.prototype.put = function(_group, _path, _payload) {
return yarp({
url: this.buildUrl(_group, _path),
method: 'PUT',
json: _payload,
headers: this.authHeaders
});
};
Client.prototype.delete = function(_group, _path) {
return yarp({
url: this.buildUrl(_group, _path),
method: 'DELETE',
headers: this.authHeaders
});
};
Client.prototype.getEntireStream = function(url, listName) {
return this.getRaw(url).then(function(data) {
if (data.meta.pagination.links.prior) {
return this.getEntireStream(data.meta.pagination.links.prior, listName).then(function(locs) {
return data[listName].concat(locs);
});
}
return data[listName];
});
};
Client.prototype.getEntireLocationStream = function(url) {
return this.getRaw(url).then(function(data) {
if (data.meta.pagination.links.prior) {
return this.getEntireLocationStream(data.meta.pagination.links.prior).then(function(locs) {
return data.locations.features.concat(locs);
});
}
return data.locations.features;
});
};
module.exports = Client;
var Utils = require('./utils');
var Hoek = require('hoek');
var Joi = require('joi');
var Vehicle = require('./vehicle');
var Trip = require('./trip');
var Rule = require('./rule');
var EmergencyContact = require('./emergency_contact');
var extend = require('extend');
var Device = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Device = function(_obj) {
extend(this, _obj);
};
Device.prototype.type = 'Device';
Device.prototype.type = 'Device';
Device.prototype.vehicles = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options);
Joi.assert(_options || {}, Utils.paginationOptions);
Device.prototype.vehicles = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options);
Joi.assert(_options || {}, Utils.paginationOptions);
return Utils.request.get(
'platform',
'devices/' + this.id + '/vehicles',
_options
).then(function(resp) {
resp.vehicles = resp.vehicles.map(function(v) { return new Vehicle(v); });
return Utils.listResponse(resp, 'vehicles', self.vehicles, self);
});
};
return client.get(
'platform',
'devices/' + this.id + '/vehicles',
_options
).then(function(resp) {
resp.vehicles = resp.vehicles.map(function(v) { return new client.Vehicle(v); });
return Utils.listResponse(resp, 'vehicles', self.vehicles, self);
});
};
Device.prototype.latestVehicle = function() {
return Utils.request.get(
'platform',
'devices/' + this.id + '/vehicles/_latest'
).then(function(resp) {
if (!resp.vehicle) {
return null;
}
return new Vehicle(resp.vehicle);
});
};
Device.prototype.messages = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
return Utils.request.get(
'telemetry',
'devices/' + self.id + '/messages',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'messages', self.messages, self);
Device.prototype.latestVehicle = function() {
return client.get(
'platform',
'devices/' + this.id + '/vehicles/_latest'
).then(function(resp) {
if (!resp.vehicle) {
return null;
}
return new client.Vehicle(resp.vehicle);
});
};
};
Device.prototype.message = function(messageId) {
return Utils.request.get(
'telemetry',
'devices/' + this.id + '/messages/' + messageId
).then(function(resp) {
return resp.message;
});
};
Device.prototype.messages = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
Device.prototype.snapshots = function(_options) {
var self = this;
var fields = _options.fields;
delete _options.fields;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
return client.get(
'telemetry',
'devices/' + self.id + '/messages',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'messages', self.messages, self);
});
};
if (Array.isArray(fields)) {
_options.fields = fields.join(',');
} else {
_options.fields = fields;
}
return Utils.request.get(
'telemetry',
'devices/' + self.id + '/snapshots',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'snapshots', self.snapshots, self);
Device.prototype.message = function(messageId) {
return client.get(
'telemetry',
'devices/' + this.id + '/messages/' + messageId
).then(function(resp) {
return resp.message;
});
};
};
Device.prototype.locations = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
Device.prototype.snapshots = function(_options) {
var self = this;
var fields = _options.fields;
delete _options.fields;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
return Utils.request.get(
'telemetry',
'devices/' + self.id + '/locations',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'locations', self.locations, self);
});
};
if (Array.isArray(fields)) {
_options.fields = fields.join(',');
} else {
_options.fields = fields;
}
Device.prototype.events = function(_options) {
var self = this;
return client.get(
'telemetry',
'devices/' + self.id + '/snapshots',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'snapshots', self.snapshots, self);
});
};
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, {
limit: Joi.number().integer().min(0).max(100),
since: Joi.date(),
until: Joi.date(),
type: Joi.string()
});
Device.prototype.locations = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
return Utils.request.get(
'events',
'devices/' + self.id + '/events',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'events', self.events, self);
});
};
return client.get(
'telemetry',
'devices/' + self.id + '/locations',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'locations', self.locations, self);
});
};
Device.prototype.trips = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
Device.prototype.events = function(_options) {
var self = this;
return Utils.request.get(
'trips',
'devices/' + this.id + '/trips',
_options).then(function(resp) {
resp.trips = resp.trips.map(function(v) { return new Trip(v); });
return Utils.listResponse(resp, 'trips', self.trips, self);
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, {
limit: Joi.number().integer().min(0).max(100),
since: Joi.date(),
until: Joi.date(),
type: Joi.string()
});
};
Device.prototype.rules = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return client.get(
'event',
'devices/' + self.id + '/events',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'events', self.events, self);
});
};
return Utils.request.get(
'rules',
'devices/' + this.id + '/rules',
_options).then(function(resp) {
resp.rules = resp.rules.map(function(v) { return new Rule(v); });
return Utils.listResponse(resp, 'rules', self.rules, self);
});
};
Device.prototype.trips = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
Device.prototype.createRule = function(_payload) {
return Utils.request.post(
'rules',
'devices/' + this.id + '/rules',
{ rule: _payload }).then(function(resp) {
return new Rule(resp.rule);
});
};
return client.get(
'trip',
'devices/' + this.id + '/trips',
_options).then(function(resp) {
resp.trips = resp.trips.map(function(v) { return new client.Trip(v); });
return Utils.listResponse(resp, 'trips', self.trips, self);
});
};
Device.prototype.emergencyContacts = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
Device.prototype.rules = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return Utils.request.get(
'safety',
'devices/' + this.id + '/emergency_contacts',
_options).then(function(resp) {
resp.trips = resp.emergencyContacts.map(function(v) { return new EmergencyContact(v); });
return Utils.listResponse(resp, 'emergencyContacts', self.emergencyContacts, self);
});
};
return client.get(
'rule',
'devices/' + this.id + '/rules',
_options).then(function(resp) {
resp.rules = resp.rules.map(function(v) { return new client.Rule(v); });
return Utils.listResponse(resp, 'rules', self.rules, self);
});
};
Device.prototype.createEmergencyContact = function(_payload) {
return Utils.request.post(
'safety',
'devices/' + this.id + '/emergency_contacts',
{ emergencyContact: _payload }).then(function(resp) {
return new EmergencyContact(resp.emergencyContact);
Device.prototype.createRule = function(_payload) {
return client.post(
'rule',
'devices/' + this.id + '/rules',
{ rule: _payload }).then(function(resp) {
return new client.Rule(resp.rule);
});
};
Device.fetch = function(id) {
return client.get('platform', 'devices/' + id).then(function(resp) {
return new Device(resp.device);
});
};
};
Device.fetch = function(id) {
return Utils.request.get('platform', 'devices/' + id).then(function(resp) {
return new Device(resp.device);
});
};
Device.forge = function(id) {
return new Device({ id: id });
};
Device.forge = function(id) {
return new Device({ id: id });
};
module.exports = Device;
return Device;
};
var Utils = require('./utils');
var Subscription = require('./subscription');
var extend = require('extend');

@@ -7,75 +6,94 @@ var Hoek = require('hoek');

var Rule = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Rule = function(_obj) {
extend(this, _obj);
};
Rule.fetch = function(deviceId, id) {
return Utils.request.get('rules', 'devices/' + deviceId + '/rules/' + id).then(function(resp) {
return new Rule(resp.rule);
});
};
Rule.fetch = function(id) {
return client.get('rule', 'rules/' + id).then(function(resp) {
return new Rule(resp.rule);
});
};
Rule.forge = function(id) {
return new Rule({ id: id });
};
Rule.forge = function(id) {
return new Rule({ id: id });
};
Rule.prototype.delete = function() {
return Utils.request.delete('rules', 'devices/' + this.deviceId + '/rules/' + this.id);
};
Rule.prototype.delete = function() {
return client.delete('rule', 'rules/' + this.id);
};
Rule.prototype.fill = function() {
var self = this;
return Utils.request.getRaw(self.links.self).then(function(resp) {
console.log(resp);
self.boundaries = resp.rule.boundaries;
return self;
});
};
Rule.prototype.fill = function() {
var self = this;
return client.getRaw(self.links.self).then(function(resp) {
self.boundaries = resp.rule.boundaries;
return self;
});
};
Rule.prototype.subscriptions = function() {
var self = this;
Rule.prototype.subscriptions = function(deviceId) {
var self = this;
return Utils.request.get(
'events',
'devices/' + this.deviceId + '/subscriptions',
{ objectType: 'rule', objectId: this.id }
).then(function(resp) {
resp.subscriptions = resp.subscriptions.map(function(v) { return new Subscription(v); });
return Utils.listResponse(resp, 'subscriptions', self.subscriptions, self);
});
};
deviceId = deviceId || this.deviceId;
Rule.prototype.createSubscription = function(_options) {
var self = this;
Hoek.assert(deviceId, 'The Rule must have deviceId set internally or passed in the options when loading events');
return Utils.request.post(
'events',
'devices/' + this.deviceId + '/subscriptions',
{ subscription: Hoek.merge(_options, { object: { type: 'rule', id: self.id } }) }
).then(function(resp) {
return new Subscription(resp.subscription);
});
};
return client.get(
'event',
'devices/' + deviceId + '/subscriptions',
{ objectType: 'rule', objectId: this.id }
).then(function(resp) {
resp.subscriptions = resp.subscriptions.map(function(v) { return new client.Subscription(v); });
return Utils.listResponse(resp, 'subscriptions', self.subscriptions, self);
});
};
Rule.prototype.events = function(_options) {
var self = this;
Rule.prototype.createSubscription = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20, objectId: this.id, type: 'rule' }, _options || {});
Joi.assert(_options, {
limit: Joi.number().integer().min(0).max(100),
since: Joi.date(),
until: Joi.date(),
type: Joi.string(),
objectId: Joi.string(),
objectType: Joi.string()
});
var deviceId = this.deviceId || (_options || {}).deviceId;
if (_options) {
delete _options.deviceId;
}
return Utils.request.get(
'events',
'devices/' + self.deviceId + '/events',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'events', self.events, self);
Hoek.assert(deviceId, 'The Rule must have deviceId set internally or passed in the options when creating a subscripton');
return client.post(
'event',
'devices/' + deviceId + '/subscriptions',
{ subscription: Hoek.merge(_options, { object: { type: 'rule', id: self.id } }) }
).then(function(resp) {
return new client.Subscription(resp.subscription);
});
};
};
module.exports = Rule;
Rule.prototype.events = function(_options) {
var self = this;
var deviceId = this.deviceId || (_options || {}).deviceId;
if (_options) {
delete _options.deviceId;
}
Hoek.assert(deviceId, 'The Rule must have deviceId set internally or passed in the options when loading events');
_options = Hoek.applyToDefaults({ limit: 20, objectId: this.id, type: 'rule' }, _options || {});
Joi.assert(_options, {
limit: Joi.number().integer().min(0).max(100),
since: Joi.date(),
until: Joi.date(),
type: Joi.string(),
objectId: Joi.string(),
objectType: Joi.string()
});
return client.get(
'event',
'devices/' + deviceId + '/events',
_options).then(function(resp) {
return Utils.streamListResponse(resp, 'events', self.events, self);
});
};
return Rule;
};

@@ -6,46 +6,35 @@ var Utils = require('./utils');

var Subscription = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Subscription = function(_obj) {
extend(this, _obj);
};
Subscription.fetch = function(deviceId, id) {
return Utils.request.get('events', 'devices/' + deviceId + '/subscriptions/' + id).then(function(resp) {
return new Subscription(resp.subscription);
});
};
Subscription.fetch = function(id) {
return client.get('event', 'subscriptions/' + id).then(function(resp) {
return new Subscription(resp.subscription);
});
};
Subscription.forge = function(id) {
return new Subscription({ id: id });
};
Subscription.forge = function(id) {
return new Subscription({ id: id });
};
Subscription.prototype.delete = function() {
return Utils.request.delete('events', 'devices/' + this.deviceId + '/subscriptions/' + this.id);
};
Subscription.prototype.delete = function() {
return client.delete('event', 'subscriptions/' + this.id);
};
Subscription.prototype.notifications = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
Subscription.prototype.notifications = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return Utils.request.get(
'events',
'devices/' + this.deviceId + '/subscriptions/' + this.id + '/notifications',
_options).then(function(resp) {
return Utils.listResponse(resp, 'notifications', self.notifications, self);
});
};
return client.get(
'event',
'subscriptions/' + this.id + '/notifications',
_options).then(function(resp) {
return Utils.listResponse(resp, 'notifications', self.notifications, self);
});
};
Subscription.prototype.events = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return Utils.request.get(
'events',
'devices/' + this.deviceId + '/subscriptions/' + this.id + '/events',
_options).then(function(resp) {
return Utils.listResponse(resp, 'events', self.events, self);
});
};
module.exports = Subscription;
return Subscription;
};

@@ -1,35 +0,36 @@

var Utils = require('./utils');
var extend = require('extend');
var qs = require('querystring');
var Trip = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Trip = function(_obj) {
extend(this, _obj);
};
Trip.prototype.locations = function(_options) {
var self = this;
_options = _options || {};
if (_options.all) {
var query = {
limit: 100,
fields: (_options.fields && _options.fields.length) ? _options.fields.join(',') : undefined
};
return Utils.request.getEntireLocationStream(self.links.locations + '&' + qs.stringify(query));
}
Trip.prototype.locations = function(_options) {
var self = this;
_options = _options || {};
if (_options.all) {
var query = {
limit: 100,
fields: (_options.fields && _options.fields.length) ? _options.fields.join(',') : undefined
};
return client.getEntireLocationStream(self.links.locations + '&' + qs.stringify(query));
}
return Utils.request.getRaw(self.links.locations).then(function(resp) {
return resp.locations.features;
});
};
return client.getRaw(self.links.locations).then(function(resp) {
return resp.locations.features;
});
};
Trip.fetch = function(id) {
return Utils.request.get('trips', 'trips/' + id).then(function(resp) {
return new Trip(resp.trip);
});
};
Trip.fetch = function(id) {
return client.get('trip', 'trips/' + id).then(function(resp) {
return new Trip(resp.trip);
});
};
Trip.forge = function(id) {
return new Trip({ id: id });
};
Trip.forge = function(id) {
return new Trip({ id: id });
};
module.exports = Trip;
return Trip;
};

@@ -1,34 +0,34 @@

var Utils = require('./utils');
var Device = require('./device');
var extend = require('extend');
var Hoek = require('hoek');
var User = function(_obj, _accessToken) {
extend(this, _obj);
this.accessToken = _accessToken;
};
module.exports = function(client) {
var User = function(_obj, _accessToken) {
extend(this, _obj);
this.accessToken = _accessToken;
};
User.prototype.devices = function() {
var self = this;
User.prototype.devices = function() {
var self = this;
Hoek.assert(self.accessToken);
return Utils.request.authGet('user/devices', self.accessToken).then(function(resp) {
return {
list: resp.devices.map(function(dev) {
return new Device({ id: dev.id, name: dev.name });
})
};
});
};
Hoek.assert(self.accessToken);
return client.authGet('user/devices', self.accessToken).then(function(resp) {
return {
list: resp.devices.map(function(dev) {
return new client.Device({ id: dev.id, name: dev.name });
})
};
});
};
User.fetch = function(accessToken) {
return Utils.request.authGet('user', accessToken).then(function(resp) {
return new User(resp.user, accessToken);
});
};
User.fetch = function(accessToken) {
return client.authGet('user', accessToken).then(function(resp) {
return new User(resp.user, accessToken);
});
};
User.forge = function(accessToken) {
return new User({}, accessToken);
};
User.forge = function(accessToken) {
return new User({}, accessToken);
};
module.exports = User;
return User;
};
var Joi = require('joi');
var Hoek = require('hoek');
var yarp = require('yarp');
var URL = require('url'); /* jshint ignore:line */
var URL = require('url');

@@ -17,93 +16,2 @@ exports.paginationOptions = Joi.object({

exports.request = {
buildUrl: function(_group, _path, _query, _skipPrefix) {
return URL.format({
protocol: exports.request.options.protocol,
hostname: _group + exports.request.options.hostBase,
port: exports.request.options.port,
pathname: (_skipPrefix ? '' : ('/api/' + exports.request.options.apiVersion)) + '/' + _path,
query: _query
});
},
getRaw: function(url) {
return yarp({
url: url,
auth: {
user: this.options.appId,
pass: this.options.secretKey
}
});
},
authGet: function(_path, _accessToken) {
return yarp({
url: this.buildUrl('auth', _path, { access_token: _accessToken }, true)
});
},
get: function(_group, _path, _query) {
return this.getRaw(this.buildUrl(_group, _path, _query));
},
post: function(_group, _path, _payload, _skipPrefix) {
return yarp({
url: exports.request.buildUrl(_group, _path, {}, _skipPrefix),
method: 'POST',
json: _payload,
auth: {
user: exports.request.options.appId,
pass: exports.request.options.secretKey
}
});
},
put: function(_group, _path, _payload) {
return yarp({
url: exports.request.buildUrl(_group, _path),
method: 'PUT',
json: _payload,
auth: {
user: exports.request.options.appId,
pass: exports.request.options.secretKey
}
});
},
delete: function(_group, _path) {
return yarp({
url: exports.request.buildUrl(_group, _path),
method: 'DELETE',
auth: {
user: exports.request.options.appId,
pass: exports.request.options.secretKey
}
});
},
getEntireStream: function(url, listName) {
return this.getRaw(url).then(function(data) {
if (data.meta.pagination.links.prior) {
return exports.request.getEntireStream(data.meta.pagination.links.prior, listName).then(function(locs) {
return data[listName].concat(locs);
});
}
return data[listName];
});
},
getEntireLocationStream: function(url) {
return this.getRaw(url).then(function(data) {
if (data.meta.pagination.links.prior) {
return exports.request.getEntireLocationStream(data.meta.pagination.links.prior).then(function(locs) {
return data.locations.features.concat(locs);
});
}
return data.locations.features;
});
}
};
var linksToFunctions = function(links, func, thisObj) {

@@ -110,0 +18,0 @@ var tr = {};

var Utils = require('./utils');
var Hoek = require('hoek');
var Joi = require('joi');
var Trip = require('./trip');
var extend = require('extend');
var Vehicle = function(_obj) {
extend(this, _obj);
};
module.exports = function(client) {
var Vehicle = function(_obj) {
extend(this, _obj);
};
Vehicle.prototype.trips = function(_options) {
var self = this;
Vehicle.prototype.trips = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return Utils.request.get(
'trips',
'vehicles/' + this.id + '/trips',
_options).then(function(resp) {
resp.trips = resp.trips.map(function(v) { return new Trip(v); });
return Utils.listResponse(resp, 'trips', self.trips, self);
return client.get(
'trip',
'vehicles/' + this.id + '/trips',
_options).then(function(resp) {
resp.trips = resp.trips.map(function(v) { return new client.Trip(v); });
return Utils.listResponse(resp, 'trips', self.trips, self);
});
};
Vehicle.fetch = function(id) {
return client.get('platform', 'vehicles/' + id).then(function(resp) {
return new Vehicle(resp.vehicle);
});
};
};
Vehicle.fetch = function(id) {
return Utils.request.get('platform', 'vehicles/' + id).then(function(resp) {
return new Vehicle(resp.vehicle);
});
};
Vehicle.forge = function(id) {
return new Vehicle({ id: id });
};
Vehicle.forge = function(id) {
return new Vehicle({ id: id });
};
module.exports = Vehicle;
return Vehicle;
};
{
"name": "vinli",
"version": "0.2.4",
"version": "1.0.0",
"description": "Official Node.js SDK for interacting with the Vinli Platform",

@@ -12,3 +12,4 @@ "main": "index.js",

"test": "mocha --recursive -R spec",
"coverage": "istanbul cover node_modules/.bin/_mocha -- --recursive --reporter list"
"coverage": "istanbul cover node_modules/.bin/_mocha -- --recursive --reporter list",
"lint": "eslint --quiet ."
},

@@ -28,2 +29,3 @@ "author": "Powell Kinney",

"chai-as-promised": "~4.3.0",
"eslint": "^0.21.2",
"istanbul": "^0.3.11",

@@ -30,0 +32,0 @@ "mocha": "~2.2.1",

@@ -19,3 +19,5 @@ Vinli Node.js SDK

```javascript
var Vinli = require('vinli')({
var Vinli = require('vinli')
var client = new Vinli({
appId: 'b3fcb3c2-0b7e-4c9a-a6a1-f53e365c2fd9',

@@ -26,3 +28,12 @@ secretKey: 'C023z8T6f39WSZrLSqqf'

When creating a client, you must pass either a `appId` and `secretKey` or `accessToken`.
```javascript
var Vinli = require('vinli')
var client = new Vinli({
accessToken: 'HWaBnDis9eZcHTMYQpKsE0mfsQT3qgKMRnpaVrivQ9GmhlXtLuE1'
});
```
Objects

@@ -34,5 +45,6 @@ -------

- [Vehicle](#vehicle)
- [Rule](#rule)
- [Event](#event)
- [Subscription](#subscription)
- [Trip](#trip)
- [Rule](#rule)
- [EmergencyContact](#emergencycontact)

@@ -123,3 +135,3 @@

For server applications that use the OAuth client type of "server", this method is used to exchange a user's OAuth token. This method returns a token that the server can use to make calls to Auth Services on behalf of the user. This token is only needed for calls to Auth.
For server applications that use the OAuth client type of "server", this method is used to exchange a user's OAuth token. This method returns a token that the server can use to make calls to Auth Services on behalf of the user.

@@ -205,9 +217,3 @@

### Device's Trips
#### `trips([options])`
Retrieves a list of Trips for the Device. This method returns Trips in reverse chronological order and accepts `limit` and `offset` pagination options.
### Device's Rules

@@ -224,17 +230,16 @@

### Device's Safety Services
#### `collisions([options])`
### Device's Trips
Retrieves a list of Collisions for the Device. Accepts `limit` and `offset` pagination options.
#### `trips([options])`
Retrieves a list of Trips for the Device. This method returns Trips in reverse chronological order and accepts `limit` and `offset` pagination options.
#### `emergencyContacts([options])`
Retrieves a list of EmergencyContacts for the Device. Accepts `limit` and `offset` pagination options.
### Device's Safety Services
#### `collisions([options])`
#### `createEmergencyContact(emergencyContact)`
Retrieves a list of Collisions for the Device. Accepts `limit` and `offset` pagination options.
Creates an EmergencyContact for the Device. EmergencyContacts can be one of two types: `sms` and `voice`. The type of the contact determines the connection made and the available fields.

@@ -256,32 +261,34 @@

Trip
----
Event
-----
#### `Trip.forge(id)`
#### `Event.forge(id)`
Creates a Trip object with the given `id`.
Creates a Event object with the given `id`.
#### `Trip.fetch(id)`
#### `Event.fetch(id)`
Retrieves the Trip from the Vinli Platform with the given `id`.
Retrieves the Event from the Vinli Platform with the given `id`.
#### `messages([options])`
Note: In order to retrieve the messages for a given Trip, the Trip object must have been created by the `fetch` method.
Subscription
------------
Retrieves a part of the stream of messages transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent messages.
#### `Subscription.forge(id)`
#### `locations([fields, options])`
Creates a Subscription object with the given `id`.
Note: In order to retrieve the locations for a given Trip, the Trip object must have been created by the `fetch` method.
#### `Subscription.fetch(id)`
Retrieves a part of the stream of locations transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent locations.
Retrieves the Subscription from the Vinli Platform with the given `id`.
#### `snapshots(fields, [options])`
#### `notifications([options])`
Note: In order to retrieve the snapshot for a given Trip, the Trip object must have been created by the `fetch` method.
Retrieves the Notifications for this Subscription. Accepts `limit` and `offset` pagination options.
Retrieves a part of the stream of snapshots transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent snapshots.
#### `delete()`
Deletes this Subscription.
Rule

@@ -298,2 +305,6 @@ ----

#### `Rule.fill(id)`
Fills in information about the Rule. This is useful in situations where a Rule was retrieved via Device.rules(). When retrieved this way, Rules do not contain boundary information.
#### `events([options])`

@@ -303,6 +314,14 @@

#### `currentState([deviceId])`
#### `subscriptions([options])`
Retrieves the current state of a Rule. If the Rule object was not created using the `fetch` method above, you must provide the `deviceId`.
Retrieves the Subscriptions for this Rule. Accepts `limit` and `offset` pagination options.
#### `createSubscription([options])`
Creates a new Subscription for this Rule. The `options` parameter must have the following:
* `eventType` - Can be 'rule-*', 'rule-enter', or 'rule-leave'
* `url` - URL to call when the subscription is triggered
* `appData` - Optional string containing additional data that will be delivered to the above URL
#### `delete()`

@@ -312,23 +331,30 @@

EmergencyContact
----------------
#### `EmergencyContact.forge(id)`
Trip
----
Creates an EmergencyContact object with the given `id`.
#### `Trip.forge(id)`
#### `EmergencyContact.fetch(id)`
Creates a Trip object with the given `id`.
Retrieves the EmergencyContact from the Vinli Platform with the given `id`.
#### `Trip.fetch(id)`
#### `update(emergencyContact)`
Retrieves the Trip from the Vinli Platform with the given `id`.
Updates the EmergencyContact with the information provided.
#### `messages([options])`
#### `test()`
Note: In order to retrieve the messages for a given Trip, the Trip object must have been created by the `fetch` method.
Sends a test signal to the Vinli Platform to trigger the EmergencyContact. The phone number for the contact will receive either a SMS or Voice Call as configured with the addition of "This is a test..." caveats.
Retrieves a part of the stream of messages transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent messages.
#### `delete()`
#### `locations([fields, options])`
Deletes this EmergencyContact.
Note: In order to retrieve the locations for a given Trip, the Trip object must have been created by the `fetch` method.
Retrieves a part of the stream of locations transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent locations.
#### `snapshots(fields, [options])`
Note: In order to retrieve the snapshot for a given Trip, the Trip object must have been created by the `fetch` method.
Retrieves a part of the stream of snapshots transmitted by this Device. Accepts `limit`, `since`, and `until` stream pagination options. Without any options, this method will return the most recent snapshots.

@@ -12,3 +12,3 @@ var nock = require('nock');

before(function() {
Vinli = require('..')({ appId: 'foo', secretKey: 'bar' });
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});

@@ -70,3 +70,3 @@

return Vinli.App.devices({limit: 2}).then(function(devices) {
return Vinli.App.devices({ limit: 2 }).then(function(devices) {
expect(devices).to.have.property('list');

@@ -79,3 +79,3 @@ expect(devices).to.have.property('total', 3);

return devices.next();
}).then(function(devices){
}).then(function(devices) {
expect(devices).to.have.property('list');

@@ -125,3 +125,3 @@ expect(devices).to.have.property('total', 3);

});
return Vinli.App.addDevice({caseId: 'VNL999'}).then(function(device) {
return Vinli.App.addDevice({ caseId: 'VNL999' }).then(function(device) {
expect(device).to.be.an.instanceOf(Vinli.Device);

@@ -128,0 +128,0 @@ expect(device).to.have.property('id', 'foo');

@@ -12,3 +12,3 @@ var nock = require('nock');

before(function() {
Vinli = require('..')({ appId: 'foo', secretKey: 'bar' });
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});

@@ -15,0 +15,0 @@

@@ -5,3 +5,3 @@ var nock = require('nock');

var client = require('..');
var Client = require('..');
var emptyMeta = {

@@ -18,3 +18,2 @@ pagination: {

describe('Client', function() {
describe('setup', function() {

@@ -31,4 +30,4 @@ beforeEach(function() {

expect(function() {
client({ secretKey: 'bar' });
}).to.throw(/"appId" is required/);
return new Client({ secretKey: 'bar' });
}).to.throw(/\[appId\]/);
});

@@ -38,12 +37,12 @@

expect(function() {
client({ appId: 'foo' });
}).to.throw(/"secretKey" is required/);
return new Client({ appId: 'foo' });
}).to.throw(/\[secretKey\]/);
});
it('should let you set the hostBase', function() {
var devices = nock('https://platform.mycompany.com').get('/api/v1/devices')
var devices = nock('https://platform.mycompany.com').get('/api/v1/devices/03afc858-23ff-4738-8eb2-4dec0e364205')
.reply(200, { devices: [], meta: emptyMeta });
return client({ appId: 'foo', secretKey: 'bar', hostBase: '.mycompany.com' })
.App.devices().then(function() {
return new Client({ appId: 'foo', secretKey: 'bar', hostBase: '.mycompany.com' })
.Device.fetch('03afc858-23ff-4738-8eb2-4dec0e364205').then(function() {
devices.done();

@@ -54,7 +53,7 @@ });

it('should let you set the protocol', function() {
var devices = nock('http://platform.vin.li:443').get('/api/v1/devices')
var devices = nock('http://platform.vin.li:443').get('/api/v1/devices/03afc858-23ff-4738-8eb2-4dec0e364205')
.reply(200, { devices: [], meta: emptyMeta });
return client({ appId: 'foo', secretKey: 'bar', protocol: 'http' })
.App.devices().then(function() {
return new Client({ appId: 'foo', secretKey: 'bar', protocol: 'http' })
.Device.fetch('03afc858-23ff-4738-8eb2-4dec0e364205').then(function() {
devices.done();

@@ -65,7 +64,7 @@ });

it('should let you set the port', function() {
var devices = nock('https://platform.vin.li:1234').get('/api/v1/devices')
var devices = nock('https://platform.vin.li:1234').get('/api/v1/devices/03afc858-23ff-4738-8eb2-4dec0e364205')
.reply(200, { devices: [], meta: emptyMeta });
return client({ appId: 'foo', secretKey: 'bar', port: 1234 })
.App.devices().then(function() {
return new Client({ appId: 'foo', secretKey: 'bar', port: 1234 })
.Device.fetch('03afc858-23ff-4738-8eb2-4dec0e364205').then(function() {
devices.done();

@@ -76,10 +75,31 @@ });

it('should let you set the apiVersion', function() {
var devices = nock('https://platform.vin.li').get('/api/v3/devices')
var devices = nock('https://platform.vin.li').get('/api/v3/devices/03afc858-23ff-4738-8eb2-4dec0e364205')
.reply(200, { devices: [], meta: emptyMeta });
return client({ appId: 'foo', secretKey: 'bar', apiVersion: 'v3' })
.App.devices().then(function() {
return new Client({ appId: 'foo', secretKey: 'bar', apiVersion: 'v3' })
.Device.fetch('03afc858-23ff-4738-8eb2-4dec0e364205').then(function() {
devices.done();
});
});
it('should let you set the serviceOrigins', function() {
var device = nock('http://foo.vin.li').get('/api/v1/devices/03afc858-23ff-4738-8eb2-4dec0e364205')
.reply(200, { device: { id: '03afc858-23ff-4738-8eb2-4dec0e364205' } });
return new Client({
appId: 'foo',
secretKey: 'bar',
serviceOrigins: {
platform: 'http://foo.vin.li',
auth: 'http://foo.vin.li',
telemetry: 'http://foo.vin.li',
event: 'http://foo.vin.li',
rule: 'http://foo.vin.li',
trip: 'http://foo.vin.li',
safety: 'http://foo.vin.li'
}
}).Device.fetch('03afc858-23ff-4738-8eb2-4dec0e364205').then(function() {
device.done();
});
});
});

@@ -89,13 +109,15 @@

it('should expose all of the resources', function() {
var Vinli = client({ appId: 'foo', secretKey: 'bar' });
var vinli = new Client({ appId: 'foo', secretKey: 'bar' });
expect(Vinli).to.have.property('App');
expect(Vinli).to.have.property('Auth');
expect(Vinli).to.have.property('Device');
expect(Vinli).to.have.property('Vehicle');
expect(Vinli).to.have.property('Trip');
expect(Vinli).to.have.property('Rule');
expect(Vinli).to.have.property('EmergencyContact');
expect(vinli).to.have.property('App');
expect(vinli).to.have.property('Auth');
expect(vinli).to.have.property('User');
expect(vinli).to.have.property('Device');
expect(vinli).to.have.property('Vehicle');
expect(vinli).to.have.property('Trip');
expect(vinli).to.have.property('Rule');
expect(vinli).to.have.property('Event');
expect(vinli).to.have.property('Subscription');
});
});
});
var nock = require('nock');
var expect = require('./helpers/test_helper');
var Vinli = require('..')({appId: 'foo', secretKey: 'bar' });
var Vinli;
describe('Device', function() {
before(function() {
Vinli = require('..')({appId: 'foo', secretKey: 'bar' });
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});

@@ -98,3 +98,3 @@

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').vehicles({limit: 3}).then(function(vehicles){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').vehicles({ limit: 3 }).then(function(vehicles) {
expect(vehicles).to.have.property('list').that.is.an('array');

@@ -120,11 +120,11 @@ expect(vehicles.list).to.have.lengthOf(3);

.reply(200, {
'vehicle': {
'id': 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
'vin': '4T1BK46K57U123456',
'make': 'Toyota',
'model': 'Camry',
'year': '2007',
'trim': 'SE 4dr Sedan (3.5L 6cyl 6A)',
'links': {
'self': '/api/v1/vehicles/fc8bdd0c-5be3-46d5-8582-b5b54052eca2'
vehicle: {
id: 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
vin: '4T1BK46K57U123456',
make: 'Toyota',
model: 'Camry',
year: '2007',
trim: 'SE 4dr Sedan (3.5L 6cyl 6A)',
links: {
self: '/api/v1/vehicles/fc8bdd0c-5be3-46d5-8582-b5b54052eca2'
}

@@ -134,3 +134,3 @@ }

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').latestVehicle().then(function(vehicle){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').latestVehicle().then(function(vehicle) {
expect(vehicle).to.be.an.instanceOf(Vinli.Vehicle);

@@ -145,5 +145,5 @@ expect(vehicle).to.have.property('vin', '4T1BK46K57U123456');

.get('/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/vehicles/_latest')
.reply(200, {vehicle: null});
.reply(200, { vehicle: null });
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').latestVehicle().then(function(vehicle){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').latestVehicle().then(function(vehicle) {
expect(vehicle).to.equal(null);

@@ -179,8 +179,8 @@ m.done();

.reply(200, {
'messages': [{
'id': '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
'timestamp': 1416841046851,
'location': {
'type': 'point',
'coordinates': [
messages: [{
id: '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
timestamp: 1416841046851,
location: {
type: 'point',
coordinates: [
-96.79064822,

@@ -190,11 +190,11 @@ 32.78053848

},
'calculatedLoadValue': 31.372549019607842,
'vehicleSpeed': 3,
'rpm': 672.5
calculatedLoadValue: 31.372549019607842,
vehicleSpeed: 3,
rpm: 672.5
}, {
'id': '26f7b270-e98d-4c7e-adab-907f4c2ea6e4',
'timestamp': 1416841045851,
'location': {
'type': 'point',
'coordinates': [
id: '26f7b270-e98d-4c7e-adab-907f4c2ea6e4',
timestamp: 1416841045851,
location: {
type: 'point',
coordinates: [
-96.79064822,

@@ -204,11 +204,11 @@ 32.78053848

},
'calculatedLoadValue': 32.15686274509804,
'vehicleSpeed': 3,
'rpm': 767.75
calculatedLoadValue: 32.15686274509804,
vehicleSpeed: 3,
rpm: 767.75
}, {
'id': '2d729a46-5830-481a-b600-f7c99e1861ae',
'timestamp': 1416841044852,
'location': {
'type': 'point',
'coordinates': [
id: '2d729a46-5830-481a-b600-f7c99e1861ae',
timestamp: 1416841044852,
location: {
type: 'point',
coordinates: [
-96.79065166,

@@ -218,14 +218,14 @@ 32.78053986

},
'calculatedLoadValue': 36.07843137254902,
'vehicleSpeed': 4,
'rpm': 763.25
calculatedLoadValue: 36.07843137254902,
vehicleSpeed: 4,
rpm: 763.25
}
],
'meta': {
'pagination': {
'remaining': 9715,
'limit': 3,
'until': 1419725719165,
'links': {
'prior': 'https://telemetry-test.vin.li/api/v1/devices/fe4bbc20-cc90-11e3-8e05-f3abac5b6410/messages?limit=3&until=1416841027851'
meta: {
pagination: {
remaining: 9715,
limit: 3,
until: 1419725719165,
links: {
prior: 'https://telemetry-test.vin.li/api/v1/devices/fe4bbc20-cc90-11e3-8e05-f3abac5b6410/messages?limit=3&until=1416841027851'
}

@@ -236,3 +236,3 @@ }

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').messages({limit: 3}).then(function(messages){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').messages({ limit: 3 }).then(function(messages) {
expect(messages).to.have.property('list').that.is.a('array').and.has.lengthOf(3);

@@ -249,29 +249,29 @@ expect(messages).to.have.property('remaining', 9715);

.reply(200, {
'messages': [{
'id': '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
'timestamp': 1416841046851,
'calculatedLoadValue': 31.372549019607842,
'vehicleSpeed': 3,
'rpm': 672.5
messages: [{
id: '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
timestamp: 1416841046851,
calculatedLoadValue: 31.372549019607842,
vehicleSpeed: 3,
rpm: 672.5
}, {
'id': '26f7b270-e98d-4c7e-adab-907f4c2ea6e4',
'timestamp': 1416841045851,
'calculatedLoadValue': 32.15686274509804,
'vehicleSpeed': 3,
'rpm': 767.75
id: '26f7b270-e98d-4c7e-adab-907f4c2ea6e4',
timestamp: 1416841045851,
calculatedLoadValue: 32.15686274509804,
vehicleSpeed: 3,
rpm: 767.75
}, {
'id': '2d729a46-5830-481a-b600-f7c99e1861ae',
'timestamp': 1416841044852,
'calculatedLoadValue': 36.07843137254902,
'vehicleSpeed': 4,
'rpm': 763.25
id: '2d729a46-5830-481a-b600-f7c99e1861ae',
timestamp: 1416841044852,
calculatedLoadValue: 36.07843137254902,
vehicleSpeed: 4,
rpm: 763.25
}],
'meta': {
'pagination': {
'remaining': 1,
'limit': 3,
'until': 1419731564093,
'since': 1416841043850,
'links': {
'prior': 'https://telemetry-test.vin.li/api/v1/devices/fe4bbc20-cc90-11e3-8e05-f3abac5b6410/messages?limit=3&since=1416841043850&until=1416841044851'
meta: {
pagination: {
remaining: 1,
limit: 3,
until: 1419731564093,
since: 1416841043850,
links: {
prior: 'https://telemetry-test.vin.li/api/v1/devices/fe4bbc20-cc90-11e3-8e05-f3abac5b6410/messages?limit=3&since=1416841043850&until=1416841044851'
}

@@ -285,16 +285,16 @@ }

.reply(200, {
'messages': [{
'id': 'ef32a83b-bf46-4266-a98d-a4736b83425e',
'timestamp': 1416841043852,
'calculatedLoadValue': 30.980392156862745,
'vehicleSpeed': 8,
'rpm': 698.25
messages: [{
id: 'ef32a83b-bf46-4266-a98d-a4736b83425e',
timestamp: 1416841043852,
calculatedLoadValue: 30.980392156862745,
vehicleSpeed: 8,
rpm: 698.25
}],
'meta': {
'pagination': {
'remaining': 0,
'limit': 3,
'until': 1416841044851,
'since': 1416841043850,
'links': { }
meta: {
pagination: {
remaining: 0,
limit: 3,
until: 1416841044851,
since: 1416841043850,
links: { }
}

@@ -304,4 +304,4 @@ }

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').messages({limit: 3, since: 1416841043850})
.then(function(messages){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').messages({ limit: 3, since: 1416841043850 })
.then(function(messages) {
expect(messages).to.have.property('list').that.is.a('array').and.has.lengthOf(3);

@@ -313,3 +313,3 @@ expect(messages).to.have.property('remaining', 1);

return messages.prior();
}).then(function(messages){
}).then(function(messages) {
expect(messages).to.have.property('list').that.is.a('array').and.has.lengthOf(1);

@@ -334,8 +334,8 @@ expect(messages).to.have.property('remaining', 0);

.reply(200, {
'message': {
'id': '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
'timestamp': 1416841046851,
'calculatedLoadValue': 31.372549019607842,
'vehicleSpeed': 3,
'rpm': 672.5
message: {
id: '4993fac7-7e0b-4d90-9e57-af8eb1d27170',
timestamp: 1416841046851,
calculatedLoadValue: 31.372549019607842,
vehicleSpeed: 3,
rpm: 672.5
}

@@ -345,3 +345,3 @@ });

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').message('4993fac7-7e0b-4d90-9e57-af8eb1d27170')
.then(function(message){
.then(function(message) {
expect(message).to.have.property('id', '4993fac7-7e0b-4d90-9e57-af8eb1d27170');

@@ -377,26 +377,26 @@ m.done();

.reply(200, {
'trips': [{
'id': 'cf9173fa-bbca-49bb-8297-a1a18586a8e7',
'start': '2014-12-30T08:50:48.669Z',
'stop': '2014-12-30T14:57:46.225Z',
'status': 'complete',
'vehicleId': '530f2690-63c0-11e4-86d8-7f2f26e5461e',
'deviceId': 'c4627b29-14bd-49c3-8e6a-1f857143039f'
},{
'id': '4cb2a8ea-64a5-49b9-bdb2-e60106f61f84',
'start': '2014-12-29T13:35:52.184Z',
'stop': '2014-12-29T13:58:32.270Z',
'status': 'complete',
'vehicleId': '530f2690-63c0-11e4-86d8-7f2f26e5461e',
'deviceId': 'c4627b29-14bd-49c3-8e6a-1f857143039f'
trips: [{
id: 'cf9173fa-bbca-49bb-8297-a1a18586a8e7',
start: '2014-12-30T08:50:48.669Z',
stop: '2014-12-30T14:57:46.225Z',
status: 'complete',
vehicleId: '530f2690-63c0-11e4-86d8-7f2f26e5461e',
deviceId: 'c4627b29-14bd-49c3-8e6a-1f857143039f'
}, {
id: '4cb2a8ea-64a5-49b9-bdb2-e60106f61f84',
start: '2014-12-29T13:35:52.184Z',
stop: '2014-12-29T13:58:32.270Z',
status: 'complete',
vehicleId: '530f2690-63c0-11e4-86d8-7f2f26e5461e',
deviceId: 'c4627b29-14bd-49c3-8e6a-1f857143039f'
}],
'meta': {
'pagination': {
'total': 748,
'limit': 2,
'offset': 0,
'links': {
'first': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=0&limit=2',
'last': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=746&limit=2',
'next': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=2&limit=2'
meta: {
pagination: {
total: 748,
limit: 2,
offset: 0,
links: {
first: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=0&limit=2',
last: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=746&limit=2',
next: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=2&limit=2'
}

@@ -407,3 +407,3 @@ }

return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').trips({limit: 2}).then(function(trips){
return Vinli.Device.forge('c4627b29-14bd-49c3-8e6a-1f857143039f').trips({ limit: 2 }).then(function(trips) {
expect(trips).to.have.property('list').that.is.an('array');

@@ -440,16 +440,2 @@ expect(trips.list).to.have.lengthOf(2);

});
describe('#emergencyContacts()', function() {
it('should exist', function() {
var device = Vinli.Device.forge('asfdafdasfdsdf');
expect(device).to.have.property('emergencyContacts').that.is.a('function');
});
});
describe('#createEmergencyContact()', function() {
it('should exist', function() {
var device = Vinli.Device.forge('asfdafdasfdsdf');
expect(device).to.have.property('createEmergencyContact').that.is.a('function');
});
});
});
var nock = require('nock');
var expect = require('./helpers/test_helper');
var Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
var Vinli = require('..')({ appId: 'foo', secretKey: 'bar' });
describe('Rule', function(){
before(function(){
Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
describe('Rule', function() {
before(function() {
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});
beforeEach(function(){
beforeEach(function() {
nock.disableNetConnect();
});
afterEach(function(){
afterEach(function() {
nock.cleanAll();
});
describe('.forge()', function(){
it('should exist', function(){
describe('.forge()', function() {
it('should exist', function() {
expect(Vinli.Rule).to.have.property('fetch').that.is.a('function');
});
it('should return a rule with the given id', function(){
it('should return a rule with the given id', function() {
var rule = Vinli.Rule.forge('c4627b29-14bd-49c3-8e6a-1f857143039f');

@@ -30,30 +30,31 @@ expect(rule).to.have.property('id', 'c4627b29-14bd-49c3-8e6a-1f857143039f');

describe('.fetch()', function(){
it('should exist', function(){
describe('.fetch()', function() {
it('should exist', function() {
expect(Vinli.Rule).to.have.property('forge').that.is.a('function');
});
it('should fetch a rule with the given id from the platform', function(){
var ruleMock = nock('https://events.vin.li')
it('should fetch a rule with the given id from the platform', function() {
var ruleMock = nock('https://rules.vin.li')
.get('/api/v1/rules/fc8bdd0c-5be3-46d5-8582-b5b54052eca2')
.reply(200, {
'rule' : {
'id' : 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
'name' : 'Speed over 35mph near Superdome',
'boundaries' : [
rule: {
id: 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
deviceId: '1a2cb688-de46-47f0-a8a6-a8569b085fb3',
name: 'Speed over 35mph near Superdome',
boundaries: [
{
'type' : 'parametric',
'parameter' : 'vehicleSpeed',
'min' : 35
type: 'parametric',
parameter: 'vehicleSpeed',
min: 35
},
{
'type' : 'radius',
'lon' : -90.0811,
'lat' : 29.9508,
'radius' : 500
type: 'radius',
lon: -90.0811,
lat: 29.9508,
radius: 500
}
],
'links' : {
'self' : 'https://events.vin.li/api/v1/rules/68d489c0-d7a2-11e3-9c1a-0800200c9a66',
'events' : 'https://events.vin.li/api/v1/rules/68d489c0-d7a2-11e3-9c1a-0800200c9a66/events'
links: {
self: 'https://events.vin.li/api/v1/rules/68d489c0-d7a2-11e3-9c1a-0800200c9a66',
events: 'https://events.vin.li/api/v1/rules/68d489c0-d7a2-11e3-9c1a-0800200c9a66/events'
}

@@ -63,3 +64,3 @@ }

return Vinli.Rule.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(rule){
return Vinli.Rule.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(rule) {
expect(rule).to.be.an.instanceOf(Vinli.Rule);

@@ -72,6 +73,6 @@ expect(rule).to.have.property('id', 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2');

it('should reject a request for an unknown Rule', function(){
nock('https://events.vin.li')
it('should reject a request for an unknown Rule', function() {
nock('https://rules.vin.li')
.get('/api/v1/rules/c4627b29-14bd-49c3-8e6a-1f857143039f')
.reply(404, {message: 'Not found'});
.reply(404, { message: 'Not found' });

@@ -82,4 +83,4 @@ expect(Vinli.Rule.fetch('c4627b29-14bd-49c3-8e6a-1f857143039f')).to.be.rejectedWith(/Not found/);

xdescribe('#events()', function(){
it('should exist', function(){
xdescribe('#events()', function() {
it('should exist', function() {
var rule = Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2');

@@ -90,4 +91,4 @@ expect(rule).to.have.property('events').that.is.a('function');

describe('#delete()', function(){
it('should exist', function(){
describe('#delete()', function() {
it('should exist', function() {
var rule = Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2');

@@ -97,8 +98,8 @@ expect(rule).to.have.property('delete').that.is.a('function');

it('should delete the rule', function(){
var m = nock('https://events.vin.li')
it('should delete the rule', function() {
var m = nock('https://rules.vin.li')
.delete('/api/v1/rules/fc8bdd0c-5be3-46d5-8582-b5b54052eca2')
.reply(204);
return Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').delete().then(function(){
return Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').delete().then(function() {
m.done();

@@ -108,37 +109,2 @@ });

});
describe('#currentState()', function(){
it('should exist', function(){
var rule = Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2');
expect(rule).to.have.property('currentState').that.is.a('function');
});
it('should require a device if the Rule has not been fetched', function(){
var rule = Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2');
expect(rule.currentState()).to.be.rejectedWith();
});
it('should fetch the rule state from the platform', function(){
var m = nock('https://events.vin.li')
.get('/api/v1/devices/270795d3-1945-4728-ad7c-47247487dcda/rules/fc8bdd0c-5be3-46d5-8582-b5b54052eca2/state')
.reply(200, {
'state': {
'rule': 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
'device': '270795d3-1945-4728-ad7c-47247487dcda',
'evaluated': true,
'covered': false
}
});
return Vinli.Rule.forge('fc8bdd0c-5be3-46d5-8582-b5b54052eca2')
.currentState(Vinli.Device.forge('270795d3-1945-4728-ad7c-47247487dcda'))
.then(function(state){
expect(state).to.be.an('object');
expect(state).to.have.property('evaluated', true);
expect(state).to.have.property('covered', false);
m.done();
});
});
});
});
var nock = require('nock');
var expect = require('./helpers/test_helper');
var Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
var Vinli;
describe('Trip', function(){
before(function(){
Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
describe('Trip', function() {
before(function() {
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});
beforeEach(function(){
beforeEach(function() {
nock.disableNetConnect();
});
afterEach(function(){
afterEach(function() {
nock.cleanAll();
});
describe('.forge()', function(){
it('should exist', function(){
describe('.forge()', function() {
it('should exist', function() {
expect(Vinli.Trip).to.have.property('fetch').that.is.a('function');
});
it('should return a trip with the given id', function(){
it('should return a trip with the given id', function() {
var trip = Vinli.Trip.forge('c4627b29-14bd-49c3-8e6a-1f857143039f');

@@ -30,8 +30,8 @@ expect(trip).to.have.property('id', 'c4627b29-14bd-49c3-8e6a-1f857143039f');

describe('.fetch()', function(){
it('should exist', function(){
describe('.fetch()', function() {
it('should exist', function() {
expect(Vinli.Trip).to.have.property('forge').that.is.a('function');
});
it('should fetch an trip with the given id from the platform', function(){
it('should fetch an trip with the given id from the platform', function() {
var m = nock('https://trips.vin.li')

@@ -46,7 +46,7 @@ .get('/api/v1/trips/cf9173fa-bbca-49bb-8297-a1a18586a8e7')

vehicleId: '530f2690-63c0-11e4-86d8-7f2f26e5461e',
deviceId: 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
deviceId: 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2'
}
});
return Vinli.Trip.fetch('cf9173fa-bbca-49bb-8297-a1a18586a8e7').then(function(trip){
return Vinli.Trip.fetch('cf9173fa-bbca-49bb-8297-a1a18586a8e7').then(function(trip) {
expect(trip).to.be.an.instanceOf(Vinli.Trip);

@@ -58,6 +58,6 @@ expect(trip).to.have.property('id', 'cf9173fa-bbca-49bb-8297-a1a18586a8e7');

it('should reject a request for an unknown trip', function(){
it('should reject a request for an unknown trip', function() {
nock('https://trips.vin.li')
.get('/api/v1/trips/c4627b29-14bd-49c3-8e6a-1f857143039f')
.reply(404, {message: 'Not found'});
.reply(404, { message: 'Not found' });

@@ -68,4 +68,4 @@ expect(Vinli.Trip.fetch('c4627b29-14bd-49c3-8e6a-1f857143039f')).to.be.rejectedWith(/Not found/);

xdescribe('#messages()', function(){
it('should exist', function(){
xdescribe('#messages()', function() {
it('should exist', function() {
var trip = Vinli.Trip.forge('asfdafdasfdsdf');

@@ -76,4 +76,4 @@ expect(trip).to.have.property('messages').that.is.a('function');

describe('#locations()', function(){
it('should exist', function(){
describe('#locations()', function() {
it('should exist', function() {
var trip = Vinli.Trip.forge('asfdafdasfdsdf');

@@ -84,4 +84,4 @@ expect(trip).to.have.property('locations').that.is.a('function');

xdescribe('#snapshots()', function(){
it('should exist', function(){
xdescribe('#snapshots()', function() {
it('should exist', function() {
var trip = Vinli.Trip.forge('asfdafdasfdsdf');

@@ -88,0 +88,0 @@ expect(trip).to.have.property('snapshots').that.is.a('function');

@@ -10,21 +10,21 @@ var nock = require('nock');

describe('User', function(){
before(function(){
Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
describe('User', function() {
before(function() {
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});
beforeEach(function(){
beforeEach(function() {
nock.disableNetConnect();
});
afterEach(function(){
afterEach(function() {
nock.cleanAll();
});
describe('.forge()', function(){
it('should exist', function(){
describe('.forge()', function() {
it('should exist', function() {
expect(Vinli.User).to.have.property('fetch').that.is.a('function');
});
it('should return a user with the given id', function(){
it('should return a user with the given id', function() {
var user = Vinli.User.forge('c4627b29-14bd-49c3-8e6a-1f857143039f');

@@ -35,8 +35,8 @@ expect(user).to.have.property('accessToken', 'c4627b29-14bd-49c3-8e6a-1f857143039f');

describe('.fetch()', function(){
it('should exist', function(){
describe('.fetch()', function() {
it('should exist', function() {
expect(Vinli.User).to.have.property('forge').that.is.a('function');
});
it('should fetch an user with the given token from the platform', function(){
it('should fetch an user with the given token from the platform', function() {
var m = nock('https://auth.vin.li')

@@ -46,9 +46,9 @@ .get('/user?access_token=fc8bdd0c-5be3-46d5-8582-b5b54052eca2')

user: {
'firstName': 'John',
'lastName': 'Sample',
'email': 'john@vin.li'
firstName: 'John',
lastName: 'Sample',
email: 'john@vin.li'
}
});
return Vinli.User.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(user){
return Vinli.User.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(user) {
expect(user).to.be.an.instanceOf(Vinli.User);

@@ -61,6 +61,6 @@ expect(user).to.have.property('accessToken', 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2');

it('should reject a request for an unknown emergency contact', function(){
it('should reject a request for an unknown emergency contact', function() {
nock('https://platform.vin.li')
.get('/api/v1/vehicles/c4627b29-14bd-49c3-8e6a-1f857143039f')
.reply(404, {message: 'Not found'});
.reply(404, { message: 'Not found' });

@@ -77,3 +77,3 @@ expect(Vinli.Vehicle.fetch('c4627b29-14bd-49c3-8e6a-1f857143039f')).to.be.rejectedWith(/Not found/);

it('should fetch an user with the given token from the platform', function(){
it('should fetch an user with the given token from the platform', function() {
var m = nock('https://auth.vin.li')

@@ -98,6 +98,5 @@ .get('/user?access_token=fc8bdd0c-5be3-46d5-8582-b5b54052eca2')

return Vinli.User.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(user){
return Vinli.User.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(user) {
return user.devices();
}).then(function(devices) {
console.log()
expect(devices).to.have.property('list').that.is.an('array');

@@ -104,0 +103,0 @@ expect(devices.list).to.have.lengthOf(1);

var nock = require('nock');
var expect = require('./helpers/test_helper');
var Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
var Vinli;
describe('Vehicle', function(){
before(function(){
Vinli = require('..')({appId: 'foo', secretKey: 'bar'});
describe('Vehicle', function() {
before(function() {
Vinli = new (require('..'))({ appId: 'foo', secretKey: 'bar' });
});
beforeEach(function(){
beforeEach(function() {
nock.disableNetConnect();
});
afterEach(function(){
afterEach(function() {
nock.cleanAll();
});
describe('.forge()', function(){
it('should exist', function(){
describe('.forge()', function() {
it('should exist', function() {
expect(Vinli.Vehicle).to.have.property('fetch').that.is.a('function');
});
it('should return a vehicle with the given id', function(){
it('should return a vehicle with the given id', function() {
var vehicle = Vinli.Vehicle.forge('c4627b29-14bd-49c3-8e6a-1f857143039f');

@@ -30,8 +30,8 @@ expect(vehicle).to.have.property('id', 'c4627b29-14bd-49c3-8e6a-1f857143039f');

describe('.fetch()', function(){
it('should exist', function(){
describe('.fetch()', function() {
it('should exist', function() {
expect(Vinli.Vehicle).to.have.property('forge').that.is.a('function');
});
it('should fetch an Vehicle with the given id from the platform', function(){
it('should fetch an Vehicle with the given id from the platform', function() {
var vehicleMock = nock('https://platform.vin.li')

@@ -41,10 +41,10 @@ .get('/api/v1/vehicles/fc8bdd0c-5be3-46d5-8582-b5b54052eca2')

vehicle: {
'id': 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
'vin': '4T1BK46K57U123456',
'make': 'Toyota',
'model': 'Camry',
'year': '2007',
'trim': 'SE 4dr Sedan (3.5L 6cyl 6A)',
'links': {
'self': '/api/v1/vehicles/fc8bdd0c-5be3-46d5-8582-b5b54052eca2'
id: 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2',
vin: '4T1BK46K57U123456',
make: 'Toyota',
model: 'Camry',
year: '2007',
trim: 'SE 4dr Sedan (3.5L 6cyl 6A)',
links: {
self: '/api/v1/vehicles/fc8bdd0c-5be3-46d5-8582-b5b54052eca2'
}

@@ -54,3 +54,3 @@ }

return Vinli.Vehicle.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(vehicle){
return Vinli.Vehicle.fetch('fc8bdd0c-5be3-46d5-8582-b5b54052eca2').then(function(vehicle) {
expect(vehicle).to.be.an.instanceOf(Vinli.Vehicle);

@@ -63,6 +63,6 @@ expect(vehicle).to.have.property('id', 'fc8bdd0c-5be3-46d5-8582-b5b54052eca2');

it('should reject a request for an unknown emergency contact', function(){
it('should reject a request for an unknown emergency contact', function() {
nock('https://platform.vin.li')
.get('/api/v1/vehicles/c4627b29-14bd-49c3-8e6a-1f857143039f')
.reply(404, {message: 'Not found'});
.reply(404, { message: 'Not found' });

@@ -73,4 +73,4 @@ expect(Vinli.Vehicle.fetch('c4627b29-14bd-49c3-8e6a-1f857143039f')).to.be.rejectedWith(/Not found/);

describe('#trips()', function(){
it('should exist', function(){
describe('#trips()', function() {
it('should exist', function() {
var device = Vinli.Device.forge('asfdafdasfdsdf');

@@ -80,30 +80,30 @@ expect(device).to.have.property('trips').that.is.a('function');

it('should return a list of trips for the device', function(){
it('should return a list of trips for the device', function() {
var m = nock('https://trips.vin.li/')
.get('/api/v1/vehicles/530f2690-63c0-11e4-86d8-7f2f26e5461e/trips?offset=0&limit=2')
.reply(200, {
'trips': [{
'id': 'cf9173fa-bbca-49bb-8297-a1a18586a8e7',
'start': '2014-12-30T08:50:48.669Z',
'stop': '2014-12-30T14:57:46.225Z',
'status': 'complete',
'vehicleId': '530f2690-63c0-11e4-86d8-7f2f26e5461e',
'deviceId': 'c4627b29-14bd-49c3-8e6a-1f857143039f'
},{
'id': '4cb2a8ea-64a5-49b9-bdb2-e60106f61f84',
'start': '2014-12-29T13:35:52.184Z',
'stop': '2014-12-29T13:58:32.270Z',
'status': 'complete',
'vehicleId': '530f2690-63c0-11e4-86d8-7f2f26e5461e',
'deviceId': 'c4627b29-14bd-49c3-8e6a-1f857143039f'
trips: [{
id: 'cf9173fa-bbca-49bb-8297-a1a18586a8e7',
start: '2014-12-30T08:50:48.669Z',
stop: '2014-12-30T14:57:46.225Z',
status: 'complete',
vehicleId: '530f2690-63c0-11e4-86d8-7f2f26e5461e',
deviceId: 'c4627b29-14bd-49c3-8e6a-1f857143039f'
}, {
id: '4cb2a8ea-64a5-49b9-bdb2-e60106f61f84',
start: '2014-12-29T13:35:52.184Z',
stop: '2014-12-29T13:58:32.270Z',
status: 'complete',
vehicleId: '530f2690-63c0-11e4-86d8-7f2f26e5461e',
deviceId: 'c4627b29-14bd-49c3-8e6a-1f857143039f'
}],
'meta': {
'pagination': {
'total': 748,
'limit': 2,
'offset': 0,
'links': {
'first': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=0&limit=2',
'last': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=746&limit=2',
'next': 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=2&limit=2'
meta: {
pagination: {
total: 748,
limit: 2,
offset: 0,
links: {
first: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=0&limit=2',
last: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=746&limit=2',
next: 'http://trips-test.vin.li/api/v1/devices/c4627b29-14bd-49c3-8e6a-1f857143039f/trips?offset=2&limit=2'
}

@@ -114,3 +114,3 @@ }

return Vinli.Vehicle.forge('530f2690-63c0-11e4-86d8-7f2f26e5461e').trips({limit: 2}).then(function(trips){
return Vinli.Vehicle.forge('530f2690-63c0-11e4-86d8-7f2f26e5461e').trips({ limit: 2 }).then(function(trips) {
expect(trips).to.have.property('list').that.is.an('array');

@@ -127,4 +127,4 @@ expect(trips.list).to.have.lengthOf(2);

xdescribe('#collisions()', function(){
it('should exist', function(){
xdescribe('#collisions()', function() {
it('should exist', function() {
var device = Vinli.Vehicle.forge('asfdafdasfdsdf');

@@ -131,0 +131,0 @@ expect(device).to.have.property('collisions').that.is.a('function');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc