Files
shields/lib/svg-badge-parser.js
Paul Melnikow 275805e90c Add BaseSvgScrapingService and rewrite [ReadTheDocs]; also affects [codacy vso] (#2229)
Based on discussion in #2031, this adds an abstract service for SVG badges. I started with Readthedocs and the other services can be done as a follow-on.

I called it **BaseSvgScrapingService** rather than **BaseSvgService** to clarify that it's for badges from svg source data – not svg badges, which is all the badges.

Since I don't expect the svg parsing function to be used anywhere else once the services are refactored, I moved it into the class. I added a default value for `valueMatcher`, which works on Shields-style badges and seems to be used more than once.

The tests are based on XmlBaseService. I added one for valueMatcher, and also moved the SVG parsing badge here. Testing on codacy + vso should ensure the old `fetchFromSvg` is still working.
2018-11-01 15:09:00 -04:00

21 lines
463 B
JavaScript

'use strict'
const { valueFromSvgBadge } = require('../services/base-svg-scraping')
const nodeifySync = require('./nodeify-sync')
// Get data from a svg-style badge.
// cb: function(err, string)
function fetchFromSvg(request, url, valueMatcher, cb) {
request(url, (err, res, buffer) => {
if (err !== null) {
cb(err)
} else {
nodeifySync(() => valueFromSvgBadge(buffer, valueMatcher), cb)
}
})
}
module.exports = {
fetchFromSvg,
}