Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor cleanup.

  • Loading branch information...
commit e9110cd0099a4206619e216f08bb704360c63d2b 1 parent 1a65a61
@mcantelon authored
Showing with 8 additions and 9 deletions.
  1. +8 −9 lib/calais.js
View
17 lib/calais.js
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.