Class: AutoTagging::OpenCalais

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

Constant Summary collapse

API_SITE_URL =
'api.opencalais.com'
API_PAGE_URL =
'/tag/rs/enrich'

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/auto_tagging/open_calais.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#get_tags(content) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/auto_tagging/open_calais.rb', line 13

def get_tags(content)
  res = nil
  Net::HTTP.start(API_SITE_URL) do |http|
    req = Net::HTTP::Post.new(API_PAGE_URL)
    req.initialize_http_header(options)
    req.body = content.to_s
    res = http.request(req)
  end

  tags = JSON.parse(res.body).values.map { |value| value["name"] }.compact if res && res.code == "200"
  tags || []
end