How to use the pelias-microservice-wrapper.ServiceConfiguration function in pelias-microservice-wrapper

To help you get started, we’ve selected a few pelias-microservice-wrapper 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 pelias / api / service / configurations / PlaceHolder.js View on Github external
'use strict';

const url = require('url');

const _ = require('lodash');

const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;

class PlaceHolder extends ServiceConfiguration {
  constructor(o) {
    super('placeholder', o);
  }

  getParameters(req) {
    const parameters = {};

    if (_.has(req.clean.parsed_text, 'street')) {
      // assemble all these fields into a space-delimited string
      parameters.text = _.values(_.pick(req.clean.parsed_text,
        ['neighbourhood', 'borough', 'city', 'county', 'state', 'country'])).join(' ');

    } else {
      parameters.text = req.clean.text;
github pelias / api / service / configurations / Language.js View on Github external
const url = require('url');

const _ = require('lodash');

const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;

class Language extends ServiceConfiguration {
  constructor(o) {
    super('language', o);
  }

  getParameters(req, res) {
    // find all the values for all keys with names that end with '_id'
    const ids = _.get(res, 'data', []).reduce((acc, doc) => {
      Array.prototype.push.apply(acc, _.values(_.pickBy(doc.parent, (v, k) => _.endsWith(k, '_id') ) ) );
      return acc;
    }, []);
    const lang = _.get(req, 'clean.lang.iso6393');
    const parameters = {
      // arrays will be nested, so flatten first, then uniqify, and finally join elements with comma
      ids: _.uniq(_.flattenDeep(ids)).join(',')
github pelias / api / service / configurations / Libpostal.js View on Github external
'use strict';

const url = require('url');

const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;

class Libpostal extends ServiceConfiguration {
  constructor(o, propertyExtractor) {
    super('libpostal', o);

    // save off the propertyExtractor function
    // this is used to extract a single property from req.  eg:
    // * _.property('clean.text')
    // * _.property('clean.parsed_text.address')
    // will return those properties from req
    this.propertyExtractor = propertyExtractor;
    
  }

  getParameters(req) {
    return {
github pelias / api / service / configurations / PointInPolygon.js View on Github external
'use strict';

const url = require('url');

const _ = require('lodash');

const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;

class PointInPolygon extends ServiceConfiguration {
  constructor(o) {
    super('pip', o);
  }

  getParameters(req) {
    if (_.has(req, 'clean.layers')) {
      return {
        layers: _.join(req.clean.layers, ',')
      };
    }

    return {};
  }
github pelias / api / service / configurations / Interpolation.js View on Github external
const url = require('url');
const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('interpolation:request');

const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;

class Interpolation extends ServiceConfiguration {
  constructor(o) {
    super('interpolation', o);
  }

  getParameters(req, hit) {
    let params = {
      number: req.clean.parsed_text.number,
      street: hit.address_parts.street || req.clean.parsed_text.street,
      lat: hit.center_point.lat,
      lon: hit.center_point.lon
    };

    debugLog.push(req, params);

pelias-microservice-wrapper

Module that provides a convenience wrapper around HTTP GET microservices

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis