Created
December 27, 2011 21:34
-
-
Save ainame/1525232 to your computer and use it in GitHub Desktop.
インタプリタ上でTwitterのgemが使いやすくするためのラッパー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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