Skip to content

Instantly share code, notes, and snippets.

@ainame
Created December 27, 2011 21:34
Show Gist options
  • Select an option

  • Save ainame/1525232 to your computer and use it in GitHub Desktop.

Select an option

Save ainame/1525232 to your computer and use it in GitHub Desktop.
インタプリタ上でTwitterのgemが使いやすくするためのラッパー
require 'twitter'
require 'json'
module MyTwitter
def self.activate
@config = JSON.parse(open("settings.json").read)
Twitter.configure do |config|
config.consumer_key = @config["consumer_key"]
config.consumer_secret = @config["consumer_secret"]
config.oauth_token = @config["oauth_token"]
config.oauth_token_secret = @config["oauth_token_secret"]
end
end
def self.twitter
if @twitter
return @twitter
else
self.activate
return @twitter = Twitter::Client.new
end
end
def self.search(query, options = { lang: "ja", locale: "ja"})
response = self.twitter.search(query, options)
data = Array.new
response.each do |tweet|
data << tweet["text"]
end
return data
end
def self.search_raw(query, options)
self.twitter.search(query, options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment