Source

Repustate Clients / ruby / tc_repustate.rb

Full commit
require "repustate"
require "test/unit"

class TestRepustate < Test::Unit::TestCase

  KEY = 'YOUR_KEY_HERE'

  TEXT = 'iPad'

  URL = 'http://tcrn.ch/aav9Ty'

  def get_accessor
    return Repustate.new(KEY)
  end

  def check_call(func_name, options={}, check_status=true)
    result = get_accessor().send(func_name, options)
    assert_not_nil(result, 'Invalid result')
    if check_status
      status = result['status']
      assert_equal('OK', status, result)
    end
  end

  def test_sentiment_for_text
    check_call('sentiment', {:text => TEXT})
  end

  def test_sentiment_for_url
    check_call('sentiment', {:url => URL})
  end

  def test_bulk_sentiment
    check_call('bulk_sentiment', {:items => [URL]})
  end

  def test_clean_html
    check_call('clean_html', {:url => URL})
  end

  def test_adjectives_for_text
    check_call('adjectives', {:text => TEXT})
  end

  def test_adjectives_for_url
    check_call('adjectives', {:url => URL})
  end

  def test_verbs_for_text
    check_call('verbs', {:text => TEXT})
  end

  def test_verbs_for_url
    check_call('verbs', {:url => URL})
  end

  def test_ngrams_for_text
    check_call('ngrams', {:text => TEXT})
  end

  def test_ngrams_for_url
    check_call('ngrams', {:url => URL})
  end

  def test_date_extraction
    check_call('date_extraction', {:text => TEXT})
  end

  def test_powerpoint
    options = {
      :report_title => 'Test Report',
      :author => 'Martin Ostrovsky',
      :images => ['repustate.gif'],
      :titles => ['A test title'],
    }
    check_call('powerpoint', options, false)
  end

end