Sha256: 07657b878cf8e7b0b7a7c0c4fe3935627710adcb15eb6655879bfd067b24882f
Contents?: true
Size: 1014 Bytes
Versions: 3
Compression:
Stored size: 1014 Bytes
Contents
module Scouter class Twitter < Scouter::Base::Object END_POINT = 'http://urls.api.twitter.com'.freeze # get Twitter Count # @param [String or Array] urls def self.get_count(urls) urls = check_and_trans_url(urls) results, errors = {}, [] urls.each_with_index do |u, idx| sleep(WAIT_SEC) if idx != 0 res, error = get_and_parse_response(u) errors << error && next if error results.merge!(res) end res_hash = Hashie::Mash.new(results) return [res_hash, errors] end private # build Twitter API URL # @param [String] url # @return [String] API url def self.api_url(url) escaped_url = URI.escape(url) "#{END_POINT}/1/urls/count.json?url=#{escaped_url}" end # Parse json data for response # @param [Hash] json # @return [Hash] url & count def self.parse_response(json, url) res = JSON.parse(json) { url => { self.service_name => res['count'] } } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scouter-0.0.3 | lib/scouter/twitter.rb |
scouter-0.0.2 | lib/scouter/twitter.rb |
scouter-0.0.1 | lib/scouter/twitter.rb |