Class: Lita::Handlers::Tweet::Data
- Inherits:
-
Struct
- Object
- Struct
- Lita::Handlers::Tweet::Data
- Defined in:
- lib/lita/handlers/tweet/data.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#robot ⇒ Object
Returns the value of attribute robot.
Instance Method Summary collapse
- #account(username) ⇒ Object
- #add_account(token, secret) ⇒ Object
- #authorize_account(token, verifier) ⇒ Object
- #bot_uri(path = "") ⇒ Object
- #create_request_token(callback_path) ⇒ Object
- #get_last_tweet(username) ⇒ Object
- #remove_account(username) ⇒ Object
- #set_last_tweet(username, tweet_id) ⇒ Object
- #usernames ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config
7 8 9 |
# File 'lib/lita/handlers/tweet/data.rb', line 7 def config @config end |
#redis ⇒ Object
Returns the value of attribute redis
7 8 9 |
# File 'lib/lita/handlers/tweet/data.rb', line 7 def redis @redis end |
#robot ⇒ Object
Returns the value of attribute robot
7 8 9 |
# File 'lib/lita/handlers/tweet/data.rb', line 7 def robot @robot end |
Instance Method Details
#account(username) ⇒ Object
12 13 14 15 16 |
# File 'lib/lita/handlers/tweet/data.rb', line 12 def account(username) hash = redis.hgetall("twitter_accounts:#{username}") data = hash.each_with_object({}){|(k,v),h| h[k.to_sym] = v } Account.new(**data.merge(config: config)) end |
#add_account(token, secret) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lita/handlers/tweet/data.rb', line 18 def add_account(token, secret) account = Account.new(token: token, secret: secret, config: config) username = account.username redis.sadd("twitter_accounts", username) redis.hmset("twitter_accounts:#{username}", "username", username, "token", token, "secret", secret ) account end |
#authorize_account(token, verifier) ⇒ Object
57 58 59 60 61 |
# File 'lib/lita/handlers/tweet/data.rb', line 57 def (token, verifier) request_token = find_request_token(token) access_token = request_token.get_access_token(oauth_verifier: verifier) add_account(access_token.token, access_token.secret) end |
#bot_uri(path = "") ⇒ Object
63 64 65 |
# File 'lib/lita/handlers/tweet/data.rb', line 63 def bot_uri(path = "") base_uri + path end |
#create_request_token(callback_path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lita/handlers/tweet/data.rb', line 45 def create_request_token(callback_path) request_token = consumer.get_request_token( oauth_callback: bot_uri(callback_path).to_s) request_hash = request_token.params key = "request_token:#{request_hash[:oauth_token]}" redis.hmset(key, *request_hash.to_a.flatten) redis.expire(key, 120) request_token end |
#get_last_tweet(username) ⇒ Object
41 42 43 |
# File 'lib/lita/handlers/tweet/data.rb', line 41 def get_last_tweet(username) redis.hget("twitter_accounts:#{username}", "last_tweet") end |
#remove_account(username) ⇒ Object
32 33 34 35 |
# File 'lib/lita/handlers/tweet/data.rb', line 32 def remove_account(username) redis.del("twitter_accounts:#{username}") redis.srem("twitter_accounts", username) end |
#set_last_tweet(username, tweet_id) ⇒ Object
37 38 39 |
# File 'lib/lita/handlers/tweet/data.rb', line 37 def set_last_tweet(username, tweet_id) redis.hset("twitter_accounts:#{username}", "last_tweet", tweet_id) end |
#usernames ⇒ Object
8 9 10 |
# File 'lib/lita/handlers/tweet/data.rb', line 8 def usernames redis.smembers("twitter_accounts") end |