lib/dandelionapi/language_detection.rb in dandelionapi-0.0.3 vs lib/dandelionapi/language_detection.rb in dandelionapi-0.0.5

- old
+ new

@@ -3,23 +3,49 @@ require "faraday" require "faraday_middleware" require "json" module Dandelionapi + module LanguageDetection - class LanguageDetection < Base + class Request < Analysis::Request - ENDPOINT = "/datatxt/li/v1" + ENDPOINT = "/li/v1" - attr_accessor :text, :url, :html, :html_fragment, :clean + MANDATORY_FIELDS = [ + "text", + "url", + "html", + "html_fragment" + ] - def analyze(options) + OPTIONAL_FIELDS = [ + "clean" + ] - raise MissingParameters.new("Please provide one of the following parameters: text, url, html or html_fragment") if ([:text, :url, :html, :html_fragment] & options.keys).empty? + FIELDS_FORMAT = { + "text" => { + valid: lambda {|value| value.is_a? String}, + error_message: 'text needs to be String' + }, + "url" => { + valid: lambda {|value| value.is_a? String}, + error_message: 'url needs to be String' + }, + "html" => { + valid: lambda {|value| value.is_a? String}, + error_message: 'html needs to be String' + }, + "html_fragment" => { + valid: lambda {|value| value.is_a? String}, + error_message: 'html_fragment needs to be String' + }, + "clean" => { + valid: lambda {|value| (value.is_a? TrueClass or value.is_a? FalseClass)}, + error_message: 'clean needs to be Boolean' + }, + } - params = options - call(ENDPOINT, params) end end - end \ No newline at end of file