Files
shields/services/wordpress/wordpress-base.js
dependabot-preview[bot] 294aa1e1df Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0; autofixes (#3671)
* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Autofixes
2019-07-08 12:13:46 -04:00

54 lines
1.3 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { nonNegativeInteger } = require('../validators')
const { BaseJsonService, NotFound } = require('..')
const foundSchema = Joi.object()
.keys({
version: Joi.string(),
rating: nonNegativeInteger,
num_ratings: nonNegativeInteger,
downloaded: nonNegativeInteger,
active_installs: nonNegativeInteger,
requires: Joi.string(), // Plugin Only
tested: Joi.string(), // Plugin Only
})
.required()
const notFoundSchema = Joi.string().allow(null, false)
const schemas = Joi.alternatives(foundSchema, notFoundSchema)
module.exports = class BaseWordpress extends BaseJsonService {
async fetch({ extensionType, slug }) {
const url = `https://api.wordpress.org/${extensionType}s/info/1.1/`
const json = await this._requestJson({
url,
schema: schemas,
options: {
qs: {
action: `${extensionType}_information`,
request: {
slug,
fields: {
active_installs: 1,
sections: 0,
homepage: 0,
tags: 0,
screenshot_url: 0,
},
},
},
qsStringifyOptions: {
encode: false,
},
},
})
if (!json) {
throw new NotFound()
}
return json
}
}