Socket
Book a DemoInstallSign in
Socket

ympc-yo

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ympc-yo

Yo API client

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

ympc-yo

A Yo client library to send Yos. It provides a hybrid promise / node-style API.

Examples

var API_KEY = 'this-is-my-api-key-asdf-ghjklmnopqrs';
var Yo = require('ympc-yo');
var yo = new Yo(API_KEY);

// promise
yo.yo('YOSERNAME')
  .then(function (res) {
    console.log('Yo, nice:', res.yo_id);
  })
  .catch(function (err) {
    console.error('Yo, lame:', err);
  });


// node-style
yo.yo('YOSERNAME', function (err, res) {
  if (err) {
    return console.error('Yo, lame:', err);
  }

  console.log('Yo, nice:', res.yo_id);
});

API

yo = new Yo(apiKey)

Create a new instance.

Arguments

  • apiKey (string; required): Your Yo APU key. Can be objained at the Yo dashboard.
var API_KEY = 'this-is-my-api-key-asdf-ghjklmnopqrs';
var Yo = require('ympc-yo');
var yo = new Yo(API_KEY);

promise = yo.yo(username)

Send a regular Yo.

Returns

  • Promise with response body

Arguments

  • username (string; required): A Yo username
yo.yo('YOSERNAME')
  .then(function (res) {
    console.log('sent yo:', res.yo_id);
  });

Send a Yo with a link.

Returns

  • Promise with response body

Arguments

  • username (string; required): A Yo username
  • link (string; required): A URL
yo.yoLink('YOSERNAME', 'http://example.com/')
  .then(function (res) {
    console.log('sent yo:', res.yo_id);
  });

Send a Yo with a link to all subscribers.

Returns

  • Promise with response body

Arguments

  • link (string; required): A URL
yo.yoAll('http://example.com/')
  .then(function (res) {
    console.log('sent yo:', res.yo_id);
  });

promise = yo.getSubscriberCount()

Get the number users who have subscribed to your Yo account.

Returns

  • Promise with number of subscribers
yo.getSubscriberCount()
  .then(function (count) {
    console.log('yo, I have', count, 'subscribers');
  });

Handling Errors

According to the Yo docs

function isErrorCode (code) {
  return function (err) {
    return err.statusCode === code;
  }
}

yo.yo('YOSERNAME')
  .then(function (res) {
    console.log('sent yo:', res.yo_id);
  })
  .catch(isErrorCode(404), function (err) {
    console.error('user does not exist');
  })
  .catch(isErrorCode(429), function (err) {
    console.error('rate limit exceeded');
  })
  .catch(isErrorCode(400), function (err) {
    console.error('bad request');
  })
  .catch(function (err) {
    console.error('something terrible happened', err);
  });

License

MIT

FAQs

Package last updated on 31 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts