Sha256: b0414511c52315e379d3b41e95e5ea1c156397274878a43000c37c469886f7c7
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
require 'httparty' module Burghers class Client URI = "http://api.opencalais.com/tag/rs/enrich" def initialize(license) @license = license end def enrich(content, content_type=nil, headers = nil) if content.start_with?('http://') or content.start_with?('https://') content = HTTParty.get(content).body content_type = "text/html" end if content_type.nil? if html?(content) content_type = "text/html" else content_type = "text/raw" end end headers = { 'accept' => 'application/json', 'x-calais-licenseID' => @license, 'content-type' => content_type }.merge(headers || {}) response = HTTParty.post(URI, :body => content, :headers => headers) if response.code != 200 raise CalaisResponseError, "Got response code of #{response.code}: #{response}" end Response.new response.parsed_response end private def html?(content) content && content.include?("<") && content.include?(">") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
burghers-0.0.3 | lib/burghers/client.rb |