Coder Social home page Coder Social logo

coffee-protocol's Introduction

Coffee-Protocol

An implementation of RFC 2325 to help with the implementation of an HTCPCP compliant server.

Installation

Use npm install coffee-protocol, or clone the repository into your preferred location.

Usage

Objects are defined in accordance with section 4 of the RFC and can be used as follows:

var coffeeProtocol = require('./index'),
    q = require('q');

var pot = new coffeeProtocol.Pot({
  potName: 'Office French Press',
  potType: coffeeProtocol.potTypes['french-press'],
  potCapacity: 2,
  potLocation: 'The kitchen'
});

var PotAdapter = coffeeProtocol.PotAdapter.extend({
  getTemperature: function(){
    var defer = q.defer();
    // Communicate to your coffee pot.
    defer.resolve(100);
    return defer.promise;
  },
  getStatus: function(){
    var defer = q.defer();
    // Communicate to your coffee pot.
    defer.resolve(coffeeProtocol.potMonitorStatuses.waiting);
    return defer.promise;
  },
  getStartTime: function(){
    var defer = q.defer();
    // Communicate to your coffee pot.
    defer.resolve(Date.now());
    return defer.promise;
  },
});

var potAdapter = new PotAdapter();

var potMonitor = new coffeeProtocol.PotMonitor(potAdapter, {
  potLevel: 0,
  potMetric: coffeeProtocol.potMonitorMetrics.mug
});

var date = new Date();
var startTime = new Date(date.getTime() + (30 * 60 * 1000));

pot.setPotLocation('The desk of Jack Lawson');
potMonitor.setPotStartTime(startTime.getTime() / 1000);

// potMonitor `get`s are promises in case we have to do an async request
// to get coffee pot status through potAdapter.
potMonitor.get('potStartTime').then(function(time){
  console.log(
    pot.get('potName') + " will start at time " + potMonitor.get('potStartTime') +
    " at location " + pot.get('potLocation')
  )
}, function(){
  console.log(arguments);
});

coffee-protocol's People

Contributors

ajacksified avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.