npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sensu/embedly

v3.0.2

Published

Embedly client library for node

Downloads

6

Readme

@sensu/embedly

An up to date version of the Embedly node client library. To find out what Embedly is all about, please visit http://embed.ly.

Getting Started

Here are some examples hint replace xxxxxxxxxxx with real key::

  var EMBEDLY_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx';

  var embedly = require('embedly'),
      util = require('util');

  var api = new embedly({key: EMBEDLY_KEY});
  // call single url
  var url = 'http://www.youtube.com/watch?v=Zk7dDekYej0';
  api.oembed({url: url}, function(err, objs) {
    if (!!err) {
      console.error('request #1 failed');
      console.error(err.stack, objs);
      return;
    }
    console.log('---------------------------------------------------------');
    console.log('1. ');
    console.log(util.inspect(objs[0]));
  });

  // call multiple urls with parameters
  var urls = ['http://www.youtube.com/watch?v=Zk7dDekYej0',
              'http://plixi.com/p/16044847'],
      opts = { urls: urls,
               maxWidth: 450,
               wmode: 'transparent',
               method: 'after' };

  api.oembed(opts, function(err, objs) {
      if (!!err) {
        console.error('request #2 failed');
        console.error(err.stack, objs);
        return;
      }
      console.log('-------------------------------------------------------');
      console.log('2. ');
      console.log(util.inspect(objs));
  });

  var api = new embedly({key: EMBEDLY_KEY});
  var url = ('http://www.guardian.co.uk/media/2011/jan' +
             '/21/andy-coulson-phone-hacking-statement');
  api.preview({url: url}, function(err, objs) {
    if (!!err) {
      console.error('request #2 failed');
      console.error(err.stack, objs);
      return;
    }
    console.log('---------------------------------------------------------');
    console.log('3. ');
    console.log(util.inspect(objs[0]));
  });

Authentication

If a key is not specified, the EMBEDLY_KEY environmental variable will be used. You can signup for an Embedly key at http://embed.ly. Support for oauth will be added in a future version of the library.

Creating an api object

The embedly exported prototype function takes an Object of optional parameters to configure the Embedly API.

 **key** _String_ Embedly consumer key

 **secure** _Boolean_ Enables ssl, defaults to true.

 **logger** _Object_ An object that has debug, warn and error functions that
            except a single _String_ parameter. The `log` module is used by
            default.

 **servicesRegexp** __RegExp__ A regular expression to match URLs against
                    before sending them to the Embedly API.

There is a second, callback parameter that passes back an error and api parameter. It is possible in certain circumstances that the embedly api will fail to initialize properly. Therefore it is recommended to use the callback function and check for errors, like the example code above.

Endpoints

Embedly api endpoints are implemented as prototype functions on the api object. There are two endpoints implemented. See the Embedly API documentation for more details on the uses of the endpoints.

  • oembed
  • extract

The endpoint functions accept an Object or parameters that are, for the most part, passed directly to the api as query parameters. The api does it's best to canonize the parameters before sending them. Sending more than 20 URLs at a time will fail. Future version of this library will batch requests of more than 20 URLs into batches whose size will be configurable.

Logging

@sensu/embedly does provide some minimal logging to help diagnose problems. By default, a winston console logger with log level error will be created, but only if winston is installed. If you'd like more control over logging, you can create your own logger and pass it into embedly on instantiation. ex:

  var embedly = require('embedly'),
      winston = require('winston'),
      logger = new (winston.Logger)({
          transports: [new (winston.transports.Console)({ level: 'info' })]
      });

  new embedly({logger: logger}, function(err, api) {
    // do stuff with api
  });

Testing

We have provided some commandline tools to test the Embedly interface.

  • embedly_oembed.js
  • embedly_extract.js

Using --help with the commands should give you a good idea of how to use them.

Develop

Run tests:

  npm test

Some tests will fail due to missing api key. Set the EMBEDLY_KEY environmental variable with your key to get them to pass::

  EMBEDLY_KEY=xxxxxxxxxxxxx npm test

Copyright

Copyright (c) 2011 Embed.ly, Inc. See LICENSE for details.