Commit 3b8a50e8 authored by alexlag's avatar alexlag
Browse files

TwitterAPI + tests

parent 7a3d10f9
require 'rake/testtask'
Rake::TestTask.new do |t|
t.name = 'test:texterra'
t.libs << 'test'
t.test_files = ['test/test_texterra_api.rb']
end
desc "Run tests"
Rake::TestTask.new do |t|
t.name = 'test:twitter'
t.libs << 'test'
t.test_files = ['test/test_twitter_api.rb']
end
task :test => ['test:texterra', 'test:twitter']
desc "Run all tests"
task :default => :test
\ No newline at end of file
require_relative './ispras_api'
class TwitterAPI < IsprasAPI
#This class provides methods to work with Twitter NLP REST via OpenAPI
disable_rails_query_string_format
def initialize(key, name, ver)
name='twitter-nlp' if name.nil? || name.empty?
ver='1.0' if ver.nil? || ver.empty?
super(key, name, ver)
end
# Extracts demographic attributes from provided Twitter info. All info is required, but can be empty
#
# @param [Hash] params
# @option params [String] :lang Language of tweets
# @option params [String] :username Username of Twitter user
# @option params [String] :screenname Screen name of Twitter user
# @option params [String] :description Description of Twitter user
# @option params [String, Array<String>] :tweet User's tweets
# @return [Hash] Enriched user with attributes
def extract_dde(params)
params[:tweet] = params[:tweet].join(' ') if params[:tweet].is_a? Array
POST 'extract', {}, params
end
def custom_query(path, query, form=nil)
form.nil? ? GET(path, query) : POST(path, query, form)
end
private
def check_error(response)
hash = @nori.parse response.body
er_node = hash[:html][:body][:p].detect { |node| node.is_a? Hash and node[:b] == 'root cause' }
raise ApiError, er_node[:pre].gsub(/ru\.ispras.*:\s*/, '')
end
end
\ No newline at end of file
require 'minitest/autorun'
require 'dotenv'
Dotenv.load
require_relative '../lib/ispapi'
require_relative '../lib/ispapi/texterra_api'
class TestTexterraAPI < Minitest::Test
def setup
@texterra = TexterraAPI.new ENV['KEY'], ENV['SERVICE_NAME'], ENV['SERVICE_VERSION']
@texterra = TexterraAPI.new ENV['TEXTERRA_KEY'], ENV['TEXTERRA_SERVICE_NAME'], ENV['TEXTERRA_SERVICE_VERSION']
@en_text = 'Apple today updated iMac to bring numerous high-performance enhancements to the leading all-in-one desktop. iMac now features fourth-generation Intel Core processors, new graphics, and next-generation Wi-Fi. In addition, it now supports PCIe-based flash storage, making its Fusion Drive and all-flash storage options up to 50 percent faster than the previous generation'
@ru_text = 'Первые в этом году переговоры министра иностранных дел России Сергея Лаврова и госсекретаря США Джона Керри, длившиеся 1,5 часа, завершились в Мюнхене.'
@en_tweet = 'mentioning veterens care which Mccain has voted AGAINST - SUPER GOOOOD point Obama+1 #tweetdebate'
......
require 'minitest/autorun'
require 'dotenv'
Dotenv.load
require_relative '../lib/ispapi/twitter_api'
class TestTwitterAPI < Minitest::Test
def setup
@twitter = TwitterAPI.new ENV['DDE_KEY'], ENV['DDE_SERVICE_NAME'], ENV['DDE_SERVICE_VERSION']
end
def test_extract_dde
@twitter.extract_dde lang: 'en', username: 'Ann', screenname: 'bob', description: 'I am Ann from NY', tweet:'Hi there, I am Ann fromNY'
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment