Class: Repustate

Inherits:
Object
  • Object
show all
Defined in:
lib/repustate.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, version = 'v3') ⇒ Repustate

Returns a new instance of Repustate.



23
24
25
26
# File 'lib/repustate.rb', line 23

def initialize(key, version='v3')
  @key = key
  @version = version
end

Instance Method Details

#bulk_sentiment(options = {:items => [], :lang => 'en'}) ⇒ Object

Bulk score multiple pieces of text (not urls!).



35
36
37
38
39
40
# File 'lib/repustate.rb', line 35

def bulk_sentiment(options={:items => [], :lang => 'en'})
  items_to_score = Hash[options[:items].enum_for(:each_with_index).collect {
                          |val, i| ["text#{i}", val]
                        }]
  call_api('bulk-score', items_to_score)
end

#clean_html(options = {:url => nil}) ⇒ Object

Clean up a web page. It doesn’t work well on home pages - it’s designed for content pages.



44
45
46
47
# File 'lib/repustate.rb', line 44

def clean_html(options={:url => nil})
  use_http_get = true
  call_api('clean-html', options, use_http_get)
end

#entities(options = {:text => nil, :lang => 'en'}) ⇒ Object



49
50
51
52
# File 'lib/repustate.rb', line 49

def entities(options={:text => nil, :lang => 'en'})
  use_http_get = true
  call_api('entities', options)
end

#sentiment(options = {:text => nil, :lang => 'en'}) ⇒ Object

Retrieve the sentiment for a single URl or block of text. Optionally select a language other than English.



30
31
32
# File 'lib/repustate.rb', line 30

def sentiment(options={:text => nil, :lang => 'en'})
  call_api('score', options)
end

#topic(options = {:text => nil, :topics => nil, :lang => 'en'}) ⇒ Object



54
55
56
57
# File 'lib/repustate.rb', line 54

def topic(options={:text => nil, :topics => nil, :lang => 'en'})
  use_http_get = true
  call_api('entities', options)
end