jugyo / earthquake

Twitter terminal client with streaming API support.
MIT License
661 stars 94 forks source link

Refrains from getting gist API twice. #132

Closed morygonzalez closed 12 years ago

morygonzalez commented 12 years ago

As the json that Gist API v3 returns contains raw code in itself, now we don't need to access API twice.

pry(main)> json = JSON.parse(open('https://api.github.com/gists/896054').read)
pry(main)> puts json['files'][json['files'].keys[0]]['content']
# -*- coding: utf-8 -*-
# https://twitter.com/#!/jugyo/status/51959560084275200
Earthquake.init do
  t = {
    "u"    => ":update",
    "re"   => ":reply",
    "rt"   => ":retweet",
    "l"    => ":recent",
    "show" => ":status",
  }
  input_filter do |text|
    text.tap do
      if m = %r|^(#{Regexp.union(t.keys)})(\s+.*)?$|o.match(text)
        warn("⚡⚡⚡ Hmm, you are a well-trained termtter user :-(.".c(:notice))
        warn("⚡⚡⚡ Use '#{t[m[1]]}' instead of '#{m[1]}' on earthquake.gem.".c(:notice))
        break [t[m[1]], m[2].gsub(/\$\w+/){|var| var2id(var) || var}].join
      end
    end
  end
end
nil
jugyo commented 12 years ago

Thank you for the nice patch!