-
Notifications
You must be signed in to change notification settings - Fork 2
/
plurk_agent.rb
54 lines (46 loc) · 1.24 KB
/
plurk_agent.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
require 'rubygems'
require 'oauth_const'
require 'plurk'
class PlurkAgent
attr_reader :prev_id
def initialize(opt={})
if opt=={} then
opt[:consumer_key] = PLURK_APP_KEY
opt[:consumer_secret] = PLURK_APP_SECRET
end
@plurk = Plurk.new(opt)
end
def get_authorize_url(host, port)
return @plurk.authorize_url!
end
def get_access_token(verifier_or_token=nil,secret=nil)
if not verifier_or_token == nil then
if secret == nil then
@plurk.authorize!(:oauth_verifier=>verifier_or_token)
else
@plurk.oauth_token = verifier_or_token
@plurk.oauth_token_secret = secret
end
end
return {:token => @plurk.oauth_token, :secret => @plurk.oauth_token_secret}
end
def has_authorized?
res = @plurk.post("/checkToken")
return res['error_text'] ? false : true
end
def post_content(content,qualifier='says')
begin
return_content = @plurk.add_plurk(content,qualifier)
@prev_id = return_content['plurk_id']
return_content
rescue RuntimeError => err
puts err
end
end
def post_comment(content,id=@prev_id,qualifier='says')
@plurk.add_response(id,content,qualifier)
end
def attributes
return @plurk.lighten.attributes
end
end