Skip to content

Commit

Permalink
adding function to get recording link
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhollan committed Dec 21, 2017
1 parent 7419af2 commit e416746
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
23 changes: 5 additions & 18 deletions CheckRings/index.js
@@ -1,22 +1,17 @@
const RingAPI = require('doorbot');
const https = require('https');
const url = require('url');
const eventGridUrl = url.parse(process.env['eventgrid_endpoint']);
const utils = require('../function-utils');
const parse = require('url').parse;
const eventGridUrl = parse(process.env['eventgrid_endpoint']);

const ring = RingAPI({
email: process.env['ring_email'],
password: GetSecrets().ring_password,
retries: 10, //authentication retries, optional, defaults to 0
});
const utils = require('../function-utils');
const ring = require('../ring-api').ring_client;

const options = {
protocol: 'https:',
hostname: eventGridUrl.hostname,
path: eventGridUrl.path,
headers: {
'content-type': 'application/json',
'aeg-sas-key': GetSecrets().eventgrid_key,
'aeg-sas-key': utils.getSecrets().eventgrid_key,
Accept: 'application/json'
},
method: 'POST'
Expand Down Expand Up @@ -65,12 +60,4 @@ function EmitEvent(ringEvent, context, callback) {
});
req.write(JSON.stringify(eventGridPayload));
req.end();
}

// TODO: Change to call keyvault to grab secrets
function GetSecrets() {
return {
eventgrid_key: process.env['eventgrid_key'],
ring_password: process.env['ring_password']
}
}
16 changes: 16 additions & 0 deletions GetRecording/function.json
@@ -0,0 +1,16 @@
{
"disabled": false,
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
21 changes: 21 additions & 0 deletions GetRecording/index.js
@@ -0,0 +1,21 @@
const ring = require('../ring-api').ring_client;

module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
ring.recording(req.body[0]['data']['id_str'], (e, recording) => {
context.log(`got recording link: ${recording}`);
if(recording) {
context.res = {
status: 200,
body: recording
}
} else {
context.res = {
status: 404,
body: null
}
}
context.done();
})

};
10 changes: 9 additions & 1 deletion function-utils.js
Expand Up @@ -6,4 +6,12 @@ module.exports.generateUUID = function() {
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
};
};

// TODO: Change to call keyvault to grab secrets
module.exports.getSecrets = function () {
return {
eventgrid_key: process.env['eventgrid_key'],
ring_password: process.env['ring_password']
}
}
9 changes: 9 additions & 0 deletions ring-api.js
@@ -0,0 +1,9 @@
const secrets = require('./function-utils').getSecrets();
const RingAPI = require('doorbot');

module.exports.ring_client = RingAPI({
email: process.env['ring_email'],
password: secrets.ring_password,
retries: 10, //authentication retries, optional, defaults to 0
});

0 comments on commit e416746

Please sign in to comment.