Skip to content

Creating a Tower Service

Lance Pollard edited this page Oct 30, 2012 · 1 revision

The following API should be implemented:

var customService = Tower.CustomService.create({
  key: '',
  secret: '',
  host: '',
  hasManyAssociation: Tower.hasMany('AssociatedWithHasMany'),
  belongsToAssociation: Tower.belongsTo('AssociatedWithBelongsTo')
});

Tower.AssociatedWithHasMany = Tower.Model.extend({
  client: 'Tower.CustomService' // App.customService
});

Tower.AssociatedWithBelongsTo = Tower.Model.extend({
  client: 'Tower.CustomService'
});

Here are some potential examples (none of this is yet implemented):

// `key` and `secret` for the auth credentials
var twilio = Tower.TwilioClient.create({
  key: '',
  secret: ''
});

// get(association).create builds the object
// params are clearly named.
twilio.get('phones').create({phoneNumber: '1-555-555-5555'});
// `key` and `secret` for the auth credentials
var irc = Tower.IrcClient.create({
  host: ''
});

irc.connect(function() {
  irc.on('message', function() {
    
  });
});
var twitter = Tower.TwitterClient.create({
  key: '',
  secret: ''
});

twitter.url('/statuses/filter').where({status: /node\.js/}).stream(function(stream) {
  stream.on('data', function(tweet) {

  });
});
var email = Tower.EmailClient.create({
  service: 'SMTP'
});
var s3 = Tower.S3Client.create({
  
});

// you can have helpers, so something like:
// alias to `s3.get('files').create(file);`
s3.upload(file);
var google = Tower.GoogleDataClient.create();

google.get('spreadsheets').where({title: /sandy/}).first(function(error, spreadsheet) {
  // copy relevant tweets to spreadsheet
  spreadsheet.get('rows').create({message: 'RT @...'});
});

Maybe they can be automatically created like this:

App.registerInjection({
  name: 'clients',
  injection: function(app, property) {
    if (!property.match(/Client$/)) return;

    App[property].create({

    });
  }
});
Clone this wiki locally