Skip to content

Commit

Permalink
added page format classes
Browse files Browse the repository at this point in the history
  • Loading branch information
schaechinger committed Mar 19, 2018
1 parent 46ee8cb commit c11bf42
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ before_install:
- npm i -g yarn@latest
script:
- yarn run cover
after_script:
after_success:
- yarn run coveralls
deploy:
provider: npm
email: $NPM_EMAIL
api_key: $NPM_TOKEN
on:
tags: true
branch: master
9 changes: 9 additions & 0 deletions lib/Internetmarke.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ class Internetmarke {
});
}

/**
* Retrieves the list of available page formats used for pdf vouchers.
*
* @returns {Promise.<PageFormat[]>}
*/
getPageFormats() {
return this._1C4AService.retrievePageFormats();
}

/**
* Update galleries (public and private) and save results locally.
*
Expand Down
23 changes: 23 additions & 0 deletions lib/PageFormat/PageFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* internetmarke
* Copyright (c) 2018 Manuel Schächinger
* MIT Lisenced
*/

'use strict';

const Cachable = require('../helper/Cachable');

class PageFormat extends Cachable {
/**
* Defines a page format with the metadata and the id used in the api.
*
* @constructor
* @param {Obect} data
*/
constructor(data) {
super({ prefix: 'PAGE_FORMAT', id: data.id, data });
}
}

module.exports = PageFormat;
54 changes: 54 additions & 0 deletions lib/PageFormat/PageFormatList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* internetmarke
* Copyright (c) 2018 Manuel Schächinger
* MIT Lisenced
*/

'use strict';

const NodeCache = require('node-cache');

const PageFormat = require('./PageFormat'),
OneClickForAppService = require('../Service/Soap/OneClickForApp');

class PageFormatList {
constructor() {
/** @type {NodeCache} */
this._nodeCache = new NodeCache({ stdTTL: 3600 * 24 });

this._pageFormats = {};
}

/**
* Loads the list of available page formats if not cached.
*
* @param {OneClickForAppService} oneClickForAppService - The 1C4A service to
* load the latest list of page formats if necessary.
* @returns {Promise.<Object>}
*/
loadList(oneClickForAppService) {
let promise = null;

console.log(this._nodeCache.getStats());

if (!this._nodeCache.getStats().keys) {
promise = oneClickForAppService.retrievePageFormats()
.then(pages => {
page.pageFormat.forEach(data => {
const pageFormat = new PageFormat(data);
pagFormat.save();
this._pageFormats[pageFormat.getId] = pageFormat;
});

return this._pageFormats;
});
}
else {
promise = Promise.resolve(this._pageFormats);
}

return promise;
}
}

module.exports = PageFormatList;
9 changes: 9 additions & 0 deletions lib/PageFormat/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* internetmarke
* Copyright (c) 2018 Manuel Schächinger
* MIT Licensed
*/

'use strict';

module.exports = require('./PageFormatList');
10 changes: 10 additions & 0 deletions lib/Service/Soap/OneClickForApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ class OneClickForAppService extends SoapService {
});
}

retrievePageFormats() {
return this._getSoapClient()
.then(client => {
return client.retrievePageFormatsAsync();
})
/*.then(pages => {
pages.pageFormat.forEach()
})*/;
}

/**
* Initialize the soap client with the partner information headers.
*
Expand Down
46 changes: 46 additions & 0 deletions lib/helper/Cachable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* internetmarke
* Copyright (c) 2018 Manuel Schächinger
* MIT Lisenced
*/

'use strict';

const NodeCache = require('node-cache');

class Cachable {
/**
* Defines an abstract instanse of a cachable entity.
*
* @constructor
* @param {Object} config
* @param {string} config.prefix
* @param {*} config.id
* @param {Object} config.data
*/
constructor({ prefix, id, data }) {
/** @type {string} */
this._prefix = prefix;
/** @type {*} */
this._id = id;

if (data.id) {
delete data.id;
}
/** @type {Object} */
this._data = data;

/** @type {NodeCache} */
this._cache = new NodeCache({ stdTTL: 86400 });
}

save() {
this._cache.set(this.getId(), this._data);
}

getId() {
return `${this._prefix}_${this._id}`;
}
}

module.exports = Cachable;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"md5": "^2.2.1",
"moment": "^2.20.1",
"moment-timezone": "^0.5.14",
"node-cache": "4.1.1",
"pino": "^4.11.0",
"soap": "^0.23.0"
},
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ cliui@^2.1.0:
right-align "^0.1.1"
wordwrap "0.0.2"

clone@2.x:
version "2.1.1"
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.1.tgz#d217d1e961118e3ac9a4b8bba3285553bf647cdb"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down Expand Up @@ -650,6 +654,10 @@ lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

lodash@4.x:
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"

lodash@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
Expand Down Expand Up @@ -759,6 +767,13 @@ nise@^1.2.0:
path-to-regexp "^1.7.0"
text-encoding "^0.6.4"

node-cache@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-4.1.1.tgz#08524645ee4039dedc3dcc1dd7c6b979e0619e44"
dependencies:
clone "2.x"
lodash "4.x"

nopt@3.x:
version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
Expand Down

0 comments on commit c11bf42

Please sign in to comment.