Sha256: ba5e1d0046d23377e31eb1478f5e9389d4bbe679f1b8a352065f35a47213c269

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 KB

Contents

# NOTE: It's important to cache duped objects
module Earthquake
  module Twitter
    attr_reader :twitter
  end

  init do
    @twitter = TwitterOAuth::Client.new(config.slice(:consumer_key, :consumer_secret, :token, :secret))

    output do |item|
      next if item["text"].nil? || item["_disable_cache"]
      item = item.dup
      item.keys.select { |key| key =~ /^_/ }.each { |key| item.delete(key) } # remote optional data like "_stream", "_highlights"
      Earthquake.cache.write("status:#{item["id"]}", item)
    end
  end

  once do
    class ::TwitterOAuth::Client
      [:status, :info].each do |m|
        define_method("#{m}_with_cache") do |*args|
          key = "#{m}:#{args.join(',')}"
          if result = Earthquake.cache.read(key)
            result.dup
          else
            result = __send__(:"#{m}_without_cache", *args)
            Earthquake.cache.write(key, result.dup)
            result
          end
        end
        alias_method_chain m, :cache
      end
    end
  end

  extend Twitter
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
earthquake-0.6.6 lib/earthquake/twitter.rb
earthquake-0.6.5 lib/earthquake/twitter.rb
earthquake-0.6.4 lib/earthquake/twitter.rb
earthquake-0.6.3 lib/earthquake/twitter.rb
earthquake-0.6.2 lib/earthquake/twitter.rb
earthquake-0.6.1 lib/earthquake/twitter.rb
earthquake-0.6.0 lib/earthquake/twitter.rb
earthquake-0.5.9 lib/earthquake/twitter.rb
earthquake-0.5.8 lib/earthquake/twitter.rb
earthquake-0.5.7 lib/earthquake/twitter.rb
earthquake-0.5.6 lib/earthquake/twitter.rb
earthquake-0.5.5 lib/earthquake/twitter.rb
earthquake-0.5.4 lib/earthquake/twitter.rb
earthquake-0.5.3 lib/earthquake/twitter.rb
earthquake-0.5.2 lib/earthquake/twitter.rb
earthquake-0.5.1 lib/earthquake/twitter.rb
earthquake-0.5.0 lib/earthquake/twitter.rb
earthquake-0.4.9 lib/earthquake/twitter.rb
earthquake-0.4.8 lib/earthquake/twitter.rb