How to use the popsicle.plugins function in popsicle

To help you get started, we’ve selected a few popsicle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AraiEzzra / DDKCORE / src / modules / transport.js View on Github external
peer = library.logic.peers.create(peer);
    __private.headers.port = 7007;
    const req = {
        url: `http://${peer.ip}:${peer.port}${url}`,
        method: options.method,
        headers: __private.headers,
        timeout: library.config.peers.options.timeout
    };

    if (options.data) {
        req.body = options.data;
    }

    popsicle.request(req)
        .use(popsicle.plugins.parse(['json'], false))
        .then((res) => {
            if (res.status !== 200) {
                // Remove peer
                __private.removePeer({ peer, code: `ERESPONSE ${res.status}` }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
            }
            const headers = peer.applyHeaders(res.headers);

            const report = library.schema.validate(headers, schema.headers);
            if (!report) {
                // Remove peer
                console.log('EHEADERS1', report);
                __private.removePeer({ peer, code: 'EHEADERS' }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
github AraiEzzra / DDKCORE / backlog / modules / transport.js View on Github external
peer = library.logic.peers.create(peer);
    __private.headers.port = 7007;
    const req = {
        url: `http://${peer.ip}:${peer.port}${url}`,
        method: options.method,
        headers: __private.headers,
        timeout: library.config.peers.options.timeout
    };

    if (options.data) {
        req.body = options.data;
    }

    popsicle.request(req)
        .use(popsicle.plugins.parse(['json'], false))
        .then((res) => {
            if (res.status !== 200) {
                // Remove peer
                __private.removePeer({ peer, code: `ERESPONSE ${res.status}` }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
            }
            const headers = peer.applyHeaders(res.headers);

            const report = library.schema.validate(headers, schema.headers);
            if (!report) {
                // Remove peer
                console.log('EHEADERS1', report);
                __private.removePeer({ peer, code: 'EHEADERS' }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
github jcoreio / crater / test / integration / integrationTests.js View on Github external
it('proxies or defers to /sockjs', async () => {
    const response = (await popsicle.get(await getRootUrl() + '/sockjs/info')
      .use(popsicle.plugins.parse(['json', 'urlencoded']))).body
    expect(response.websocket).to.be.true
  })
}
github doodyparizada / word2vec-spam-filter / webclient / scripts / src / index.ts View on Github external
function analyze(indexes: number[], reals: number[]): Promise<{ spam: boolean; confidence: number; }> {
	return popsicle
		.request(createGetUrl("/words/vector", "ids", indexes))
		.use(popsicle.plugins.parse("json"))
		.then(response => {
			let result: Vector = null;

			reals.forEach(index => {
				let vector = new Vector(response.body.words[index].vector);

				if (result === null) {
					result = vector;
				} else {
					result.add(vector);
				}
			});

			return popsicle
				.request(createGetUrl("/spam/detect", "vector", result.toArray()))
				.use(popsicle.plugins.parse("json"))
github VadimDez / ng2-pdf-viewer / node_modules / typings-core / dist / utils / fs.js View on Github external
'User-Agent': template(userAgent, {
                nodeVersion: process.version,
                platform: process.platform,
                arch: process.arch,
                typingsVersion: pkg.version
            })
        },
        options: {
            ca: ca,
            key: key,
            cert: cert,
            rejectUnauthorized: rejectUnauthorized
        },
        use: [
            popsicle.plugins.headers(),
            popsicle.plugins.unzip(),
            popsicle.plugins.concatStream('string')
        ]
    })
        .use(popsicleProxy({ proxy: proxy, httpProxy: httpProxy, httpsProxy: httpsProxy, noProxy: noProxy }))
        .use(popsicleRetry())
        .use(popsicleStatus(200))
        .use(function (self) {
        var hostname = self.Url.hostname;
        if (self.Url.host === registryURL.host) {
            self.before(function (req) {
                if (store_1.default.get('clientId')) {
                    req.set('Typings-Client-Id', store_1.default.get('clientId'));
                }
            });
            self.after(function (res) {
                if (res.get('Typings-Client-Id')) {
github LiskHQ / lisk-desktop / src / utils / api / btc / service.js View on Github external
export const getDynamicFees = () => new Promise(async (resolve, reject) => {
  try {
    const config = getBtcConfig(0);
    const response = await popsicle.get(config.minerFeesURL)
      .use(popsicle.plugins.parse('json'));
    const json = response.body;

    if (response) {
      resolve({
        Low: json.hourFee,
        Medium: json.halfHourFee,
        High: json.fastestFee,
      });
    } else {
      reject(json);
    }
  } catch (error) {
    reject(error);
  }
});
github crypti / eth-price / index.js View on Github external
module.exports = toSymbol => {
	if (typeof toSymbol === 'string') {
		toSymbol = toSymbol.toUpperCase();
	} else {
		toSymbol = 'USD';
	}

	return popsicle.request({
		method: 'POST',
		url: 'https://min-api.cryptocompare.com/data/price',
		query: {
			fsym: 'ETH',
			tsyms: toSymbol
		}
	})
		.use(popsicle.plugins.parse(['json']))
		.then(resp => resp.body)
		.then(data => {
			const symbols = Object.keys(data);

			return symbols
				.map(symbol => `${symbol}: ${data[symbol]}`);
		});
};
github LiskHQ / lisk-desktop / src / utils / api / btc / network.js View on Github external
get: path => (new Promise(async (resolve, reject) => {
      try {
        const response = await popsicle.get(`${config.url}/${path}`, config.requestOptions).use(popsicle.plugins.parse('json'));
        if (response.status === 200) {
          resolve(response);
        } else {
          reject(response);
        }
      } catch (error) {
        reject(error);
      }
    })),
    post: (path, body) => (
github LiskHQ / lisk-desktop / src / utils / api / lsk / liskService.js View on Github external
}) => new Promise((resolve, reject) => {
  serverUrl = networkConfig ? getServerUrl(networkConfig) : serverUrl;
  popsicle.get(`${serverUrl}${path}?${new URLSearchParams(searchParams)}`)
    .use(popsicle.plugins.parse('json'))
    .then((response) => {
      if (response.statusType() === 2) {
        resolve(transformResponse(response.body));
      } else {
        reject(new Error(response.body.message || response.body.error));
      }
    }).catch((error) => {
      if (error.code === 'EUNAVAILABLE') {
        const networkName = getNetworkNameBasedOnNethash(networkConfig);
        error = new Error(i18n.t('Unable to connect to {{networkName}}', { networkName }));
      }
      reject(error);
    });
});