From 39b716a069c5e70e0569b1768ecc86a8a8fc18a3 Mon Sep 17 00:00:00 2001 From: Taylor Cox Date: Thu, 22 Mar 2018 10:35:18 -0400 Subject: [PATCH 1/3] Per #2 removing font-awesome --- index.html | 1 - src/components/nytToolbar.vue | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index d77ef02..4a61c7f 100755 --- a/index.html +++ b/index.html @@ -12,7 +12,6 @@ - diff --git a/src/components/nytToolbar.vue b/src/components/nytToolbar.vue index 8d6ee7c..1fddd09 100644 --- a/src/components/nytToolbar.vue +++ b/src/components/nytToolbar.vue @@ -6,7 +6,7 @@ - fa-code + code @@ -15,7 +15,7 @@ - fa-github + code From edb8c85f463bfee09a5ca0c885ad6251aa445b43 Mon Sep 17 00:00:00 2001 From: Taylor Cox Date: Thu, 22 Mar 2018 16:43:59 -0400 Subject: [PATCH 2/3] engine enhancements, dry refactoring (fieldMap) --- engine.html | 211 +++++++++++++++++++++++++--------------------------- 1 file changed, 100 insertions(+), 111 deletions(-) diff --git a/engine.html b/engine.html index 6d5605f..0217463 100644 --- a/engine.html +++ b/engine.html @@ -16,7 +16,24 @@ const globes = { baseUrl: '', apiKey: '', - sections: [] + sections: [], + connected: false, + fieldMap: [ + {name:'api_section',type:'V_WString',size:500}, + {name:'article_section',type:'V_WString',size:500}, + {name:'article_subsection',type:'V_WString',size:1000}, + {name:'title',type:'V_WString',size:1000}, + {name:'abstract',type:'V_WString',size:1000}, + {name:'url',type:'V_WString',size:1000}, + {name:'short_url',type:'V_WString',size:1000}, + {name:'byline',type:'V_WString',size:1000}, + {name:'updated',type:'V_WString',size:1000}, + {name:'created',type:'V_WString',size:1000}, + {name:'published',type:'V_WString',size:1000}, + {name:'image_url',type:'V_WString',size:1000}, + {name:'image_caption',type:'V_WString',size:1000}, + {name:'image_copyright',type:'V_WString',size:1000} + ] } Alteryx.Plugin.DefineConnections = function() @@ -37,8 +54,13 @@ globes.baseUrl = config.Configuration.baseUrl; globes.apiKey = config.Configuration.apiKey; globes.sections = config.Configuration.selections; - } else { + globes.connected = true; + } else if (config.Configuration.connects > 0 ) { Alteryx.Engine.SendMessage.Error('Connection to ' + config.Configuration.baseUrl + ' failed! Please check your API Key..'); + globes.connected = false; + } else { + Alteryx.Engine.SendMessage.Warning('Not connected, don\'t expect any results...'); + globes.connected = false; } }; @@ -58,120 +80,87 @@ Alteryx.Plugin.PI_PushAllRecords = function(recordLimit) { - if(recordLimit.RecordLimit > 0){ - - // go time, make some API calls - - var fieldMap = [ - {name:'api_section',type:'V_WString',size:500}, - {name:'article_section',type:'V_WString',size:500}, - {name:'article_subsection',type:'V_WString',size:1000}, - {name:'title',type:'V_WString',size:1000}, - {name:'abstract',type:'V_WString',size:1000}, - {name:'url',type:'V_WString',size:1000}, - {name:'short_url',type:'V_WString',size:1000}, - {name:'byline',type:'V_WString',size:1000}, - {name:'updated',type:'V_WString',size:1000}, - {name:'created',type:'V_WString',size:1000}, - {name:'published',type:'V_WString',size:1000}, - {name:'image_url',type:'V_WString',size:1000}, - {name:'image_caption',type:'V_WString',size:1000}, - {name:'image_copyright',type:'V_WString',size:1000} - ]; - - Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": fieldMap }); - - var promises = []; - - globes.sections.forEach(function(s){ - getUrl = globes.baseUrl + '/svc/topstories/v2/' + s + '.json?api-key=' + globes.apiKey; - promises.push(axios.get(getUrl)) - }); - - var articles = []; - - axios.all(promises).then(function(results) { - results.forEach(function(response) { - - Alteryx.Engine.SendMessage.Info('Pulled ' + response.data.num_results + ' articles from the "' + response.data.section + '" section.'); - - for (r = 0; r < response.data.results.length; r++) { - if(response.data.results[r].multimedia[0]) { - article = [ - response.data.section, - response.data.results[r].section, - response.data.results[r].subsection, - response.data.results[r].title, - response.data.results[r].abstract, - response.data.results[r].url, - response.data.results[r].short_url, - response.data.results[r].byline, - response.data.results[r].updated_date, - response.data.results[r].created_date, - response.data.results[r].published_date, - response.data.results[r].multimedia[0].url, - response.data.results[r].multimedia[0].caption, - response.data.results[r].multimedia[0].copyright - ]; - }else{ - article = [ - response.data.section, - response.data.results[r].section, - response.data.results[r].subsection, - response.data.results[r].title, - response.data.results[r].abstract, - response.data.results[r].url, - response.data.results[r].short_url, - response.data.results[r].byline, - response.data.results[r].updated_date, - response.data.results[r].created_date, - response.data.results[r].published_date, - '-', - '-', - '-' - ]; + if(recordLimit.RecordLimit > 0){ + + // go time, make some API calls + + Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); + + var promises = []; + + globes.sections.forEach(function(s){ + getUrl = globes.baseUrl + '/svc/topstories/v2/' + s + '.json?api-key=' + globes.apiKey; + promises.push(axios.get(getUrl)) + }); + + var articles = []; + + axios.all(promises).then(function(results) { + results.forEach(function(response) { + + Alteryx.Engine.SendMessage.Info('Pulled ' + response.data.num_results + ' articles from the "' + response.data.section + '" section.'); + + for (r = 0; r < response.data.results.length; r++) { + if(response.data.results[r].multimedia[0]) { + article = [ + response.data.section, + response.data.results[r].section, + response.data.results[r].subsection, + response.data.results[r].title, + response.data.results[r].abstract, + response.data.results[r].url, + response.data.results[r].short_url, + response.data.results[r].byline, + response.data.results[r].updated_date, + response.data.results[r].created_date, + response.data.results[r].published_date, + response.data.results[r].multimedia[0].url, + response.data.results[r].multimedia[0].caption, + response.data.results[r].multimedia[0].copyright + ]; + }else{ + article = [ + response.data.section, + response.data.results[r].section, + response.data.results[r].subsection, + response.data.results[r].title, + response.data.results[r].abstract, + response.data.results[r].url, + response.data.results[r].short_url, + response.data.results[r].byline, + response.data.results[r].updated_date, + response.data.results[r].created_date, + response.data.results[r].published_date, + '-', + '-', + '-' + ]; + } + articles.push(article); } - articles.push(article); - } + }) + + Alteryx.Engine.SendMessage.PushRecords("Articles", articles); + Alteryx.Engine.SendMessage.Complete(); }) - - Alteryx.Engine.SendMessage.PushRecords("Articles", articles); + .catch(function (error) { + Alteryx.Engine.SendMessage.Error('Uh oh! Error in API callback...'); + Alteryx.Engine.SendMessage.Error('This is usually the result of API call limits being exceeded (limits are 5 per second and/or 1000 per day) Try reducing the number of selected sections in the UI.'); + Alteryx.Engine.SendMessage.Error('Error details are below. For other errors, please submit an issue at https://github.com/alteryx-vue/nyt-connector/issues'); + Alteryx.Engine.SendMessage.Error('Error Message: ' + JSON.stringify(error.response.data.message)); + Alteryx.Engine.SendMessage.Error('Response Headers: ' + JSON.stringify(error.response.headers)); + Alteryx.Engine.SendMessage.Complete(); + }); + + } else { + + // just push the field map + Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); Alteryx.Engine.SendMessage.Complete(); - }) - .catch(function (error) { - Alteryx.Engine.SendMessage.Error('Uh oh! Error in API callback...'); - Alteryx.Engine.SendMessage.Error('This is usually the result of API call limits being exceeded (limits are 5 per second and/or 1000 per day) Try reducing the number of selected sections in the UI.'); - Alteryx.Engine.SendMessage.Error('Error details are below. For other errors, please submit an issue at https://github.com/alteryx-vue/nyt-connector/issues'); - Alteryx.Engine.SendMessage.Error('Error Message: ' + JSON.stringify(error.response.data.message)); - Alteryx.Engine.SendMessage.Error('Response Headers: ' + JSON.stringify(error.response.headers)); - Alteryx.Engine.SendMessage.Complete(); - }); - - } else { + + } - // just push the field map - var fieldMap = [ - {name:'api_section',type:'V_WString',size:500}, - {name:'article_section',type:'V_WString',size:500}, - {name:'article_subsection',type:'V_WString',size:1000}, - {name:'title',type:'V_WString',size:1000}, - {name:'abstract',type:'V_WString',size:1000}, - {name:'url',type:'V_WString',size:1000}, - {name:'short_url',type:'V_WString',size:1000}, - {name:'byline',type:'V_WString',size:1000}, - {name:'updated',type:'V_WString',size:1000}, - {name:'created',type:'V_WString',size:1000}, - {name:'published',type:'V_WString',size:1000}, - {name:'image_url',type:'V_WString',size:1000}, - {name:'image_caption',type:'V_WString',size:1000}, - {name:'image_copyright',type:'V_WString',size:1000} - ]; - - Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": fieldMap }); - Alteryx.Engine.SendMessage.Complete(); - - } }; Alteryx.Plugin.PI_Close = function() From 7403bc8919701373f14c8ef89efb7c173ae477fd Mon Sep 17 00:00:00 2001 From: Taylor Cox Date: Thu, 22 Mar 2018 17:20:18 -0400 Subject: [PATCH 3/3] more engine enhancements & refactoring --- engine.html | 156 +++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 86 deletions(-) diff --git a/engine.html b/engine.html index 0217463..fd5fe07 100644 --- a/engine.html +++ b/engine.html @@ -17,7 +17,6 @@ baseUrl: '', apiKey: '', sections: [], - connected: false, fieldMap: [ {name:'api_section',type:'V_WString',size:500}, {name:'article_section',type:'V_WString',size:500}, @@ -36,6 +35,69 @@ ] } + function fetchArticles() { + + // go time, make some API calls + + Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); + + var promises = []; + + globes.sections.forEach(function(s){ + getUrl = globes.baseUrl + '/svc/topstories/v2/' + s + '.json?api-key=' + globes.apiKey; + promises.push(axios.get(getUrl)) + }); + + var articles = []; + + axios.all(promises).then(function(results) { + results.forEach(function(res) { + + Alteryx.Engine.SendMessage.Info('Downloaded ' + res.data.num_results + ' articles from the "' + res.data.section + '" section.'); + + for (r = 0; r < res.data.results.length; r++) { + + apiSection = res.data.section + a = res.data.results[r] + + imgUrl = a.multimedia[0] ? a.multimedia[0].url : '-' + imgCaption = a.multimedia[0] ? a.multimedia[0].caption : '-' + imgCopyright = a.multimedia[0] ? a.multimedia[0].copyright : '-' + + articles.push([ + apiSection, + a.section, + a.subsection, + a.title, + a.abstract, + a.url, + a.short_url, + a.byline, + a.updated_date, + a.created_date, + a.published_date, + imgUrl, + imgCaption, + imgCopyright + ]); + } + + }) + + Alteryx.Engine.SendMessage.PushRecords("Articles", articles); + Alteryx.Engine.SendMessage.Complete(); + }) + .catch(function (error) { + Alteryx.Engine.SendMessage.Error('Uh oh! Error in API callback...'); + Alteryx.Engine.SendMessage.Error('This is usually the result of API call limits being exceeded (limits are 5 per second and/or 1000 per day) Try reducing the number of selected sections in the UI.'); + Alteryx.Engine.SendMessage.Error('Error details are below. For other errors, please submit an issue at https://github.com/alteryx-vue/nyt-connector/issues'); + Alteryx.Engine.SendMessage.Error('Error Message: ' + JSON.stringify(error.response.data.message)); + Alteryx.Engine.SendMessage.Error('Response Headers: ' + JSON.stringify(error.response.headers)); + Alteryx.Engine.SendMessage.Complete(); + }); + + } + Alteryx.Plugin.DefineConnections = function() { return { @@ -54,13 +116,10 @@ globes.baseUrl = config.Configuration.baseUrl; globes.apiKey = config.Configuration.apiKey; globes.sections = config.Configuration.selections; - globes.connected = true; } else if (config.Configuration.connects > 0 ) { Alteryx.Engine.SendMessage.Error('Connection to ' + config.Configuration.baseUrl + ' failed! Please check your API Key..'); - globes.connected = false; } else { Alteryx.Engine.SendMessage.Warning('Not connected, don\'t expect any results...'); - globes.connected = false; } }; @@ -79,88 +138,13 @@ Alteryx.Plugin.PI_PushAllRecords = function(recordLimit) { - - if(recordLimit.RecordLimit > 0){ - - // go time, make some API calls - - Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); - - var promises = []; - - globes.sections.forEach(function(s){ - getUrl = globes.baseUrl + '/svc/topstories/v2/' + s + '.json?api-key=' + globes.apiKey; - promises.push(axios.get(getUrl)) - }); - - var articles = []; - - axios.all(promises).then(function(results) { - results.forEach(function(response) { - - Alteryx.Engine.SendMessage.Info('Pulled ' + response.data.num_results + ' articles from the "' + response.data.section + '" section.'); - - for (r = 0; r < response.data.results.length; r++) { - if(response.data.results[r].multimedia[0]) { - article = [ - response.data.section, - response.data.results[r].section, - response.data.results[r].subsection, - response.data.results[r].title, - response.data.results[r].abstract, - response.data.results[r].url, - response.data.results[r].short_url, - response.data.results[r].byline, - response.data.results[r].updated_date, - response.data.results[r].created_date, - response.data.results[r].published_date, - response.data.results[r].multimedia[0].url, - response.data.results[r].multimedia[0].caption, - response.data.results[r].multimedia[0].copyright - ]; - }else{ - article = [ - response.data.section, - response.data.results[r].section, - response.data.results[r].subsection, - response.data.results[r].title, - response.data.results[r].abstract, - response.data.results[r].url, - response.data.results[r].short_url, - response.data.results[r].byline, - response.data.results[r].updated_date, - response.data.results[r].created_date, - response.data.results[r].published_date, - '-', - '-', - '-' - ]; - } - articles.push(article); - } - - }) - - Alteryx.Engine.SendMessage.PushRecords("Articles", articles); - Alteryx.Engine.SendMessage.Complete(); - }) - .catch(function (error) { - Alteryx.Engine.SendMessage.Error('Uh oh! Error in API callback...'); - Alteryx.Engine.SendMessage.Error('This is usually the result of API call limits being exceeded (limits are 5 per second and/or 1000 per day) Try reducing the number of selected sections in the UI.'); - Alteryx.Engine.SendMessage.Error('Error details are below. For other errors, please submit an issue at https://github.com/alteryx-vue/nyt-connector/issues'); - Alteryx.Engine.SendMessage.Error('Error Message: ' + JSON.stringify(error.response.data.message)); - Alteryx.Engine.SendMessage.Error('Response Headers: ' + JSON.stringify(error.response.headers)); - Alteryx.Engine.SendMessage.Complete(); - }); - - } else { - - // just push the field map - Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); - Alteryx.Engine.SendMessage.Complete(); - - } - + if (recordLimit.RecordLimit > 0) { + fetchArticles(); + } else { + // config update only, just push field map + Alteryx.Engine.SendMessage.RecordInfo("Articles", { "Field": globes.fieldMap }); + Alteryx.Engine.SendMessage.Complete(); + } }; Alteryx.Plugin.PI_Close = function()