resource-watch/widget

View on GitHub
app/src/services/screenshot.service.js

Summary

Maintainability
A
35 mins
Test Coverage
A
100%
const logger = require('logger');
const { RWAPIMicroservice } = require('rw-api-microservice-node');

class ScreenshotService {

    static async takeWidgetScreenshot(id, apiKey) {
        logger.debug('[ScreenshotService]: Taking screenshot');
        try {
            return await RWAPIMicroservice.requestToMicroservice({
                uri: `/v1/webshot/widget/${id}/thumbnail`,
                method: 'POST',
                json: true,
                headers: {
                    'x-api-key': apiKey,
                }
            });
        } catch (e) {
            logger.error(`[ScreenshotService]: Error taking screenshot: ${e}`);
            throw new Error(e);
        }
    }

}

module.exports = ScreenshotService;