Skip to content

Instantly share code, notes, and snippets.

@clicube

clicube/1 server.rb

Last active Aug 29, 2015
Embed
What would you like to do?
require 'yaml'
require 'twitter'
#OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
CONFIG_FILE = File.dirname(__FILE__) + "/config.yaml"
config_data = YAML.load_file(CONFIG_FILE)
stream_client = Twitter::Streaming::Client.new do |config|
config.consumer_key = config_data['consumer_key']
config.consumer_secret = config_data['consumer_secret']
config.access_token = config_data['access_token']
config.access_token_secret = config_data['access_token_secret']
end
rest_client = Twitter::REST::Client.new do |config|
config.consumer_key = config_data['consumer_key']
config.consumer_secret = config_data['consumer_secret']
config.access_token = config_data['access_token']
config.access_token_secret = config_data['access_token_secret']
end
stream_client.user do |object|
next unless object.is_a?(Twitter::Tweet)
next unless object.in_reply_to_screen_name == "sort_rb"
text = object.text.dup
text.gsub!(/@[A-Za-z0-9_]+ /, "")
text.gsub!(/https?:\/\/[^ ]+/, "")
text = text.split(//).sort.join.strip
reply = "@#{object.user.screen_name} #{text}"
rest_client.update(reply, { in_reply_to_status: object })
end
consumer_key: xxxxxxxx
consumer_secret: xxxxxxxx
access_token: xxxxxxxx
access_token_secret: xxxxxxxx
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

を不要にするためには、

# apt-get install ca-certificates

とする。(Windowsはわかりません)

consumer_key などは、 https://apps.twitter.com で確認。 (実際に使うアカウントでログインしよう)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.