Class: Lita::Handlers::Tweeta
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Tweeta
- Defined in:
- lib/lita/handlers/tweeta.rb
Instance Method Summary collapse
-
#initialize(robot) ⇒ Tweeta
constructor
A new instance of Tweeta.
- #tweeta(response) ⇒ Object
- #user_tweet(response) ⇒ Object
Constructor Details
#initialize(robot) ⇒ Tweeta
Returns a new instance of Tweeta.
17 18 19 20 21 22 23 24 25 |
# File 'lib/lita/handlers/tweeta.rb', line 17 def initialize(robot) super @client = Twitter::REST::Client.new do |config| config.consumer_key = Lita.config.handlers.tweeta.consumer_key config.consumer_secret = Lita.config.handlers.tweeta.consumer_secret config.access_token = Lita.config.handlers.tweeta.access_token config.access_token_secret = Lita.config.handlers.tweeta.access_token_secret end end |
Instance Method Details
#tweeta(response) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/lita/handlers/tweeta.rb', line 27 def tweeta(response) begin tweet = @client.status(response.matches.first.first.to_i) rescue Twitter::Error::NotFound return else response.reply format(tweet) end end |
#user_tweet(response) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lita/handlers/tweeta.rb', line 37 def user_tweet(response) username = response.matches.first.first if @client.user?(username) user = @client.user(username) tweets = @client.user_timeline(user, {count: 1, include_rts: false}) unless tweets.empty? response.reply format(tweets.first) end end end |