module DemoTape

Constants

VERSION

Attributes

client[RW]
config[RW]

Public Class Methods

configure() { |config| ... } click to toggle source
# File lib/demo_tape.rb, line 10
def configure
  @config ||= Config.new
  yield @config

  begin
    RSpotify::authenticate @config.spotify_client_id, @config.spotify_secret
    @client ||= Twilio::REST::Client.new @config.twilio_client_id, @config.twilio_secret
  rescue Exception => e
    puts e.message
  end
end
find_artist(name:) click to toggle source
# File lib/demo_tape.rb, line 22
def find_artist(name:)
  begin
    artist = RSpotify::Artist.search(name).first

    {
      name: artist.name,
      top_track: artist.top_tracks(:US).first.name,
      image: artist.images[artist.images.count - 2],
      spotify_url: artist.external_urls["spotify"]
    }
  rescue Exception => e
    puts e.message
  end
end
send_text(number:, artist:) click to toggle source
# File lib/demo_tape.rb, line 37
def send_text(number:, artist:)
  begin
    @client.api.account.messages.create({
      from: '+18574454093', to: number,
      body: "#{artist[:name]}'s top track: #{artist[:top_track]}. Listen on Spotify! #{artist[:spotify_url]}"
    })
  rescue Exception => e
    puts e.message
  end
end