Skip to content

Instantly share code, notes, and snippets.

@no6v
Last active December 14, 2015 09:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no6v/5064995 to your computer and use it in GitHub Desktop.
Save no6v/5064995 to your computer and use it in GitHub Desktop.
Earthquake.once do
Module.new do |api_v1_1_forcibly|
def request(http_method, path, *arguments)
super(http_method, path.sub("/1/", "/1.1/"), *arguments)
end
OAuth::AccessToken.__send__(:prepend, api_v1_1_forcibly)
end
Module.new do |api_v1_1|
def favorite(id)
post("/favorites/create.json", id: id)
end
def unfavorites(id)
post("/favorites/destroy.json", id: id)
end
def mentions(options = {})
get("/statuses/mentions_timeline.json?#{options.to_query}")
end
def friend(screen_name)
post("/friendships/create.json", screen_name: screen_name)
end
def unfriend(screen_name)
post("/friendships/destroy.json", screen_name: screen_name)
end
def block(screen_name)
post("/blocks/create.json", screen_name: screen_name)
end
def unblock(screen_name)
post("/blocks/destroy.json", screen_name: screen_name)
end
def search(q, options = {})
options[:count] ||= 20
options[:q] = q
get("/search/tweets.json?#{options.to_query}")
end
def list_statuses(user, list, options = {})
options.reverse_update({owner_screen_name: user, slug: list})
get("/lists/statuses.json?#{options.to_query}")
end
TwitterOAuth::Client.__send__(:prepend, api_v1_1)
end
end
Earthquake.init do
command :search_tweets do |m|
search_options = config[:search_options] ? config[:search_options].dup : {}
words = m[1].shellsplit.map{|x|
case x
when /^from:(.+)/, /^to:(.+)/
$1
when /^-/, "AND", "OR"
else
x
end
}.compact
puts_items twitter.search(m[1], search_options)["statuses"].each{|s|
s["_disable_cache"] = true
s["_highlights"] = words
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment