structure-embed

0.2.6 • Public • Published

structure-embed

Abstract class for creating embed hooks. Create an implementation of this class and register the hook method of your instance with the dispatcher.

Example implementation

import {registerHook} from 'structure-dispatcher'
import Embed from 'structure-embed'

class ExampleEmbed extends Embed {

  async processDigitalAsset(urlParts, digitalAsset) {

    if(/\bexample\.com/.test(urlParts.hostname)) {

      const embedUrl = `https://www.example.com/oembed?url=${urlParts.href}&format=json`

      const embed = await this.fetchEmbed(embedUrl)

      embed.mimetype = 'example/type'

      return embed

    }
  }
}

const exampleEmbed = new ExampleEmbed()

registerHook({
  when: 'after',
  serviceName: 'digital-assets',
  actionNames: ['getByUrl'],
}, exampleEmbed.hook)

Readme

Keywords

Package Sidebar

Install

npm i structure-embed

Weekly Downloads

0

Version

0.2.6

License

Apache-2.0

Unpacked Size

34.6 kB

Total Files

16

Last publish

Collaborators

  • mparkerdfy
  • johnomarkid
  • tom-james-watson
  • chrisabrams