Beispiel #1
0
var Client = function(options) {
  options = extend(true, {}, DEFAULT_CLIENT_OPTIONS, options || {});
  this._baseURL = options.baseURL;
  this._restURL = join(this._baseURL, options.restPath, '/');
  this._automationURL = join(this._baseURL, options.automationPath, '/');
  this._username = options.username;
  this._password = options.password;
  this._repositoryName = options.repositoryName || 'default';
  this._schemas = options.schemas || [];
  this._headers = options.headers || {};
  this._timeout = options.timeout;
  this.connected = false;

  var self = this;
  var RestService = rest.service(function() {
    this.defaults.username = self._username;
    this.defaults.password = self._password;
  }, {
    baseURL: self._restURL
  });
  this._restService = new RestService();

  var AutomationService = rest.service(function() {
    this.defaults.username = self._username;
    this.defaults.password = self._password;
  }, {
    baseURL: self._automationURL
  });
  this._automationService = new AutomationService();
};
var rest = require('restler');

Alerts = rest.service(function(u, p, baseOverride) {
  this.defaults.username = u;
  this.defaults.password = p;
  if (baseOverride) {
    this.baseURL = baseOverride;
  }
}, {
  baseURL: 'http://localhost:8080'
}, {
  getByAmo: function(amo) {
    return this.get('/alerts/' + amo, {});
  },
  getAll: function() {
    return this.get('/alerts', {});
  },
  getSingle: function(amo, alertName) {
    return this.get('/alerts/' + amo + '/' + alertName, {});
  }
});

Beispiel #3
0
var Tasks = exports.Tasks = togglCollection(Task);
var Tag = exports.Tag = togglModel('tag');
var Tags = exports.Tags = togglCollection(Tag);
var User = exports.User = togglModel('user');
var Users = exports.Users = togglCollection(User);
var Workspace = exports.Workspace = togglModel('workspace');
var Workspaces = exports.Workspaces = togglCollection(Workspace);
var TimeEntry = exports.TimeEntry = togglModel('time_entry', 'time_entries');
var TimeEntries = exports.TimeEntries = togglCollection(TimeEntry);

var Toggl = rest.service(
function (api_key) {
  this.api_key = api_key;
  this.defaults = {
    username: api_key,
    password: "******"
  };
}, {
  baseURL: 'https://www.toggl.com'
},
  {});
exports.Toggl = Toggl;

var toggl;

var methodMap = {
  'create': 'POST',
  'update': 'PUT',
  'delete': 'DELETE',
  'read':   'GET'
};
var rest = require('restler'),
 xml2json = require('xml2json');

var config = require('../config');

Mingle = rest.service(function(u, p) {
  this.defaults.username = u;
  this.defaults.password = p;
}, {
  baseURL: config.url
}, {
  show: function(id) {
    return this.get('/api/v2/projects/'+ config.projectName +'/cards/' + id + ".xml");
  }
});

var client = new Mingle(config.username, config.password);

exports.results = function(req, res){
  var cardNumber = req.body.card_number;
  client.show(cardNumber).on('complete', function(cardDetails) {
    if(cardDetails == undefined){
      res.render("Oops could not find your card");
      return true;
    }
    if(cardDetails.card){
      var title = cardDetails.card.name[0];
      var description = cardDetails.card.description[0].trim();

      res.render('search', { title: title + "( #" + cardNumber + " )", description: description, card_number: cardNumber });
    }
Beispiel #5
0
  username: '******',
  password: '******',
  data: {
    'sound[message]': 'hello from restler!',
    'sound[file]': rest.file('doug-e-fresh_the-show.mp3', null, 321567, null, 'audio/mpeg')
  }
}).on('complete', function(data) {
  sys.puts(data.audio_url);
});

// create a service constructor for very easy API wrappers a la HTTParty...
Twitter = rest.service(function(u, p) {
  this.defaults.username = u;
  this.defaults.password = p;
}, {
  baseURL: 'http://twitter.com'
}, {
  update: function(message) {
    return this.post('/statuses/update.json', { data: { status: message } });
  }
});

var client = new Twitter('danwrong', 'password');
client.update('Tweeting using a Restler service thingy').on('complete', function(data) {
  sys.p(data);
});

// post JSON
var jsonData = { id: 334 };
rest.postJson('http://example.com/action', jsonData).on('complete', function(data, response) {
  // handle response
});
var req1 = restler.get('http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true');
req1.on('complete', processResponse.bind(null, '1'));


var req2 = restler.request('http://maps.googleapis.com/maps/api/geocode/json',
    {
        method: 'GET',
        query: {
            latlng: '40.714224,-73.961452',
            sensor: true
        }
    }
);

req2.on('complete', processResponse.bind(null, '2'));

var GeoService = restler.service(function (sensor) {
    // this.defaults.query = {sensor: sensor ? true : false};
}, {
    baseURL: 'http://maps.googleapis.com/maps/api/geocode/'
}, {
    getAddress: function (latlng, cb) {
        return this.get('json', {query: {sensor: true, latlng: latlng}}).on('complete', cb);
    }
});


var geoService = new GeoService(false);
// geoService.getAddress('40.714224,-73.961452');
geoService.getAddress('40.714224,-73.961452', processResponse.bind(null, '3'));
Beispiel #7
0
var rest = require('restler');
/*
 * GET home page.
 */

Trello = rest.service(function() {
  this.key = process.env.TRELLO_API_KEY;
  this.token = process.env.TRELLO_API_TOKEN;
}, {
  baseURL: process.env.TRELLO_API_URL
}, {
  cards: function(list_id) {
    return this.get('lists/'+list_id+'/cards', {query: {key: this.key, token: this.token}});
  }
});

var client = new Trello();

function getReviewCards(req, res) {
  req.accepts('json, text');
  res.type('json');
  switch(req.params.product) {
    case 'dialog':
      client.cards(process.env.DIALOG_REVIEW_LIST_ID).on('complete', function(data) {
        res.send(data);
      });
      break;
    case 'cdm':
      client.cards(process.env.CDM_REVIEW_LIST_ID).on('complete', function(data) {
        res.send(data);
      });
Beispiel #8
0
var rest = require('restler');

var Stormz = rest.service(function(access_token) {
    this.defaults.headers = {
        authorization: 'Bearer '+ access_token
    };
}, {
  baseURL: 'https://api.stormz.me'
});

module.exports = Stormz;
Beispiel #9
0
var rest = require('restler');

var Steam = rest.service(function(apikey) {
  this.apikey = apikey;
}, {
  baseURL: 'https://api.steampowered.com'
});

Steam.prototype.resolveVanityURL = function(vanity_url) {
  var opts = {
    query: {
      key: this.apikey,
      vanityurl: vanity_url
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
  return this.get('/ISteamUser/ResolveVanityURL/v0001/', opts );
};

Steam.prototype.playerSummary = function(user_id) {
  var opts = {
    query: {
      key: this.apikey,
      steamids: user_id
    },
    headers: {
      'Content-Type': 'application/json'
    }
  };
Beispiel #10
0
var restler         = require('restler'),
    config          = require('config'),
    utils           = require('../utils');


// create a simple accessor for getting at the api

module.exports = restler.service(
  function( slug, version ) {
    this.slug        = slug;
    this.api_version = version;
    this.baseURL     = utils.instance_base_url_from_slug( this.slug ) + '/api/' + this.api_version + '/';

    // these match the user created in the fixture
    this.defaults.username = '******';
    this.defaults.password = '******';
  },
  {  }
);
Beispiel #11
0
    }

    this.initXmpp(config.xmpp);
    this.initHandlers(config.handlersDirectory);
    this.initChatHandler();

    this.passwordServerConfig = config.passwordServer;
    this.passwordsFileName = 'passwords';
    this.readPasswordsFromFile();
    this.initPasswordServer();
};

jiraBotOpts.defaults = {};


var JiraBot = rest.service(jiraBotOpts.constructorFn, jiraBotOpts.defaults);


JiraBot.prototype.encrypt = function (message) {
    var cipher = crypto.createCipher('aes-256-cbc', this.masterPassword);
    cipher.update(message, 'utf8', 'hex');
    return cipher.final('hex');
};


JiraBot.prototype.decrypt = function(message) {
    var decipher = crypto.createDecipher('aes-256-cbc', this.masterPassword);
    decipher.update(message, 'hex', 'utf8');
    return decipher.final('utf8');
};
Beispiel #12
0
module.exports = Harvest = function(opts) {
    var self = this;

    if (typeof opts.subdomain === "undefined")
        throw new Error('The Harvest API client requires a subdomain');

    this.use_oauth = (typeof opts.identifier !== "undefined" &&
                      typeof opts.secret !== "undefined");
    this.use_basic_auth = (typeof opts.email !== "undefined" &&
                           typeof opts.password !== "undefined");

    if (!this.use_oauth && !this.use_basic_auth)
        throw new Error('The Harvest API client requires credentials for basic authentication or an identifier and secret for OAuth');

    this.subdomain = opts.subdomain;
    this.host = "https://" + this.subdomain + ".harvestapp.com";
    this.email = opts.email;
    this.password = opts.password;
    this.identifier = opts.identifier;
    this.secret = opts.secret;
    this.user_agent = opts.user_agent;

    var restService = restler.service(function(u, p) {
        this.defaults.username = u;
        this.defaults.password = p;
    }, {
        baseURL: self.host
    }, {

        run: function(type, url, data) {
	    console.log('run', type, url, data);
            var opts = {};
            opts.headers = {
                'Content-Type': 'application/xml',
                'Accept': 'application/xml'
            };

            if (typeof data !== 'undefined') {
                if (typeof data === 'object') {
                    opts.headers['Content-Length'] = querystring.stringify(data).length;
                } else {
                    opts.headers['Content-Length'] = data.length;
                }
            } else {
                opts.headers['Content-Length'] = 0;
            }

            opts.data = data;
            switch(type) {
            case 'get':
                return this.get(url, opts);
                break;

            case 'post':
                return this.post(url, opts);
                break;

            case 'put':
                return this.put(url, opts);
                break;

            case 'delete':
                return this.del(url, opts);
                break;
            }
            return this;
        }
    });

    this.processRequest = function(res, cb) {
	//console.log('processRequest', cb);

	if (typeof cb !== "function") throw new Error('processRequest: Callback is not defined');

        res.addListener('success', function(data, res) {

            //console.log('success', util.inspect(data, false, 10));

            // TODO Xml sucks and the JSON it generates is horrendous
            // this default response could be greatly simplified for all requests
            cb(null, data);

        }).addListener('error', cb);
    };

    this.service = new restService(this.email, this.password);

    this.client = {
        get: function(url, data, cb) {
            self.processRequest(self.service.run('get', url, data), cb);
        },
        patch: function(url, data, cb) {
            self.processRequest(self.service.run('patch', url, data), cb);
        },
        post: function(url, data, cb) {
            self.processRequest(self.service.run('post', url, data), cb);
        },
        put: function(url, data, cb) {
            self.processRequest(self.service.run('put', url, data), cb);
        },
        delete: function(url, data, cb) {
            self.processRequest(self.service.run('delete', url, data), cb);
        }
    };

    var TimeTracking = require('./lib/time-tracking');
    var Clients = require('./lib/clients');
    var ClientContacts = require('./lib/client-contacts');
    var Projects = require('./lib/projects');
    var Tasks = require('./lib/tasks');
    var People = require('./lib/people');
    var ExpenseCategories = require('./lib/expense-categories');
    var Expenses = require('./lib/expenses');
    var UserAssignment = require('./lib/user-assignment');
    var TaskAssignment = require('./lib/task-assignment');
    var Reports = require('./lib/reports');
    var Invoices = require('./lib/invoices');
    var InvoiceMessages = require('./lib/invoice-messages');
    var InvoicePayments = require('./lib/invoice-payments');
    var InvoiceCategories = require('./lib/invoice-categories');

    this.TimeTracking = new TimeTracking(this);
    this.Clients = new Clients(this);
    this.ClientContacts = new ClientContacts(this);
    this.Projects = new Projects(this);
    this.Tasks = new Tasks(this);
    this.People = new People(this);
    this.ExpenseCategories = new ExpenseCategories(this);
    this.Expenses = new Expenses(this);
    this.UserAssignment = new UserAssignment(this);
    this.TaskAssignment = new TaskAssignment(this);
    this.Reports = new Reports(this);
    this.Invoices = new Invoices(this);
    this.InvoiceMessages = new InvoiceMessages(this);
    this.InvoicePayments = new InvoicePayments(this);
    this.InvoiceCategories = new InvoiceCategories(this);

    return this;

};