Module: Crown::Topsy

Defined in:
lib/crown/topsy.rb

Class Method Summary collapse

Class Method Details

.count(uri, proxy_host = nil, proxy_port = nil) ⇒ Object

——————————————————————- #

count

——————————————————————- #



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/crown/topsy.rb', line 46

def count(uri, proxy_host = nil, proxy_port = nil)
    begin
        session = Net::HTTP.new('otter.topsy.com', 80, proxy_host, proxy_port)
        path = '/urlinfo.json?url=' + CGI.escape(uri)
        response = Crown::HTTP.get(session, path)
        return 0 if (response == nil || response.code.to_i != 200)
        
        json = JSON.parse(response.body)
        return json["response"]["trackback_total"].to_i
    rescue Exception
        return 0
    end
end