Skip to content
Browse files

Full API support and version bump.

  • Loading branch information...
1 parent 2a3e068 commit 07ecd8c1b989246fd4e4d7d6b3dde4520fe253f4 Andrew Kirilenko committed Jul 17, 2012
Showing with 562 additions and 4 deletions.
  1. +129 −1 lib/api_client.js
  2. +180 −1 lib/client.js
  3. +2 −2 package.json
  4. +106 −0 src/api_client.coffee
  5. +145 −0 src/client.coffee
View
130 lib/api_client.js
@@ -24,7 +24,8 @@
scheme: 'https',
host: this.AWS_US_EAST_HOST,
port: 443,
- api_version: 2
+ api_version: 2,
+ user_agent: this.version
};
APIClient.__super__.constructor.call(this, 'iron', 'worker', options, defaultOptions, ['project_id', 'token', 'api_version']);
}
@@ -43,6 +44,62 @@
});
};
+ APIClient.prototype.codesList = function(options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/codes", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.codesGet = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/codes/" + id, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.codesDelete = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this["delete"]("projects/" + this.options.project_id + "/codes/" + id, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb, false);
+ });
+ };
+
+ APIClient.prototype.codesRevisions = function(id, options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/codes/" + id + "/revisions", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.codesDownload = function(id, options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/codes/" + id + "/download", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb, false);
+ });
+ };
+
+ APIClient.prototype.tasksList = function(options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/tasks", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.tasksGet = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/tasks/" + id, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
APIClient.prototype.tasksCreate = function(codeName, payload, options, cb) {
var parseResponseBind;
parseResponseBind = _.bind(this.parseResponse, this);
@@ -58,6 +115,77 @@
});
};
+ APIClient.prototype.tasksCancel = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/tasks/" + id + "/cancel", {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.tasksCancelAll = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/codes/" + id + "/cancel_all", {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.tasksLog = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/tasks/" + id + "/log", {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb, false);
+ });
+ };
+
+ APIClient.prototype.tasksSetProgress = function(id, options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/tasks/" + id + "/progress", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.schedulesList = function(options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/schedules", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.schedulesGet = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/schedules/" + id, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.schedulesCreate = function(codeName, payload, options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/schedules", {
+ 'schedules': [
+ _.extend({
+ 'code_name': codeName,
+ 'payload': payload
+ }, options)
+ ]
+ }, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.schedulesCancel = function(id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/schedules/" + id + "/cancel", {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
return APIClient;
})(ironCore.Client);
View
181 lib/client.js
@@ -1,6 +1,8 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var Client, apiClient;
+ var Client, apiClient, _;
+
+ _ = require('underscore');
apiClient = require('./api_client');
@@ -10,6 +12,76 @@
this.api = new apiClient.APIClient(options);
}
+ Client.prototype.codesList = function(options, cb) {
+ return this.api.codesList(options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body.codes);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.codesGet = function(codeId, cb) {
+ return this.api.codesGet(codeId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.codesDelete = function(codeId, cb) {
+ return this.api.codesDelete(codeId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.codesRevisions = function(codeId, options, cb) {
+ return this.api.codesRevisions(codeId, options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body.revisions);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.codesDownload = function(codeId, options, cb) {
+ return this.api.codesDownload(codeId, options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksList = function(options, cb) {
+ return this.api.tasksList(options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body.tasks);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksGet = function(taskId, cb) {
+ return this.api.tasksGet(taskId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
Client.prototype.tasksCreate = function(codeName, params, options, cb) {
var payload;
payload = '';
@@ -27,6 +99,113 @@
});
};
+ Client.prototype.tasksCancel = function(taskId, cb) {
+ return this.api.tasksCancel(taskId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksCancelAll = function(codeId, cb) {
+ return this.api.tasksCancelAll(codeId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksLog = function(taskId, cb) {
+ return this.api.tasksLog(taskId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksSetProgress = function(taskId, options, cb) {
+ return this.api.tasksSetProgress(taskId, options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.tasksWaitFor = function(taskId, options, cb) {
+ var sleep, tasksWaitForBind;
+ tasksWaitForBind = _.bind(this.tasksWaitFor, this);
+ sleep = options.sleep;
+ if (!(sleep != null)) {
+ sleep = 5;
+ }
+ return this.tasksGet(taskId, function(error, body) {
+ if (!(error != null)) {
+ if (body.status === 'queued' || body.status === 'running') {
+ return _.delay(tasksWaitForBind, sleep * 1000, taskId, options, cb);
+ } else {
+ return cb(error, body);
+ }
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.schedulesList = function(options, cb) {
+ return this.api.schedulesList(options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body.tasks);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.schedulesGet = function(scheduleId, cb) {
+ return this.api.schedulesGet(scheduleId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.schedulesCreate = function(codeName, params, options, cb) {
+ var payload;
+ payload = '';
+ if (typeof params === 'string') {
+ payload = params;
+ } else {
+ payload = JSON.stringify(params);
+ }
+ return this.api.schedulesCreate(codeName, payload, options, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body.schedules[0]);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
+ Client.prototype.schedulesCancel = function(scheduleId, cb) {
+ return this.api.schedulesCancel(scheduleId, function(error, body) {
+ if (!(error != null)) {
+ return cb(error, body);
+ } else {
+ return cb(error, body);
+ }
+ });
+ };
+
return Client;
})();
View
4 package.json
@@ -1,14 +1,14 @@
{
"name": "iron_worker",
- "version": "0.0.3",
+ "version": "0.1.0",
"description": "Node client for IronWorker}",
"homepage": "https://github.com/iron-io/iron_worker_node",
"author": "Andrew Kirilenko & Iron.io, Inc",
"main": "./lib/client",
"dependencies": {
"pkginfo": "0.2.3",
"underscore": "1.3.3",
- "iron_core": "0.0.3"
+ "iron_core": "0.1.0"
},
"devDependencies": {
"coffee-script": "1.3.3"
View
106 src/api_client.coffee
@@ -14,6 +14,7 @@ class APIClient extends ironCore.Client
host: @AWS_US_EAST_HOST,
port: 443,
api_version: 2,
+ user_agent: @version
super('iron', 'worker', options, defaultOptions, ['project_id', 'token', 'api_version'])
@@ -26,11 +27,116 @@ class APIClient extends ironCore.Client
headers: ->
_.extend({}, super(), {'Authorization': "OAuth #{@options.token}"})
+ codesList: (options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/codes", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ codesGet: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/codes/#{id}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ codesDelete: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @delete("projects/#{@options.project_id}/codes/#{id}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb, false)
+ )
+
+ codesRevisions: (id, options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/codes/#{id}/revisions", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ codesDownload: (id, options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/codes/#{id}/download", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb, false)
+ )
+
+ tasksList: (options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/tasks", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ tasksGet: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/tasks/#{id}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
tasksCreate: (codeName, payload, options, cb) ->
parseResponseBind = _.bind(@parseResponse, @)
@post("projects/#{@options.project_id}/tasks", {'tasks': [_.extend({'code_name': codeName, 'payload': payload}, options)]}, (error, response, body) ->
parseResponseBind(error, response, body, cb)
)
+ tasksCancel: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/tasks/#{id}/cancel", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ tasksCancelAll: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/codes/#{id}/cancel_all", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ tasksLog: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/tasks/#{id}/log", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb, false)
+ )
+
+ tasksSetProgress: (id, options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/tasks/#{id}/progress", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ schedulesList: (options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/schedules", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ schedulesGet: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/schedules/#{id}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ schedulesCreate: (codeName, payload, options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/schedules", {'schedules': [_.extend({'code_name': codeName, 'payload': payload}, options)]}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ schedulesCancel: (id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/schedules/#{id}/cancel", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
module.exports.APIClient = APIClient
View
145 src/client.coffee
@@ -1,9 +1,67 @@
+_ = require('underscore')
+
apiClient = require('./api_client')
class Client
constructor: (options) ->
@api = new apiClient.APIClient(options)
+ codesList: (options, cb) ->
+ @api.codesList(options, (error, body) ->
+ if not error?
+ cb(error, body.codes)
+ else
+ cb(error, body)
+ )
+
+ codesGet: (codeId, cb) ->
+ @api.codesGet(codeId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ codesDelete: (codeId, cb) ->
+ @api.codesDelete(codeId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ codesRevisions: (codeId, options, cb) ->
+ @api.codesRevisions(codeId, options, (error, body) ->
+ if not error?
+ cb(error, body.revisions)
+ else
+ cb(error, body)
+ )
+
+ codesDownload: (codeId, options, cb) ->
+ @api.codesDownload(codeId, options, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ tasksList: (options, cb) ->
+ @api.tasksList(options, (error, body) ->
+ if not error?
+ cb(error, body.tasks)
+ else
+ cb(error, body)
+ )
+
+ tasksGet: (taskId, cb) ->
+ @api.tasksGet(taskId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
tasksCreate: (codeName, params, options, cb) ->
payload = ''
@@ -19,4 +77,91 @@ class Client
cb(error, body)
)
+ tasksCancel: (taskId, cb) ->
+ @api.tasksCancel(taskId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ tasksCancelAll: (codeId, cb) ->
+ @api.tasksCancelAll(codeId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ tasksLog: (taskId, cb) ->
+ @api.tasksLog(taskId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ tasksSetProgress: (taskId, options, cb) ->
+ @api.tasksSetProgress(taskId, options, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ tasksWaitFor: (taskId, options, cb) ->
+ tasksWaitForBind = _.bind(@tasksWaitFor, @)
+
+ sleep = options.sleep
+ sleep = 5 if not sleep?
+
+ @tasksGet(taskId, (error, body) ->
+ if not error?
+ if body.status == 'queued' or body.status == 'running'
+ _.delay(tasksWaitForBind, sleep * 1000, taskId, options, cb)
+ else
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ schedulesList: (options, cb) ->
+ @api.schedulesList(options, (error, body) ->
+ if not error?
+ cb(error, body.tasks)
+ else
+ cb(error, body)
+ )
+
+ schedulesGet: (scheduleId, cb) ->
+ @api.schedulesGet(scheduleId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
+ schedulesCreate: (codeName, params, options, cb) ->
+ payload = ''
+
+ if typeof(params) == 'string'
+ payload = params
+ else
+ payload = JSON.stringify(params)
+
+ @api.schedulesCreate(codeName, payload, options, (error, body) ->
+ if not error?
+ cb(error, body.schedules[0])
+ else
+ cb(error, body)
+ )
+
+ schedulesCancel: (scheduleId, cb) ->
+ @api.schedulesCancel(scheduleId, (error, body) ->
+ if not error?
+ cb(error, body)
+ else
+ cb(error, body)
+ )
+
module.exports.Client = Client

0 comments on commit 07ecd8c

Please sign in to comment.
Something went wrong with that request. Please try again.