lib/burghers/client.rb in burghers-0.0.1 vs lib/burghers/client.rb in burghers-0.0.2

- old
+ new

@@ -12,14 +12,16 @@ if content.start_with?('http://') or content.start_with?('https://') content = HTTParty.get(content).body content_type = "text/html" end - if content_type.nil? and content.include?("<") and content.include(">") - content_type = "text/html" - elsif content_type.nil? - content_type = "text/raw" + 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, @@ -28,10 +30,16 @@ response = HTTParty.post(URI, :body => content, :headers => headers) if response.code != 200 raise "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