Sha256: 943261ddf8fcc25513ae1fed7c9adb7bb5712299023569460075ec64030e6d7d
Contents?: true
Size: 985 Bytes
Versions: 1
Compression:
Stored size: 985 Bytes
Contents
require "faraday" require "faraday_middleware" require "json" module Applied class Sentiment ENDPOINT = "/api/sentiment_api/" attr_accessor :return_original, :classifier def analyze(data, options) params = options call(ENDPOINT, data, options) end protected def call(endpoint, data, options) begin request = { data: { api_key: Applied.config.api_key, call: { return_original: options[:return_original], classifier: options[:classifier], data: data } } } conn = Faraday.new(url: Applied.config.endpoint) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end response = conn.post endpoint, request: request.to_json JSON.parse response.body rescue Exception => e raise Applied::BadResponse end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
applied-0.0.2 | lib/applied/sentiment.rb |