forked from anestesya/relogioDePonto
/
oclockrtwit.rb
61 lines (53 loc) · 1.96 KB
/
oclockrtwit.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class OClockrTwit
require 'oauth'
#
# inicializa a autenticação por oauth.
#
def initialize
@oclockr_oauth = { #configurações usadas para conecção
'consumer_key' => "UT84Cc0OsmOVdQaJ8zNtPA",
'consumer_secret' => "Z50TpDOHXXNhdhSv1m18DQ54zqoNtgE1c3ouWynv8",
'consumer_token' => nil,
'request_token' => nil,
'request_token_secret' => nil,
'access_token' => nil,
'access_token_scret' => nil,
'authorize_url' => nil
}
end
def consumer
OAuth::Consumer.new(
@oclockr_oauth['consumer_key'],
@oclockr_oauth['consumer_secret'],
{:site=>"https://twitter.com"}
)
end
def SetAccessToken(strToken, strSecret)
@oclockr_oauth['access_token'] = strToken
@oclockr_oauth['access_token_secret'] = strSecret
end
def Auth
oAuth = Twitter::OAuth.new(@oclockr_oauth['consumer_token'], @oclockr_oauth['consumer_secret'])
oAuth.autorize_from_access(@oclockr_oauth['access_token'], @oclockr_oauth['access_secret'])
oAuth
end
def twitter_oauth_login
url = "http://localhost:3000/"
request_token = consumer.get_request_token(:oauth_callback => url)
@oclockr_oauth['request_token'] = request_token.token
@oclockr_oauth['request_token_secret'] = request_token.secret
@oclockr_oauth['authorize_url'] = request_token.authorize_url
end
def twitter_oauth_access
request_token = OAuth::RequestToken.new(
consumer, @oclockr_oauth['request_token'],
@oclockr_oauth['request_token_secret']
)
access_token = request_token.get_access_token(:oauth_verifier => @oclockr_oauth['authorize_url'])
SetAccessToken(access_token.token, access_token.secret)
end
def getTimeline
resposta = consumer.request(:get, 'account/verify_credentials.json',
twitter_oauth_access, {:scheme => :query_string})
end
end