Sha256: a6e4c3faf5ac729c5f2aa0952e2b79f256536600d6a63e42ee0de9b02a2f24f8

Contents?: true

Size: 898 Bytes

Versions: 3

Compression:

Stored size: 898 Bytes

Contents

require "twitter"
require "keyword_struct"

module Lita
  module Handlers
    class Tweet < Handler

      Account = KeywordStruct.new(:username, :token, :secret, :config, :last_tweet) do
        def tweet(text)
          client.update(text)
        end

        def untweet
          last_tweet ? client.destroy_status(last_tweet) : false
        end

        def lookup_username!
          client.user.screen_name.tap do |username|
            self.username = username
          end
        end

      private

        def client
          return nil unless config && token && secret

          @client ||= ::Twitter::REST::Client.new do |c|
            c.consumer_key        = config.consumer_key
            c.consumer_secret     = config.consumer_secret
            c.access_token        = token
            c.access_token_secret = secret
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lita-tweet-0.4.2 lib/lita/handlers/tweet/account.rb
lita-tweet-0.4.1 lib/lita/handlers/tweet/account.rb
lita-tweet-0.4.0 lib/lita/handlers/tweet/account.rb