Module: Jkl

Defined in:
lib/jkl.rb,
lib/jkl/rss_client.rb,
lib/jkl/rest_client.rb,
lib/jkl/text_client.rb,
lib/jkl/calais_client.rb

Defined Under Namespace

Modules: Extraction, Rss, Text

Class Method Summary collapse

Class Method Details

.document_from(text) ⇒ Object



38
39
40
# File 'lib/jkl/rest_client.rb', line 38

def document_from(text)
  Hpricot(text)
end

.get_from(uri) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jkl/rest_client.rb', line 21

def get_from(uri)
  begin
    response = Net::HTTP.get_response(URI.parse(uri))
    response.body
  rescue  URI::InvalidURIError => e
    puts("WARN: Invalid URI: #{e}")
  rescue SocketError => e
    puts("WARN: Could not connect: #{e}")
  rescue Errno::ECONNREFUSED  => e
    puts("WARN: Connection refused: #{e}")
  end
end

.get_xml_from(uri) ⇒ Object



34
35
36
# File 'lib/jkl/rest_client.rb', line 34

def get_xml_from(uri)
  Hpricot.XML(get_from(uri))
end


12
13
14
15
16
17
# File 'lib/jkl.rb', line 12

def links(feed)
  links = Jkl::Rss::links(Jkl::Rss::items(Jkl::get_xml_from(feed)))
  links.each do |link|
    yield link if block_given?
  end
end

.post_to(url, post_args = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jkl/rest_client.rb', line 7

def post_to(url, post_args = {})
  begin
    uri = URI.parse(url)
    resp, data = Net::HTTP.post_form(uri, post_args)
    data
  rescue  URI::InvalidURIError => e
    puts("WARN: Invalid URI: #{e}")
  rescue SocketError => e
    puts("WARN: Could not connect: #{e}")
  rescue Errno::ECONNREFUSED  => e
    puts("WARN: Connection refused: #{e}")
  end
end

.tags(key, link) ⇒ Object



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

def tags(key, link)
  text = Jkl::Text::sanitize(Jkl::get_from(link))
  Jkl::Extraction::tags(key, text)
end


19
20
21
# File 'lib/jkl.rb', line 19

def topix_links(keyphrase, url = "http://www.topix.net/rss/search/article?q=")
  links("#{url}#{keyphrase}")
end


28
29
30
# File 'lib/jkl.rb', line 28

def trends(url = "http://search.twitter.com/trends.json")
  JSON.parse(Jkl::get_from(url))["trends"].map{|t| t["name"]}
end