class Ejaydj::Djs::TwitterBot

Constants

MAX_ARTIST_LENGTH
MAX_SONG_LENGTH

Attributes

twitter_access_token[RW]
twitter_access_token_secret[RW]
twitter_client[RW]
twitter_consumer_key[RW]
twitter_consumer_secret[RW]

Public Class Methods

new(attributes={}, &block) click to toggle source
Calls superclass method Ejaydj::Dj::new
# File lib/ejaydj/djs/twitter_bot.rb, line 16
def initialize(attributes={}, &block)
  super(attributes, &block)
end

Public Instance Methods

tweet_me_a_song(time: Time.now) click to toggle source
# File lib/ejaydj/djs/twitter_bot.rb, line 20
def tweet_me_a_song(time: Time.now)
  @song = play_me_a_song(time: time)
  tweet = tweet_string

  twitter_client.update(tweet)
  {message: tweet, song: @song}
end

Private Instance Methods

shorten_tweet(tweet_string) click to toggle source
# File lib/ejaydj/djs/twitter_bot.rb, line 35
def shorten_tweet(tweet_string)
  return tweet_string unless tweet_string.length > 140

  @song.name    = "#{@song.name[0..MAX_SONG_LENGTH]}..." if @song.name.length > MAX_SONG_LENGTH
  @song.artist  = "#{@song.artist[0..MAX_ARTIST_LENGTH]}..." if @song.artist.length > MAX_ARTIST_LENGTH

  "NP: #{@song.name} by #{@song.artist}: #{shorten_url(@song.url)} | #{shorten_url(@song.playlist.url)}"
end
shorten_url(url) click to toggle source
# File lib/ejaydj/djs/twitter_bot.rb, line 44
def shorten_url(url)
  Googl.shorten(url).short_url
end
tweet_string() click to toggle source
# File lib/ejaydj/djs/twitter_bot.rb, line 30
def tweet_string
  tweet_string = ("NP: #{@song.name} by #{@song.artist}: #{shorten_url(@song.url)} | playlist: #{shorten_url(@song.playlist.url)}")
  shorten_tweet(tweet_string)
end