Permalink
Browse files

Initial implementation.

  • Loading branch information...
1 parent 467935f commit c791150995225a70474832a354962c25265ec17f Andrew Kirilenko committed Jul 8, 2012
Showing with 109 additions and 14 deletions.
  1. +2 −14 .gitignore
  2. +22 −0 LICENSE
  3. +4 −0 Makefile
  4. +23 −0 package.json
  5. +36 −0 src/api_client.coffee
  6. +22 −0 src/client.coffee
View
16 .gitignore
@@ -1,15 +1,3 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
+lib
node_modules
-npm-debug.log
+npm-debug.log
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Iron.io, Inc
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
4 Makefile
@@ -0,0 +1,4 @@
+build:
+ `npm bin`/coffee -o lib -c src/*.coffee
+
+all: build
View
23 package.json
@@ -0,0 +1,23 @@
+{
+ "name": "iron_worker",
+ "version": "0.0.1",
+ "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": "git://github.com/iron-io/iron_core_node.git#master"
+ },
+ "devDependencies": {
+ "coffee-script": "1.3.3"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/iron-io/iron_worker_node.git"
+ },
+ "engines": {
+ "node": ">= 0.6.0"
+ }
+}
View
36 src/api_client.coffee
@@ -0,0 +1,36 @@
+require('pkginfo')(module)
+version = @version
+
+_ = require('underscore')
+
+iron_core = require('iron_core');
+
+class APIClient extends iron_core.Client
+ AWS_US_EAST_HOST: 'worker-aws-us-east-1.iron.io'
+
+ constructor: (options) ->
+ default_options =
+ scheme: 'https',
+ host: @AWS_US_EAST_HOST,
+ port: 443,
+ api_version: 2,
+
+ super('iron', 'worker', options, default_options, ['project_id', 'token', 'api_version'])
+
+ version: ->
+ "iron_worker_node-#{version} (#{super()})"
+
+ url: ->
+ super() + @options.api_version.toString() + '/'
+
+ headers: ->
+ _.extend({}, super(), {'Authorization': "OAuth #{@options.token}"})
+
+ tasks_create: (code_name, payload, options, cb) ->
+ parse_response = _.bind(@parse_response, @)
+
+ @post("projects/#{@options.project_id}/tasks", {'tasks': [_.extend({'code_name': code_name, 'payload': payload}, options)]}, (error, response, body) ->
+ parse_response(error, response, body, cb)
+ )
+
+module.exports.APIClient = APIClient
View
22 src/client.coffee
@@ -0,0 +1,22 @@
+api_client = require('./api_client')
+
+class Client
+ constructor: (options) ->
+ @api = new api_client.APIClient(options)
+
+ tasks_create: (code_name, params, options, cb) ->
+ payload = ''
+
+ if typeof(params) == 'string'
+ payload = params
+ else
+ payload = JSON.stringify(params)
+
+ @api.tasks_create(code_name, payload, options, (error, body) ->
+ if not error?
+ cb(error, body.tasks[0])
+ else
+ cb(error, body)
+ )
+
+module.exports.Client = Client

0 comments on commit c791150

Please sign in to comment.