1.0.0 • Published 4 years ago

mm-integration v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

mm-integration

A wrapper around Schibsted's Multimedia integrations for use in the browser and on the server.

const Integration = require('mm-integration')
Integration.defaults.auth = {
  username: process.env['MM_API_PROD_USERNAME'],
  password: process.env['MM_API_PROD_PASSWORD'],
}

// Creating an integration
const myIntegration = new Integration('<p>Hello world!</p>')
await myIntegration.save()
console.log('Integration created at', myIntegration.url)

// Updating an integration
myIntegration.title = 'Hello world!'
await myIntegration.save()
console.log('Integration updated')

// Deleting an integration
await myIntegration.delete()
console.log('Integration deleted')

Integration

Kind: global class

new Integration(opts)

Create an instance representing an MM integration

ParamTypeDefaultDescription
optsString | ObjectCan be a string representing the integration's html body or an object of options
opts.idStringThe server-side id of the integration
opts.urlStringThe URL from which the CMS will fetch the integration. If you want to programmatically update an existing integration, you will need to provide both the id and the url. This is unexpected and not ideal, but unfortunately the Content API provides no way to access the URL of an integration, given its ID.
opts.htmlString''The HTML body of the integration.
opts.authorString''Author name to be associated with the integration.
opts.titleString''Title to be associated with the integration.
opts.baseString'https://enrichment.api.plan3.se/proxy/content/v3/publication/bt/multimedias'The base URL of the API, without a trailing slash.
opts.authString{username: '', password: ''}An object with your credentials for the multimedia API, containing username and password properties. All options can also be set and changed by setting the instance properties.

integration.save() ⇒ Promise

Saves the integration to the server, either creating a new one or updating an existing one as appropriate

Kind: instance method of Integration Returns: Promise - A promise as returned by fetch()

integration.delete() ⇒ Promise

Requests the server to delete an existing integration

Kind: instance method of Integration Returns: Promise - A promise as returned by fetch()

Integration.defaults

You can globally set the defaults for all new Integrations by modifying the Integration.defaults static object. This can contain the same options as the opts object you can pass into new Integration(opts).

Note that while you can globally set the id or url properties, this is almost certainly a bad idea.

To get a fresh objects with the "default defaults", you can call Integration.getDefaults().

Kind: static property of Integration Example

// Reset the global defaults:
Integration.defaults = Integration.getDefaults()