ike18t/spotify_jukebox

View on GitHub
app/web_helper.rb

Summary

Maintainability
A
0 mins
Test Coverage
module WebHelper
  IMAGE_URL_FORMAT = 'https://d3rt1990lpmkn.cloudfront.net/640/%s'.freeze

  class << self
    def get_playlist_id_and_user_id_from_url(url)
      match_data = url.match /^.*user\/(.*)\/playlist\/(.*)$/
      { user_id: match_data[1], playlist_id: match_data[2] }
    end

    def create_playlist_uri(playlist_id, owner_id)
      uri_format = 'spotify:user:%s:playlist:%s'
      uri_format % [owner_id, playlist_id]
    end

    def track_info_to_json(track, user)
      { current_track: { name: track.name,
                         artists: track.artists.join(', '),
                         album: track.album.name,
                         image: WebHelper::IMAGE_URL_FORMAT % track.album.art_hex },
        current_user: { id: user.id, name: user.name, avatar_url: user.image_url } }.to_json.to_s
    end
  end
end