UNPKG

1.5 kBJavaScriptView Raw
1const bunyan = require('bunyan');
2const { HeaderManager } = require('@amedia/atomizer-header');
3
4const log = bunyan.createLogger({ name: 'gaia client example' });
5
6const { GaiaClient } = require('..');
7
8const headerManager = new HeaderManager({
9 appName: 'testapp',
10 serverName: 'testserver',
11 hostname: 'testhost',
12});
13
14const gaiaClient = new GaiaClient('http://v3local.api.no/gaia', { headerManager });
15
16// This is how a function should be used in code
17
18gaiaClient
19 .getProperty('www.tangotidende.no', 'shall.esi.be.used')
20 .then(result => {
21 // Do something with the property
22 })
23 .catch(err => {
24 // Do error handling.
25 });
26
27// Example usage of all methods
28// WARNING: Heavy promise usage ahead
29
30const promises = [
31 Promise.all(['(1) Get Property', gaiaClient.getProperty('www.tangotidende.no', 'shall.esi.be.used')]),
32 Promise.all([
33 '(2) Get Properties',
34 gaiaClient.getProperties('www.tangotidende.no', ['arena.design.version', 'custom.css.url.large']),
35 ]),
36 Promise.all(['(3) Get Global Property', gaiaClient.getGlobalProperty('castor.arena.version')]),
37 Promise.all(['(4) Get Footer File', gaiaClient.getFooter('www.ba.no')]),
38 Promise.all(['(4) Get Menu File', gaiaClient.getMenu('www.ba.no')]),
39];
40Promise.all(promises)
41 .then(values => {
42 values.forEach(inner => {
43 console.log('\n*****\n');
44 console.log(inner);
45 });
46 })
47 .catch(err => {
48 log.error(err);
49 });