Sha256: 84555a704085fbd465716f13b798c6d701658ad3fce7108e50c41b7cd504b5f4

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

require 'crack/json'

module ShareChecker
  module Providers
    class Tweetracker < Provider
      
      # Response sample
      #
      # {
      #   "tweets":30,
      #   "id":"4e281dcec546612414000004",
      #   "users":26,
      #   "query":"http://www.mcdonaldseurokids2012.com.ua/challenges/1/works/140"
      # }
      #
      def parse(response)
        count = 0
        
        begin
          obj = Crack::JSON.parse(response)
          count = (obj["users"] ? obj["users"].to_i : 0)
        rescue Exception => e
          puts "Error parse json: #{response}, #{e.message}"
          count = 0
        end
        
        return count
      end
      
      def url
        "http://tracktweets.aimbulance.com/api/v1/groups/#{group_id}/urls/count.json?query="
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
share_checker-0.1.1 lib/share_checker/providers/tweetracker.rb