forked from nomlab/nomrat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweetSender.rb
executable file
·42 lines (37 loc) · 979 Bytes
/
TweetSender.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
## Created : 2011/06/09 -Y.Kimura
## Modified : 2013/04/10 -Y.Kimura
## Ruby Ver : 1.8.7
## tweet string
##################
require 'rubygems'
require 'oauth'
$KCODE = "UTF8"
##################
##---------------------------------------------------TweetClass:send tweet
class TweetSender
def initialize
## [ConsumerKey,Secret,AccessToken,Secret] in this file.
## separated by "\n"
f = open( "_twitter_auth.stg" ).read
tokens = f.split("\n")
@consumer = OAuth::Consumer.new(
@CONSUMER_KEY = tokens[0],
@CONSUMER_SECRET = tokens[1],
:site => 'https://api.twitter.com'
)
@access_token = OAuth::AccessToken.new(
@consumer,
@ACCESS_TOKEN = tokens[2],
@ACCESS_TOKEN_SECRET =tokens[3]
)
end
## tweet
def send_message( string )
posted = @access_token.post(
'/1.1/statuses/update.json',
'status' => string
)
return posted
end
end