Permalink
Browse files

Changed it so JSON only parses if 'object' output is requested, in ca…

…se user wants actual JSON.
  • Loading branch information...
mcantelon committed Dec 31, 2010
1 parent e9110cd commit b69aa3889634e6f3f989619394d7abe1e61e203d
Showing with 9 additions and 5 deletions.
  1. +9 −5 lib/calais.js
View
@@ -14,7 +14,7 @@ Calais.prototype = {
'apiHost': 'api.opencalais.com',
'apiPath': '/tag/rs/enrich',
'contentType': 'text/raw',
- 'outputFormat': 'application/json',
+ 'outputFormat': 'object',
'reltagBaseURL': '',
'calculateRelevanceScore': true,
'enableMetadataType': 'GenericRelations,SocialTags',
@@ -67,11 +67,15 @@ Calais.prototype = {
if (this.validate_options()) {
+ var outputFormat = (calais.options.outputFormat == 'object')
+ ? 'application/json'
+ : this.options.outputFormat
+
var params = {
'Host': this.options.apiHost,
'x-calais-licenseID': this.api_key,
'Content-Type': this.options.contentType,
- 'Accept': this.options.outputFormat,
+ 'Accept': outputFormat,
'Content-Length': this.options.content.length,
'calculateRelevanceScore': this.options.calculateRelevanceScore,
'enableMetadataType': this.options.enableMetadataType,
@@ -103,15 +107,15 @@ Calais.prototype = {
var calaisData = data.join('')
// take note of whether JSON output was requested
- var jsonOutput = (calais.options.outputFormat == 'application/json')
+ var jsOutput = (calais.options.outputFormat == 'object')
// parse to a Javascript object if outputting JSON
- var result = (jsonOutput)
+ var result = (jsOutput)
? JSON.parse(calaisData)
: calaisData
// ignore cleanResult preference if not outputting JSON
- result = (jsonOutput && calais.options.cleanResult)
+ result = (jsOutput && calais.options.cleanResult)
? calais.clean_result(result)
: result

0 comments on commit b69aa38

Please sign in to comment.