Labrador Utilities
Install
yarn add @aller/labrador-utils
or
npm install @aller/labrador-utils
Modules
Labrador API
Init
const { api } = require('labrador-utils')
const labApi = api({ base: 'http://api.secret.labrador.api.lol', site_id: 1 })
High-level methods
labApi.getArticleById({ id: 9999999, args... })
labApi.getArticlesByTags({ tags:['test', 'bil'], args... })
labApi.getArticlesByTag({ tag: 'test', args... })
labApi.getArticlesBySection({ section: 'mat', args... })
labApi.getFrontPageById({ id: 9999999, args... })
labApi.getFragment({ id: 9999999, args... }, ?clean)
Article-based high level methods also have query-specific options e.g:
labApi.getArticleById({
isFeatured: true,
visibility_status: 'P'
})
Base methods
labApi.getQuery('/front', { query: 'id:999999', args... }).get()
labApi.getFrontPage({ query: 'id:9999999', args... }).getResult()
labApi.getArticles({ query: 'tag:test', args... }).getFrist()
All base methods have 3 request methods
get() -> { result: [ { ENTITY }...] }
getResult() -> [ {ENTITY }... ]
getFirst() -> { ENTITY }
Query builder
The base methods use the queryBuilder for parsing of the query-parameter. The queryBuilder takes nested JS objects/arrays as input and generates a query string as output.
labApi.getArticles({
query: [{ tag: ['nyheter', 'bil'] }, { 'review_score': '*' }],
}).getResult()
labApi.queryBuilder([{ tags: ['hello', { wat: ['test1', ['hello', 'hello2'], 'OR'] }] }])
Concepts:
['nyheter', 'bil']
['nyheter', 'bil', 'OR']
{ tag: ['nyheter', 'bil', 'OR']}
Additional arguments
All additional args. on all methods, are sent as query params, e.g:
labApi.getArticlesByTags({
tags: ['test', 'bil'],
limit: 5,
start: 5,
order: 'desc',
orderBy: 'published'
})
Defaults are found here