Permalink
Browse files

Added the files.

  • Loading branch information...
1 parent 8ea082e commit 1819ed41f42df524bc3b203d16c16258266f58b2 @mcantelon committed Dec 29, 2010
Showing with 139 additions and 0 deletions.
  1. +21 −0 LICENSE
  2. +7 −0 TODO
  3. +8 −0 example.js
  4. +76 −0 lib/calais.js
  5. +27 −0 package.json
View
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2010 Mike Cantelon
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
7 TODO
@@ -0,0 +1,7 @@
+To-do:
+-try changing host so result is undefined
+-have it so you pass in options and each option has a default
+-have a raw mode for getting raw request
+-add support for raw mode
+-automated test
+-upload to npm
View
@@ -0,0 +1,8 @@
+var sys = require('sys'),
+ Calais = require('./lib/calais').Calais
+
+var calais = new Calais('your_api_key')
+calais.set('content', 'The Federal Reserve is the enemy of Ron Paul.')
+calais.get(function(result) {
+ sys.puts(sys.inspect(result))
+})
View
@@ -0,0 +1,76 @@
+var http = require('http'),
+ sys = require('sys')
+
+var Calais = function(api_key) {
+ this.initialize(api_key)
+ return this
+}
+
+Calais.prototype = {
+
+ initialize:function(api_key) {
+ this.api_key = api_key
+ },
+
+ set:function(key, value) {
+ this[key] = value
+ },
+
+ validate_params:function() {
+ return true
+ },
+
+ _parseChunks: function(chunks) {
+ return chunks.join('');
+ },
+
+ clean_result:function(result) {
+ var clean_result = []
+ for(var i in result) {
+ if (i != 'doc') {
+ clean_result.push(result[i])
+ }
+ }
+ return clean_result
+ },
+
+ get:function(callback) {
+
+ var calais = this
+
+ if (this.validate_params()) {
+
+ var scope = this
+
+ var params = {
+ 'Host': 'api.opencalais.com',
+ 'x-calais-licenseID': this.api_key,
+ 'Content-Type': 'text/raw',
+ 'Accept': 'application/json',
+ 'Content-Length': this.content.length
+ }
+
+ var client = http.createClient(80, 'api.opencalais.com')
+ var request = client.request('POST', '/tag/rs/enrich', params)
+ request.end(this.content)
+
+ request.on('response', function(response) {
+ var data = []
+ response.on('data', function(chunk) {
+ data.push(chunk)
+ })
+ response.on('end', function() {
+ var urldata = scope._parseChunks(data)
+ var result = JSON.parse(urldata)
+ // if not raw mode
+ if (1) {
+ result = calais.clean_result(result)
+ }
+ return callback(result)
+ })
+ })
+ }
+ }
+}
+
+exports.Calais = Calais
View
@@ -0,0 +1,27 @@
+{
+ "name": "calais",
+ "version": "0.0.1",
+ "description": "Semantically analyze text using the Calais web service.",
+ "tags" : ["semantic", "calais"],
+ "author" : "Mike Cantelon <mcantelon@gmail.com>",
+ "contributors" : [],
+ "dependencies" : {},
+ "main": "./lib/calais",
+ "directories" : {
+ "lib": "./lib"
+ },
+ "repository": {
+ "type": "git",
+ "url" : "http://github.com/mcantelon/node-calais"
+ },
+ "engines": {
+ "node": ">= 0.3.0"
+ },
+ "bugs" : {
+ "web" : "http://github.com/mcantelon/node-calais/issues",
+ },
+ "licenses" : [{
+ "type" : "MIT",
+ "url" : "http://github.com/mcantelon/node-calais/LICENSE"
+ }]
+}

0 comments on commit 1819ed4

Please sign in to comment.