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
|
.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
|
.topix_links(keyphrase, url = "http://www.topix.net/rss/search/article?q=") ⇒ Object
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
|
.trends(url = "http://search.twitter.com/trends.json") ⇒ Object
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
|