This code automates the process of fetching API discovery documents, converting them to a specific format, and saving them to local files. It is likely used to prepare API documentation or configuration for a system that relies on Google Discovery.
npm run import -- "test rpc from spec"
var fs = require('fs')
var path = require('path')
var importer = require('../Core')
var getRpcFromSpec = importer.import("get rpc from spec")
function testDiscovery(config = {api: 'drive', version: 'v3'}) {
var discovery = getRpcFromSpec(require('/Users/briancullinan/Downloads/rest.json'));
// Promise.resolve(discovery)
return discovery.apis.getRest(config)
.then(r => {
try {
fs.writeFileSync(path.join(__dirname, `../Resources/APIs/${config.api}.${config.version}.json`),
JSON.stringify(r.body, null, 4))
} catch (up) {
throw up
}
return r.body
})
}
if(typeof $ !== 'undefined') {
$.async();
testDiscovery()
.then(r => $.sendResult(r))
// .then(r => $.sendResult(getRpcFromSpec(r)))
.catch(e => $.sendError(e))
}
module.exports = testDiscovery
const fs = require('fs');
const path = require('path');
const importer = require('../Core');
const { getRpcFromSpec } = importer.import();
/**
* Test API discovery for a given configuration.
*
* @param {Object} config - Configuration object with 'api' and'version' properties.
* @param {string} config.api - API name.
* @param {string} config.version - API version.
* @returns {Promise
This code snippet fetches and saves API discovery documents in a specific format.
Key Points:
fs
for file system operations, path
for path manipulation, and importer
for loading a function getRpcFromSpec
.testDiscovery
Function:
config
object with api
and version
properties.rest.json
).getRpcFromSpec
to convert the specification into a Google Discovery format.if(typeof $ !== 'undefined')
block executes only in a specific environment (likely a browser).testDiscovery
, handles the result (sending it as a success or error message), and likely interacts with a framework or environment using $.async()
, $.sendResult()
, and $.sendError()
.Purpose:
This code likely automates the process of fetching, converting, and saving API discovery documents for use in a system that requires them.