Giter Club home page Giter Club logo

node-ifttt's Introduction

ifttt

IFTTT

Enables you to build IFTTT compatible node endpoints with express.

Features

Planned

Install

Install the module via npm:

$ npm install --save ifttt

Usage

// Require the module in your code.
var Ifttt = require('ifttt');

// Create new IFTTT channel.
var iftttChannel = new Ifttt();

// Add triggers & actions to your IFTTT channel.
iftttChannel.registerTrigger(YOUR_TRIGGER);
iftttChannel.registerAction(YOUR_ACTION);

// Add IFTTT channel routes to your express app.
iftttChannel.addExpressRoutes(app);

Examples

Create trigger

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example trigger.
function ExampleTrigger() {
  ExampleTrigger.super_.call(this, 'example');
}
util.inherits(ExampleTrigger, Ifttt.Trigger);

// Overwrite `_getResponseData` with your response handler.
ExampleTrigger.prototype._getResponseData = function(req, requestPayload, cb){
  var results = [];

  results.push({
    field1: 'value1',
    created_at: new Date().toISOString(),
    meta: {
      id: 'id1',
      timestamp: new Date.now()
    }
  });

  return cb(null, results);
};

module.exports = ExampleTrigger;

Create action

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example action.
function ExampleAction() {
  ExampleAction.super_.call(this, 'example');
}
util.inherits(ExampleAction, Ifttt.Action);

// Overwrite `_getResponseData` with your response handler.
ExampleAction.prototype._getResponseData = function(req, requestPayload, cb){
  var results = [];

  results.push({
    id: 'id1'
  });

  return cb(null, results);
};

module.exports = ExampleAction;

Create trigger field

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example field.
function ExampleField() {
  ExampleField.super_.call(this, 'example');

  // Set sample data so IFTTT can properly test this field.
  this.setOptionsSampleData('valid_option_value', 'invalid_option_value');
}
util.inherits(ExampleField, Ifttt.Trigger.TriggerField);

// Overwrite `_getOptionsData` to return field options.
ExampleField.prototype._getOptionsData = function(req, response, cb){
  var option = new response.OptionEntity();
  option.setLabel('Valid option 1');
  option.setValue('valid_option_value');
  response.addOption(option);

  var option = new response.OptionEntity();
  option.setLabel('Valid option 2');
  option.setValue('valid_option_value2');
  response.addOption(option);

  return cb(null);
};

// Overwrite `_getValidateData` to check if value is valid.
ExampleField.prototype._getValidateData = function(req, response, payload, cb){
  var value = payload.getValue();

  if (value === 'valid_option_value') {
    response.setValid(true);
    return cb(null);
  }
  else if (value === 'invalid_option_value') {
    response.setValid(false);
    return cb(null);
  }
};

module.exports = ExampleField;

node-ifttt's People

Contributors

bkonetzny avatar

Watchers

joe beuckman avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.