Skip to content

Commit

Permalink
Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Dec 31, 2010
1 parent 1a65a61 commit e9110cd
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/calais.js
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e9110cd

Please sign in to comment.