Sha256: 61231fc15add9e3df2da8ffe214aca48aa2271d28e29929d82ff5f77ea8982d6

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

module Ebooks
  class Twitter

    def initialize(credentials = {})
      @consumer_key        = credentials.fetch(:consumer_key)
      @consumer_secret     = credentials.fetch(:consumer_secret)
      @access_token        = credentials.fetch(:oauth_token)
      @access_token_secret = credentials.fetch(:oauth_token_secret)
    end

    def twitter_client
      ::Twitter::REST::Client.new do |config|
        config.consumer_key        = @consumer_key
        config.consumer_secret     = @consumer_secret
        config.access_token        = @access_token
        config.access_token_secret = @access_token_secret
      end
    end

    def tweet(tweet_text)
      tweet_text = tweet_text.gsub('@', '')[0..139]
      p "#{Time.now}: #{tweet_text}"
      twitter_client.update(tweet_text)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ebooks-0.2.1 lib/ebooks/twitter.rb
ebooks-0.2.0 lib/ebooks/twitter.rb