mm-integration
v1.0.0
Published
Wrapper around Schibsted multimedia integrations
Downloads
152
Readme
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
- Integration
- new Integration([opts])
- instance
- static
new Integration([opts])
Create an instance representing an MM integration
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [opts] | String | Object | | Can be a string representing the integration's html body or an object of options |
| [opts.id] | String | | The server-side id of the integration |
| [opts.url] | String | | The 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.html] | String | '' | The HTML body of the integration. |
| [opts.author] | String | '' | Author name to be associated with the integration. |
| [opts.title] | String | '' | Title to be associated with the integration. |
| [opts.base] | String | 'https://enrichment.api.plan3.se/proxy/content/v3/publication/bt/multimedias' | The base URL of the API, without a trailing slash. |
| [opts.auth] | String | {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 Integration
s 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()