diff --git a/services/wordpress/wordpress-base.js b/services/wordpress/wordpress-base.js index 365e70625fdca..04046aa0c4687 100644 --- a/services/wordpress/wordpress-base.js +++ b/services/wordpress/wordpress-base.js @@ -41,7 +41,7 @@ const notFoundSchema = Joi.object() const pluginSchemas = Joi.alternatives(pluginSchema, notFoundSchema) const themeSchemas = Joi.alternatives(themeSchema, notFoundSchema) -export default class BaseWordpress extends BaseJsonService { +export class BaseWordpress extends BaseJsonService { async fetch({ extensionType, slug }) { const url = `https://api.wordpress.org/${extensionType}s/info/1.2/` let schemas @@ -84,3 +84,12 @@ export default class BaseWordpress extends BaseJsonService { return json } } + +export const documentation = ` +

+ These badges rely on an API that is no longer supported by Wordpress. You are + still free to use them, simply bear in mind that Shields.io cannot guarantee + that they'll keep on working in the future. Please also double-check the + provided slug, as an incorrect value may lead to unexpected results. +

+` diff --git a/services/wordpress/wordpress-downloads.service.js b/services/wordpress/wordpress-downloads.service.js index 4a9585e250c1e..ec5b020857b93 100644 --- a/services/wordpress/wordpress-downloads.service.js +++ b/services/wordpress/wordpress-downloads.service.js @@ -1,7 +1,6 @@ import Joi from 'joi' import { renderDownloadsBadge } from '../downloads.js' -import { NotFound } from '../index.js' -import BaseWordpress from './wordpress-base.js' +import { documentation, BaseWordpress } from './wordpress-base.js' const dateSchema = Joi.object() .pattern(Joi.date().iso(), Joi.number().integer()) @@ -58,6 +57,7 @@ function DownloadsForExtensionType(extensionType) { title: `WordPress ${capt} Downloads`, namedParams: { interval: 'dm', slug: exampleSlug }, staticPreview: this.render({ interval: 'dm', downloads: 200000 }), + documentation, }, ] @@ -91,17 +91,9 @@ function DownloadsForExtensionType(extensionType) { }, }, }) - const size = Object.keys(json).length downloads = Object.values(json).reduce( (a, b) => parseInt(a) + parseInt(b) ) - // This check is for non-existent and brand-new plugins both having new stats. - // Non-Existent plugins results are the same as a brandspanking new plugin with no downloads. - if (downloads <= 0 && size <= 1) { - throw new NotFound({ - prettyMessage: `${extensionType} not found or too new`, - }) - } } return this.constructor.render({ interval, downloads }) @@ -127,6 +119,7 @@ function InstallsForExtensionType(extensionType) { title: `WordPress ${capt} Active Installs`, namedParams: { slug: exampleSlug }, staticPreview: renderDownloadsBadge({ downloads: 300000 }), + documentation, }, ] diff --git a/services/wordpress/wordpress-downloads.tester.js b/services/wordpress/wordpress-downloads.tester.js index 05019f0782733..b82bffc9dc949 100644 --- a/services/wordpress/wordpress-downloads.tester.js +++ b/services/wordpress/wordpress-downloads.tester.js @@ -98,34 +98,6 @@ t.create('Plugin Downloads - Active | Not Found') message: 'not found', }) -t.create('Plugin Downloads - Day | Not Found') - .get('/plugin/dd/100.json') - .expectBadge({ - label: 'downloads', - message: 'plugin not found or too new', - }) - -t.create('Plugin Downloads - Week | Not Found') - .get('/plugin/dw/100.json') - .expectBadge({ - label: 'downloads', - message: 'plugin not found or too new', - }) - -t.create('Plugin Downloads - Month | Not Found') - .get('/plugin/dm/100.json') - .expectBadge({ - label: 'downloads', - message: 'plugin not found or too new', - }) - -t.create('Plugin Downloads - Year | Not Found') - .get('/plugin/dy/100.json') - .expectBadge({ - label: 'downloads', - message: 'plugin not found or too new', - }) - t.create('Theme Downloads - Total | Not Found') .get('/theme/dt/100.json') .expectBadge({ @@ -139,31 +111,3 @@ t.create('Theme Downloads - Active | Not Found') label: 'active installs', message: 'not found', }) - -t.create('Theme Downloads - Day | Not Found') - .get('/theme/dd/100.json') - .expectBadge({ - label: 'downloads', - message: 'theme not found or too new', - }) - -t.create('Theme Downloads - Week | Not Found') - .get('/theme/dw/100.json') - .expectBadge({ - label: 'downloads', - message: 'theme not found or too new', - }) - -t.create('Theme Downloads - Month | Not Found') - .get('/theme/dm/100.json') - .expectBadge({ - label: 'downloads', - message: 'theme not found or too new', - }) - -t.create('Theme Downloads - Year | Not Found') - .get('/theme/dy/100.json') - .expectBadge({ - label: 'downloads', - message: 'theme not found or too new', - }) diff --git a/services/wordpress/wordpress-last-update.service.js b/services/wordpress/wordpress-last-update.service.js index 10b48ef92b7e4..eb7ae157bb142 100644 --- a/services/wordpress/wordpress-last-update.service.js +++ b/services/wordpress/wordpress-last-update.service.js @@ -2,7 +2,7 @@ import moment from 'moment' import { InvalidResponse } from '../index.js' import { formatDate } from '../text-formatters.js' import { age as ageColor } from '../color-formatters.js' -import BaseWordpress from './wordpress-base.js' +import { documentation, BaseWordpress } from './wordpress-base.js' const extensionData = { plugin: { @@ -35,6 +35,7 @@ function LastUpdateForType(extensionType) { title: `WordPress ${capt} Last Updated`, namedParams: { slug: exampleSlug }, staticPreview: this.render({ lastUpdated: '2020-08-11' }), + documentation, }, ] diff --git a/services/wordpress/wordpress-platform.service.js b/services/wordpress/wordpress-platform.service.js index 5c0d1cbd05aa7..c19716ed672ae 100644 --- a/services/wordpress/wordpress-platform.service.js +++ b/services/wordpress/wordpress-platform.service.js @@ -1,7 +1,7 @@ import { NotFound } from '../index.js' import { addv } from '../text-formatters.js' import { version as versionColor } from '../color-formatters.js' -import BaseWordpress from './wordpress-base.js' +import { documentation, BaseWordpress } from './wordpress-base.js' import { versionColorForWordpressVersion } from './wordpress-version-color.js' const extensionData = { @@ -33,6 +33,7 @@ function WordpressRequiresVersion(extensionType) { title: `WordPress ${capt}: Required WP Version`, namedParams: { slug: exampleSlug }, staticPreview: this.render({ wordpressVersion: '4.8' }), + documentation, }, ] @@ -77,6 +78,7 @@ class WordpressPluginTestedVersion extends BaseWordpress { staticPreview: this.renderStaticPreview({ testedVersion: '4.9.8', }), + documentation, }, ] @@ -128,6 +130,7 @@ function RequiresPHPVersionForType(extensionType) { title: `WordPress ${capt} Required PHP Version`, namedParams: { slug: exampleSlug }, staticPreview: this.render({ version: '5.5' }), + documentation, }, ] diff --git a/services/wordpress/wordpress-rating.service.js b/services/wordpress/wordpress-rating.service.js index 6489fde9dae90..af2e41d55775c 100644 --- a/services/wordpress/wordpress-rating.service.js +++ b/services/wordpress/wordpress-rating.service.js @@ -1,6 +1,6 @@ import { starRating, metric } from '../text-formatters.js' import { floorCount } from '../color-formatters.js' -import BaseWordpress from './wordpress-base.js' +import { documentation, BaseWordpress } from './wordpress-base.js' const extensionData = { plugin: { @@ -38,6 +38,7 @@ function RatingForExtensionType(extensionType) { rating: 80, numRatings: 100, }), + documentation, }, ] @@ -78,7 +79,7 @@ function StarsForExtensionType(extensionType) { staticPreview: this.render({ rating: 80, }), - documentation: 'There is an alias /r/:slug.svg as well.', + documentation, }, ] diff --git a/services/wordpress/wordpress-version.service.js b/services/wordpress/wordpress-version.service.js index 9f5d62741391e..f3015bfa3cca3 100644 --- a/services/wordpress/wordpress-version.service.js +++ b/services/wordpress/wordpress-version.service.js @@ -1,6 +1,6 @@ import { addv } from '../text-formatters.js' import { version as versionColor } from '../color-formatters.js' -import BaseWordpress from './wordpress-base.js' +import { documentation, BaseWordpress } from './wordpress-base.js' function VersionForExtensionType(extensionType) { const { capt, exampleSlug } = { @@ -29,6 +29,7 @@ function VersionForExtensionType(extensionType) { title: `WordPress ${capt} Version`, namedParams: { slug: exampleSlug }, staticPreview: this.render({ version: 2.5 }), + documentation, }, ]