0.2.6 • Published 7 years ago

structure-embed v0.2.6

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
7 years ago

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)