@amedia/gaia-client

7.1.2 • Public • Published

Gaia Node Client

A node.js client for the Gaia REST service.

The methods in this client retrieve data from the endpoints in the Gaia REST service. Iow; one do need access to a running Gaia REST service.

Installation

$ npm install @amedia/gaia-client --save

Basic usage

Example on getting the property aid.use Object for www.ba.no:

const { GaiaClient } = require('gaia-client');

// use the HeaderManager from your app

const gaiaClient = new GaiaClient('http://varnish-local.api.no/gaia', {
  headerManager,
});

gaiaClient
  .getProperty('www.ba.no', 'aid.use')
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

Take a look at bin/example.js for a simple script which uses all the methods of gaiaClient.

Constructor

This constructs a new client:

const gaiaClient = new GaiaClient(urlRoot, { headerManager });

The constructor take the following parameters:

  • urlRoot is the url to the Gaia server you want to use. This should be the hostname to the server without any paths. This parameter is required.
  • options - config object. All options are optional
  • options.headerManager is the HeaderManager from your app. Default null.
  • options.timeout Default 2000ms
  • options.agent is the http.Agent for the fetchOptions for gaia backend. Default undefined
  • options.keepAlive Keep alivie on the request. Default false.

API

All methods returns a promise which resolve to an object.

If an error happens, either if the endpoint returns something else than 200 or the endpoint is not accessible, the Promise will be rejected with an error describing why.

The client has the following methods:

.getProperty(publicationDomain, propertyName) -> Promise

Retrieves the property with the given name from the publication with the given domain.

Example

gaiaClient
  .getProperty('www.tangotidende.no', 'shall.esi.be.used')
  .then((result) => console.log(result['shall.esi.be.used']))
  .catch((err) => console.error(err));

.getProperties(publicationDomain, propertyNames) -> Promise

propertyNames is a list of names.

Retrieves the properties with the given names from the publication with the given domain. Returns a list of properties.

Example

gaiaClient
  .getProperties('www.tangotidende.no', [
    'arena.design.version',
    'custom.css.url.large',
  ])
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

.getGlobalProperty(propertyName) -> Promise

Retrieves the global property with the given name.

Example

gaiaClient
  .getGlobalProperty('castor.arena.version')
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

.getFooter(publication) -> Promise

Retrieves the footer for the publication.

Example

gaiaClient
  .getFooter('www.ba.no')
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

.getMenu(publication) -> Promise

Retrieves the menu for the publication.

Example

gaiaClient
  .getMenu('www.ba.no')
  .then((result) => console.log(result))
  .catch((err) => console.error(err));

Tests

$ npm test

Tests are written in Mocha.

Breaking changes version 4

Promise not Bluebird

The promise returned is no longer a Bluebird Promise. This means catch is no longer a filtered catch and the Promise does not support the spread method

Removed site config methods

We have a dedicated site-config module

  • getAllPublications
  • getPublicationById
  • getPublicationByDomain
  • getSiteconfig

New property result format

All property methods return a key value map, not dictionary.

  {
      'aid.use': 'true'
  }

not

[
  {
    value: 'true',
    medusa: false,
    overridable: false,
    name: 'aid.use',
  },
];

New result format for menu

We have switched to the new v3 version of gaia API. The data structure for menu is changed.

Readme

Keywords

none

Package Sidebar

Install

npm i @amedia/gaia-client

Weekly Downloads

270

Version

7.1.2

License

none

Unpacked Size

91.3 kB

Total Files

24

Last publish

Collaborators

  • henrikgs
  • ojbrun
  • olavm
  • teodorlu
  • martin.midtsund
  • duvholt.amedia
  • simenf05
  • natalie.lien
  • oleny
  • mortenlocka
  • jarandu
  • sylvihb
  • eivl
  • varl
  • baardr
  • eirik-haukeland
  • robinfiske87
  • kathte
  • sigurdb
  • carlef-amedia
  • celinevictoria
  • kjersty
  • mathsterk
  • veggiss
  • magnusrr
  • matsjsk-amedia
  • simonamedia
  • altheaase
  • johanhaugland
  • akselnordal
  • rathienth
  • amediocredad
  • zahsaf17
  • elisabethirg
  • johnche
  • amandakj
  • jibblol
  • simengj
  • oleberdal-amedia
  • fliropp
  • helgevalvik
  • amediautvikling
  • jorgenwahlberg
  • torbs
  • duveit
  • renatewr
  • equivocal
  • mariann
  • hennikul
  • karinaas
  • fredrik.danielsen
  • kjetilhoiby
  • fjellman
  • steinkvarud
  • annadahl
  • mfolkeseth
  • larskl
  • emilhauk
  • chrispz
  • pergu
  • tingstad
  • bjorngjorven
  • reidarsollid
  • rahilhussain
  • susanne.moseby
  • tommygi
  • thomas.orten
  • peder-forfang
  • rasmusamedia