Module: Crown::BackType
- Defined in:
- lib/crown/backtype.rb
Class Method Summary collapse
-
.count(uri, api_key, proxy_host = nil, proxy_port = nil) ⇒ Object
——————————————————————- # count ——————————————————————- #.
Class Method Details
.count(uri, api_key, proxy_host = nil, proxy_port = nil) ⇒ Object
——————————————————————- #
count
——————————————————————- #
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/crown/backtype.rb', line 46 def count(uri, api_key, proxy_host = nil, proxy_port = nil) return 0 if (api_key == nil) begin session = Net::HTTP.new('api.backtype.com', 80, proxy_host, proxy_port) path = '/tweetcount.json?q=' + CGI.escape(uri) + '&key=' + api_key response = Crown::HTTP.get(session, path) return nil if (response == nil || response.code.to_i != 200) json = JSON.parse(response.body) return json["tweetcount"].to_i rescue Exception return 0 end end |