From 15d2d15b3d34eda93a8058bdcc47a4d73d9eddc0 Mon Sep 17 00:00:00 2001 From: Adriano Godoy Date: Wed, 6 Apr 2016 09:18:27 -0300 Subject: [PATCH 1/2] 0.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2be7f7..8a61035 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hubot-analytics", "description": "A hubot script to get google analytics reports", - "version": "0.1.0", + "version": "0.1.1", "author": "Plan B Comunicação ", "license": "MIT", "keywords": "hubot, hubot-scripts, google analytics, ga", From 47aaf591eabcfec260eb512a32d3078c5d2d15c2 Mon Sep 17 00:00:00 2001 From: Adriano Godoy Date: Wed, 6 Apr 2016 13:15:56 -0300 Subject: [PATCH 2/2] Show errors when environment is not configured --- src/analytics.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/analytics.js b/src/analytics.js index ddd484c..b68e125 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -16,20 +16,25 @@ var google = require("googleapis"); var analytics = google.analytics("v3"); +var global_error; -var GOOGLE_API_CLIENT_EMAIL = process.env.GOOGLE_API_CLIENT_EMAIL; -var GOOGLE_API_PRIVATE_KEY = process.env.GOOGLE_API_PRIVATE_KEY.replace(/\\n/g, "\n"); +module.exports = function(robot) { -var oauth2Client = new google.auth.JWT(GOOGLE_API_CLIENT_EMAIL, null, GOOGLE_API_PRIVATE_KEY, ["https://www.googleapis.com/auth/analytics.readonly"], null); + try { + var GOOGLE_API_CLIENT_EMAIL = process.env.GOOGLE_API_CLIENT_EMAIL; + var GOOGLE_API_PRIVATE_KEY = process.env.GOOGLE_API_PRIVATE_KEY.replace(/\\n/g, "\n"); -module.exports = function(robot) { + var oauth2Client = new google.auth.JWT(GOOGLE_API_CLIENT_EMAIL, null, GOOGLE_API_PRIVATE_KEY, ["https://www.googleapis.com/auth/analytics.readonly"], null); + } catch(err) { + global_error = "Error on load - check your environments variables GOOGLE_API_CLIENT_EMAIL and GOOGLE_API_PRIVATE_KEY."; + } robot.hear(/analytics profiles/, function(res) { + if(global_error) { + return res.reply(global_error) + } oauth2Client.authorize(function(err) { - if (err) { - return res.reply(err); - } analytics.management.profiles.list( {