Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initiali APIClient implementation.

  • Loading branch information...
commit df1d8a81c7c80df03c07a2d3faa76308e9f32a79 1 parent f71dea2
@iced iced authored
View
15 .gitignore
@@ -1,15 +1,2 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
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
106 lib/api_client.js
@@ -0,0 +1,106 @@
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var APIClient, ironCore, version, _,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ require('pkginfo')(module);
+
+ version = this.version;
+
+ _ = require('underscore');
+
+ ironCore = require('iron_core');
+
+ APIClient = (function(_super) {
+
+ __extends(APIClient, _super);
+
+ APIClient.prototype.AWS_US_EAST_HOST = 'mq-aws-us-east-1.iron.io';
+
+ APIClient.prototype.RACKSPACE_HOST = 'mq-rackspace-dfw.iron.io';
+
+ function APIClient(options) {
+ var defaultOptions;
+ defaultOptions = {
+ scheme: 'https',
+ host: this.AWS_US_EAST_HOST,
+ port: 443,
+ api_version: 1,
+ user_agent: this.version,
+ queue_name: 'default'
+ };
+ APIClient.__super__.constructor.call(this, 'iron', 'mq', options, defaultOptions, ['project_id', 'token', 'api_version', 'queue_name']);
+ }
+
+ APIClient.prototype.version = function() {
+ return "iron_mq_node-" + version + " (" + (APIClient.__super__.version.call(this)) + ")";
+ };
+
+ APIClient.prototype.url = function() {
+ return APIClient.__super__.url.call(this) + this.options.api_version.toString() + '/';
+ };
+
+ APIClient.prototype.headers = function() {
+ return _.extend({}, APIClient.__super__.headers.call(this), {
+ 'Authorization': "OAuth " + this.options.token
+ });
+ };
+
+ APIClient.prototype.queuesList = function(options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/queues", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.queuesGet = function(queue_name, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/queues/" + queue_name, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.queuesClear = function(queue_name, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/queues/" + queue_name + "/clear", {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.messagesPost = function(queue_name, messages, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.post("projects/" + this.options.project_id + "/queues/" + queue_name + "/messages", {
+ messages: messages
+ }, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.messagesGet = function(queue_name, options, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this.get("projects/" + this.options.project_id + "/queues/" + queue_name + "/messages", options, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ APIClient.prototype.messagesDelete = function(queue_name, message_id, cb) {
+ var parseResponseBind;
+ parseResponseBind = _.bind(this.parseResponse, this);
+ return this["delete"]("projects/" + this.options.project_id + "/queues/" + queue_name + "/messages/" + message_id, {}, function(error, response, body) {
+ return parseResponseBind(error, response, body, cb);
+ });
+ };
+
+ return APIClient;
+
+ })(ironCore.Client);
+
+ module.exports.APIClient = APIClient;
+
+}).call(this);
View
23 package.json
@@ -0,0 +1,23 @@
+{
+ "name": "iron_mq",
+ "version": "0.1.0",
+ "description": "Node client for IronWorker}",
+ "homepage": "https://github.com/iron-io/iron_mq_node",
+ "author": "Andrew Kirilenko & Iron.io, Inc",
+ "main": "./lib/client",
+ "dependencies": {
+ "pkginfo": "0.2.3",
+ "underscore": "1.3.3",
+ "iron_core": "0.2"
+ },
+ "devDependencies": {
+ "coffee-script": "1.3.3"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/iron-io/iron_mq_node.git"
+ },
+ "engines": {
+ "node": ">= 0.6.0"
+ }
+}
View
74 src/api_client.coffee
@@ -0,0 +1,74 @@
+require('pkginfo')(module)
+version = @version
+
+_ = require('underscore')
+
+ironCore = require('iron_core');
+
+class APIClient extends ironCore.Client
+ AWS_US_EAST_HOST: 'mq-aws-us-east-1.iron.io'
+ RACKSPACE_HOST: 'mq-rackspace-dfw.iron.io'
+
+ constructor: (options) ->
+ defaultOptions =
+ scheme: 'https',
+ host: @AWS_US_EAST_HOST,
+ port: 443,
+ api_version: 1,
+ user_agent: @version,
+ queue_name: 'default'
+
+ super('iron', 'mq', options, defaultOptions, ['project_id', 'token', 'api_version', 'queue_name'])
+
+ version: ->
+ "iron_mq_node-#{version} (#{super()})"
+
+ url: ->
+ super() + @options.api_version.toString() + '/'
+
+ headers: ->
+ _.extend({}, super(), {'Authorization': "OAuth #{@options.token}"})
+
+ queuesList: (options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/queues", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ queuesGet: (queue_name, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/queues/#{queue_name}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ queuesClear: (queue_name, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/queues/#{queue_name}/clear", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ messagesPost: (queue_name, messages, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @post("projects/#{@options.project_id}/queues/#{queue_name}/messages", {messages: messages}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ messagesGet: (queue_name, options, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @get("projects/#{@options.project_id}/queues/#{queue_name}/messages", options, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+ messagesDelete: (queue_name, message_id, cb) ->
+ parseResponseBind = _.bind(@parseResponse, @)
+
+ @delete("projects/#{@options.project_id}/queues/#{queue_name}/messages/#{message_id}", {}, (error, response, body) ->
+ parseResponseBind(error, response, body, cb)
+ )
+
+module.exports.APIClient = APIClient
Please sign in to comment.
Something went wrong with that request. Please try again.