Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "pageviews", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A lightweight JavaScript client library for the Wikimedia Pageviews API for Wikipedia and various of its sister projects for Node.js and the browser.", | ||
@@ -32,4 +32,4 @@ "main": "pageviews.js", | ||
"chai": "^3.5.0", | ||
"mocha": "^2.4.5" | ||
"mocha": "^3.2.0" | ||
} | ||
} |
/** | ||
* @license | ||
* Copyright 2016 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* Copyright 2017 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* | ||
@@ -72,3 +72,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
default: 'daily', | ||
allowed: ['daily'] | ||
allowed: ['daily', 'monthly'] | ||
}; | ||
@@ -75,0 +75,0 @@ |
/** | ||
* @license | ||
* Copyright 2016 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* Copyright 2017 Thomas Steiner (@tomayac). All Rights Reserved. | ||
* | ||
@@ -17,2 +17,2 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
var request,USER_AGENT="pageviews.js",environment="undefined"==typeof window?"node":"browser";if("node"===environment){request=require("request");var packageJson=require("./package.json");USER_AGENT="pageviews.js-v"+packageJson.version+" ("+packageJson.repository.url+")"}else request=function(e,r){var t=new XMLHttpRequest;t.addEventListener("load",function(){return r(null,{statusCode:this.status},this.responseText)}),t.addEventListener("error",function(e){return r(e)}),t.open("GET",e.url),t.send()};var pageviews=function(){var e="https://wikimedia.org/api/rest_v1",r={"default":"all-access",allowed:["all-access","desktop","mobile-web","mobile-app"]},t={"default":"all-sites",allowed:["all-sites","desktop-site","mobile-site"]},a={"default":"all-agents",allowed:["all-agents","user","spider","bot"]},i={"default":"hourly",allowed:["daily","hourly","monthly"]},n={"default":"daily",allowed:["daily"]},s={"default":"daily",allowed:["daily","monthly"]},o=function(e,o){var l=function(e){return 10>e?"0"+e:e.toString()};if(!e)return new Error("Required parameters missing.");if(!e.project&&!e.projects)return new Error("getAggregatedPageviews"===o||"getTopPageviews"===o?'Required parameter "project" or "projects" missing.':'Required parameter "project" missing.');if(e.project&&"all-projects"!==e.project&&"wikidata"!==e.project&&-1===e.project.indexOf("."))return new Error('Required parameter "project" invalid.');if(!("getAggregatedPageviews"!==o&&"getTopPageviews"!==o||!e.projects||"all-projects"==e.projects||Array.isArray(e.projects)&&e.projects.length&&!e.projects.filter(function(e){return-1===e.indexOf(".")&&"all-projects"!==e&&"wikidata"!==e}).length))return new Error('Required parameter "projects" invalid.');if("getPerArticlePageviews"===o){if(!e.article&&!e.articles)return new Error('Required parameter "article" or "articles" missing.');if(e.articles&&(!Array.isArray(e.articles)||!e.articles.length))return new Error('Required parameter "articles" invalid.')}if("getPerArticlePageviews"===o||"getUniqueDevices"===o){if(!e.start)return new Error('Required parameter "start" missing.');if(e.start="object"==typeof e.start?e.start.getUTCFullYear()+l(e.start.getUTCMonth()+1)+l(e.start.getUTCDate()):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])$/.test(e.start))return new Error('Required parameter "start" invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getUTCFullYear()+l(e.end.getUTCMonth()+1)+l(e.end.getUTCDate()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])$/.test(e.end))return new Error('Required parameter "end" invalid.')}else if("getAggregatedPageviews"===o){if(!e.start)return new Error('Required parameter "start" missing.');if(e.start="object"==typeof e.start?e.start.getUTCFullYear()+l(e.start.getUTCMonth()+1)+(l(e.start.getUTCDate())+l(e.start.getUTCHours())):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.start))return new Error('Required parameter "start" missing or invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getUTCFullYear()+l(e.end.getUTCMonth()+1)+l(e.end.getUTCDate())+l(e.end.getUTCHours()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.end))return new Error('Required parameter "end" missing or invalid.')}if("getTopPageviews"===o){if(e.date&&(e.date="object"==typeof e.date?e.date:new Date(e.date.substr(0,4)+"-"+e.date.substr(4,2)+"-"+e.date.substr(6,2)),e.year=e.date.getUTCFullYear(),e.month=l(e.date.getUTCMonth()+1),e.day=l(e.date.getUTCDate())),!e.year||!/^(?:19|20)\d\d$/.test(e.year))return new Error('Required parameter "year" missing or invalid.');if(!e.month||!/^(?:0?[1-9]|1[012])$/.test(e.month))return new Error('Required parameter "month" missing or invalid.');if(!e.day||!/^(?:0?[1-9]|[12][0-9]|3[01])$/.test(e.day))return new Error('Required parameter "day" missing or invalid.');if(e.limit&&!/^\d+$/.test(e.limit)&&0<e.limit&&e.limit<=1e3)return new Error('Invalid optional parameter "limit".')}if(e.access&&-1===r.allowed.indexOf(e.access))return new Error('Invalid optional parameter "access".');if(e.accessSite&&-1===t.allowed.indexOf(e.accessSite))return new Error('Invalid optional parameter "accessSite".');if(e.agent&&-1===a.allowed.indexOf(e.agent))return new Error('Invalid optional parameter "agent".');if(e.granularity)if("getAggregatedPageviews"===o){if(-1===i.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getPerArticlePageviews"===o){if(-1===n.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getUniqueDevices"===o&&-1===s.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".');return e},l=function(e,r,t){var a;if(e||200!==r.statusCode){if(e)return e;if(404===r.statusCode)try{return a=JSON.parse(t),new Error(a.detail)}catch(i){return new Error(i)}return new Error("Status code "+r.statusCode)}try{a=JSON.parse(t)}catch(i){return new Error(i)}return a},u=function(t){return new Promise(function(i,s){if(t=o(t,"getPerArticlePageviews"),t.stack)return s(t);if(t.articles){var d=[];return t.articles.map(function(e,r){var a=t;delete a.articles,a.article=e,d[r]=u(a)}),i(Promise.all(d))}var c=t.project,g=encodeURIComponent(t.article.replace(/\s/g,"_")),p=t.start,f=t.end,m=t.access?t.access:r["default"],w=t.agent?t.agent:a["default"],v=t.granularity?t.granularity:n["default"],y={url:e+"/metrics/pageviews/per-article/"+c+"/"+m+"/"+w+"/"+g+"/"+v+"/"+p+"/"+f,headers:{"User-Agent":USER_AGENT}};request(y,function(e,r,t){var a=l(e,r,t);return a.stack?s(a):i(a)})})},d=function(t){return new Promise(function(n,s){if(t=o(t,"getAggregatedPageviews"),t.stack)return s(t);if("all-projects"===t.projects&&(t.projects=null,t.project="all-projects"),t.projects){var u=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,u[r]=d(a)}),n(Promise.all(u))}var c=t.project,g=t.start,p=t.end,f=t.access?t.access:r["default"],m=t.agent?t.agent:a["default"],w=t.granularity?t.granularity:i["default"],v={url:e+"/metrics/pageviews/aggregate/"+c+"/"+f+"/"+m+"/"+w+"/"+g+"/"+p,headers:{"User-Agent":USER_AGENT}};request(v,function(e,r,t){var a=l(e,r,t);return a.stack?s(a):n(a)})})},c=function(t){return new Promise(function(a,i){if(t=o(t,"getTopPageviews"),t.stack)return i(t);if(t.projects){var n=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,n[r]=c(a)}),a(Promise.all(n))}var s=t.project,u=t.year,d="number"==typeof t.month&&t.month<10?"0"+t.month:t.month,g="number"==typeof t.day&&t.day<10?"0"+t.day:t.day,p=t.limit||!1,f=t.access?t.access:r["default"],m={url:e+"/metrics/pageviews/top/"+s+"/"+f+"/"+u+"/"+d+"/"+g,headers:{"User-Agent":USER_AGENT}};request(m,function(e,r,t){var n=l(e,r,t);return n.stack?i(n):(p&&(n.items[0].articles=n.items[0].articles.slice(0,p)),a(n))})})},g=function(){return new Promise(function(r,t){var a={url:e+"/metrics/pageviews/",headers:{"User-Agent":USER_AGENT}};request(a,function(e,a,i){var n=l(e,a,i);return n.stack?t(n):r(n)})})},p=function(r){return new Promise(function(a,i){if(r=o(r,"getUniqueDevices"),r.stack)return i(r);var n=r.project,u=r.start,d=r.end,c=r.accessSite?r.accessSite:t["default"],g=r.granularity?r.granularity:s["default"],p={url:e+"/metrics/unique-devices/"+n+"/"+c+"/"+g+"/"+u+"/"+d,headers:{"User-Agent":USER_AGENT}};request(p,function(e,r,t){var n=l(e,r,t);return n.stack?i(n):a(n)})})};return{getPageviewsDimensions:g,getPerArticlePageviews:u,getAggregatedPageviews:d,getTopPageviews:c,getUniqueDevices:p}}();"node"===environment&&(module.exports=pageviews); | ||
var request,USER_AGENT="pageviews.js",environment="undefined"==typeof window?"node":"browser";if("node"===environment){request=require("request");var packageJson=require("./package.json");USER_AGENT="pageviews.js-v"+packageJson.version+" ("+packageJson.repository.url+")"}else request=function(e,r){var t=new XMLHttpRequest;t.addEventListener("load",function(){return r(null,{statusCode:this.status},this.responseText)}),t.addEventListener("error",function(e){return r(e)}),t.open("GET",e.url),t.send()};var pageviews=function(){var e="https://wikimedia.org/api/rest_v1",r={"default":"all-access",allowed:["all-access","desktop","mobile-web","mobile-app"]},t={"default":"all-sites",allowed:["all-sites","desktop-site","mobile-site"]},a={"default":"all-agents",allowed:["all-agents","user","spider","bot"]},i={"default":"hourly",allowed:["daily","hourly","monthly"]},n={"default":"daily",allowed:["daily","monthly"]},s={"default":"daily",allowed:["daily","monthly"]},o=function(e,o){var l=function(e){return 10>e?"0"+e:e.toString()};if(!e)return new Error("Required parameters missing.");if(!e.project&&!e.projects)return new Error("getAggregatedPageviews"===o||"getTopPageviews"===o?'Required parameter "project" or "projects" missing.':'Required parameter "project" missing.');if(e.project&&"all-projects"!==e.project&&"wikidata"!==e.project&&-1===e.project.indexOf("."))return new Error('Required parameter "project" invalid.');if(!("getAggregatedPageviews"!==o&&"getTopPageviews"!==o||!e.projects||"all-projects"==e.projects||Array.isArray(e.projects)&&e.projects.length&&!e.projects.filter(function(e){return-1===e.indexOf(".")&&"all-projects"!==e&&"wikidata"!==e}).length))return new Error('Required parameter "projects" invalid.');if("getPerArticlePageviews"===o){if(!e.article&&!e.articles)return new Error('Required parameter "article" or "articles" missing.');if(e.articles&&(!Array.isArray(e.articles)||!e.articles.length))return new Error('Required parameter "articles" invalid.')}if("getPerArticlePageviews"===o||"getUniqueDevices"===o){if(!e.start)return new Error('Required parameter "start" missing.');if(e.start="object"==typeof e.start?e.start.getUTCFullYear()+l(e.start.getUTCMonth()+1)+l(e.start.getUTCDate()):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])$/.test(e.start))return new Error('Required parameter "start" invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getUTCFullYear()+l(e.end.getUTCMonth()+1)+l(e.end.getUTCDate()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])$/.test(e.end))return new Error('Required parameter "end" invalid.')}else if("getAggregatedPageviews"===o){if(!e.start)return new Error('Required parameter "start" missing.');if(e.start="object"==typeof e.start?e.start.getUTCFullYear()+l(e.start.getUTCMonth()+1)+(l(e.start.getUTCDate())+l(e.start.getUTCHours())):e.start,!/^(?:19|20)\d\d[- \/.]?(?:0[1-9]|1[012])[- \/.]?(?:0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.start))return new Error('Required parameter "start" missing or invalid.');if(!e.end)return new Error('Required parameter "end" missing.');if(e.end="object"==typeof e.end?e.end.getUTCFullYear()+l(e.end.getUTCMonth()+1)+l(e.end.getUTCDate())+l(e.end.getUTCHours()):e.end,!/^(19|20)\d\d[- \/.]?(0[1-9]|1[012])[- \/.]?(0[1-9]|[12][0-9]|3[01])[- \/.]?(?:[012][0-9])$/.test(e.end))return new Error('Required parameter "end" missing or invalid.')}if("getTopPageviews"===o){if(e.date&&(e.date="object"==typeof e.date?e.date:new Date(e.date.substr(0,4)+"-"+e.date.substr(4,2)+"-"+e.date.substr(6,2)),e.year=e.date.getUTCFullYear(),e.month=l(e.date.getUTCMonth()+1),e.day=l(e.date.getUTCDate())),!e.year||!/^(?:19|20)\d\d$/.test(e.year))return new Error('Required parameter "year" missing or invalid.');if(!e.month||!/^(?:0?[1-9]|1[012])$/.test(e.month))return new Error('Required parameter "month" missing or invalid.');if(!e.day||!/^(?:0?[1-9]|[12][0-9]|3[01])$/.test(e.day))return new Error('Required parameter "day" missing or invalid.');if(e.limit&&!/^\d+$/.test(e.limit)&&0<e.limit&&e.limit<=1e3)return new Error('Invalid optional parameter "limit".')}if(e.access&&-1===r.allowed.indexOf(e.access))return new Error('Invalid optional parameter "access".');if(e.accessSite&&-1===t.allowed.indexOf(e.accessSite))return new Error('Invalid optional parameter "accessSite".');if(e.agent&&-1===a.allowed.indexOf(e.agent))return new Error('Invalid optional parameter "agent".');if(e.granularity)if("getAggregatedPageviews"===o){if(-1===i.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getPerArticlePageviews"===o){if(-1===n.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".')}else if("getUniqueDevices"===o&&-1===s.allowed.indexOf(e.granularity))return new Error('Invalid optional parameter "granularity".');return e},l=function(e,r,t){var a;if(e||200!==r.statusCode){if(e)return e;if(404===r.statusCode)try{return a=JSON.parse(t),new Error(a.detail)}catch(i){return new Error(i)}return new Error("Status code "+r.statusCode)}try{a=JSON.parse(t)}catch(i){return new Error(i)}return a},u=function(t){return new Promise(function(i,s){if(t=o(t,"getPerArticlePageviews"),t.stack)return s(t);if(t.articles){var d=[];return t.articles.map(function(e,r){var a=t;delete a.articles,a.article=e,d[r]=u(a)}),i(Promise.all(d))}var c=t.project,g=encodeURIComponent(t.article.replace(/\s/g,"_")),p=t.start,f=t.end,m=t.access?t.access:r["default"],w=t.agent?t.agent:a["default"],v=t.granularity?t.granularity:n["default"],y={url:e+"/metrics/pageviews/per-article/"+c+"/"+m+"/"+w+"/"+g+"/"+v+"/"+p+"/"+f,headers:{"User-Agent":USER_AGENT}};request(y,function(e,r,t){var a=l(e,r,t);return a.stack?s(a):i(a)})})},d=function(t){return new Promise(function(n,s){if(t=o(t,"getAggregatedPageviews"),t.stack)return s(t);if("all-projects"===t.projects&&(t.projects=null,t.project="all-projects"),t.projects){var u=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,u[r]=d(a)}),n(Promise.all(u))}var c=t.project,g=t.start,p=t.end,f=t.access?t.access:r["default"],m=t.agent?t.agent:a["default"],w=t.granularity?t.granularity:i["default"],v={url:e+"/metrics/pageviews/aggregate/"+c+"/"+f+"/"+m+"/"+w+"/"+g+"/"+p,headers:{"User-Agent":USER_AGENT}};request(v,function(e,r,t){var a=l(e,r,t);return a.stack?s(a):n(a)})})},c=function(t){return new Promise(function(a,i){if(t=o(t,"getTopPageviews"),t.stack)return i(t);if(t.projects){var n=[];return t.projects.map(function(e,r){var a=t;delete a.projects,a.project=e,n[r]=c(a)}),a(Promise.all(n))}var s=t.project,u=t.year,d="number"==typeof t.month&&t.month<10?"0"+t.month:t.month,g="number"==typeof t.day&&t.day<10?"0"+t.day:t.day,p=t.limit||!1,f=t.access?t.access:r["default"],m={url:e+"/metrics/pageviews/top/"+s+"/"+f+"/"+u+"/"+d+"/"+g,headers:{"User-Agent":USER_AGENT}};request(m,function(e,r,t){var n=l(e,r,t);return n.stack?i(n):(p&&(n.items[0].articles=n.items[0].articles.slice(0,p)),a(n))})})},g=function(){return new Promise(function(r,t){var a={url:e+"/metrics/pageviews/",headers:{"User-Agent":USER_AGENT}};request(a,function(e,a,i){var n=l(e,a,i);return n.stack?t(n):r(n)})})},p=function(r){return new Promise(function(a,i){if(r=o(r,"getUniqueDevices"),r.stack)return i(r);var n=r.project,u=r.start,d=r.end,c=r.accessSite?r.accessSite:t["default"],g=r.granularity?r.granularity:s["default"],p={url:e+"/metrics/unique-devices/"+n+"/"+c+"/"+g+"/"+u+"/"+d,headers:{"User-Agent":USER_AGENT}};request(p,function(e,r,t){var n=l(e,r,t);return n.stack?i(n):a(n)})})};return{getPageviewsDimensions:g,getPerArticlePageviews:u,getAggregatedPageviews:d,getTopPageviews:c,getUniqueDevices:p}}();"node"===environment&&(module.exports=pageviews); |
@@ -198,3 +198,3 @@ # pageviews.js | ||
# License | ||
Copyright 2016 Thomas Steiner (@tomayac) | ||
Copyright 2017 Thomas Steiner (@tomayac) | ||
@@ -201,0 +201,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77479
12