Skip to content

Refrains from getting gist API twice. #132

Merged
merged 1 commit into from Jul 5, 2012

2 participants

@morygonzalez

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
@morygonzalez morygonzalez Refrains from getting gist API twice.
As the json that Gist API v3 returns contains raw code in itself,
don't need to access API twice.
26d13fe
@jugyo jugyo merged commit 52575cd into jugyo:master Jul 5, 2012
@jugyo
Owner
jugyo commented Jul 5, 2012

Thank you for the nice patch!

@morygonzalez morygonzalez deleted the morygonzalez:feature/refrain-from-getting-gist-twice branch Mar 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.