Permalink
Browse files

Minor cleanup.

  • Loading branch information...
1 parent 1a65a61 commit e9110cd0099a4206619e216f08bb704360c63d2b @mcantelon committed Dec 31, 2010
Showing with 8 additions and 9 deletions.
  1. +8 −9 lib/calais.js
View
@@ -51,10 +51,6 @@ Calais.prototype = {
return true
},
- _parseChunks: function(chunks) {
- return chunks.join('');
- },
-
clean_result:function(result) {
var clean_result = []
for(var i in result) {
@@ -71,8 +67,6 @@ Calais.prototype = {
if (this.validate_options()) {
- var scope = this
-
var params = {
'Host': this.options.apiHost,
'x-calais-licenseID': this.api_key,
@@ -105,13 +99,18 @@ Calais.prototype = {
})
response.on('end', function() {
- var urldata = scope._parseChunks(data)
+ // serialize the returned data
+ var calaisData = data.join('')
+
+ // take note of whether JSON output was requested
var jsonOutput = (calais.options.outputFormat == 'application/json')
+ // parse to a Javascript object if outputting JSON
var result = (jsonOutput)
- ? JSON.parse(urldata)
- : urldata
+ ? JSON.parse(calaisData)
+ : calaisData
+ // ignore cleanResult preference if not outputting JSON
result = (jsonOutput && calais.options.cleanResult)
? calais.clean_result(result)
: result

0 comments on commit e9110cd

Please sign in to comment.