🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

itemsapi-node

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itemsapi-node

Node.js client for ItemsAPI

1.0.19
latest
Source
npm
Version published
Maintainers
1
Created
Source

itemsapi-node

Node.js client for ItemsAPI - node.js & elasticsearch search server for web and mobile. For more low level info go to documentation

$ npm install itemsapi-node --save

Init client:

var ItemsAPI = require('itemsapi-node');
var client = new ItemsAPI('http://yourLocalOrHerokuUrl.com/api/v1', 'cities');

Items

Search items

var facets = {
  country:['Canada', 'India']
};

client.search({
  sort: 'most_votes',
  query: '',
  page: 1,
  aggs: facets,
  per_page: 12
}).then(function(res) {
  console.log(res);
  //console.log(JSON.stringify(res, null, 2));
})

Example response:

{ meta: { query: '', sort: 'most_votes', search_time: 20 },
  pagination: { page: '1', per_page: '12', total: 67 },
  data: 
   { items: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     aggregations: { country: [Object], distance_ranges: [Object] },
     sortings: { country: [Object], distance: [Object], city: [Object] } 
  } 
}

Similar items

client.similar('item-id', {
  fields: ['tags']
}).then(function(res) {
  console.log(res);
})

Get item

client.getItem(id)
.then(function(result) {
  console.log(result);
})

Add item

client.addItem(data)
.then(function(result) {
  console.log(result);
})

Delete item

client.deleteItem(id)
.then(function(result) {
  console.log(result);
})

Add items in bulk

client.addBulkItems(cities)
.then(function(res) {
  console.log('added ' + cities.length + 'elements');
})

Collections

Get collection

client.getCollection()
.then(function(result) {
  console.log(result);
})

Example response:

{ 
  name: 'cities',
  type: 'cities',
  index: 'cities',
  meta: { title: 'Cities' },
  defaults: { sort: 'city' },
  schema: { 
    city: { type: 'string', store: true, index: 'not_analyzed' },
    province: { type: 'string', store: true },
    province_icon: { type: 'string', display: 'image' },
    country: { type: 'string', index: 'not_analyzed', store: true },
    country_icon: { type: 'string', display: 'image' },
    geo: { type: 'geo_point' } 
  },
  sortings: { 
    country: { 
      title: 'Country',
      type: 'normal',
      order: 'asc',
      field: 'country' 
    },
    distance: { title: 'Distance', type: 'geo', order: 'asc', field: 'geo' },
    city: { title: 'City', type: 'normal', order: 'asc', field: 'city' } 
  },
  table: {},
  aggregations: { 
    country: { type: 'terms', field: 'country', size: 10, title: 'Country' },
    distance_ranges: { 
      type: 'geo_distance',
      field: 'geo',
      ranges: [Object],
      unit: 'km',
      title: 'Distance ranges [km]' 
    } 
  } 
}

Add collection

client.addCollection(collection)
.then(function(result) {
  console.log(result);
})

Get all collections

client.getCollections()
.then(function(result) {
  console.log(result);
})

Update collection partially

client.partialUpdateCollection({
  index: 'new-index-name',
  type: 'new-type-name',
})
.then(function(result) {
  console.log(result);
})

Keywords

itemsapi

FAQs

Package last updated on 29 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts