<commit_before>require 'sinatra'
require "sinatra/json"
require "sinatra/namespace"

class Spotbot::Web < Sinatra::Base
  helpers Sinatra::JSON
  register Sinatra::Namespace

  attr_reader :player, :queue, :playlist

  def initialize(player)
    @queue = Spotbot::Queue.instance
    @playlist = Spotbot::Playlist.instance
    @player = player
    super()
  end

  before do
    content_type 'application/json'
  end

  namespace '/queue' do
    get '/tracks' do
      json queue.all.map(&:as_json)
    end

    post '/tracks' do
      track = queue.add(params[:uri])
      json track.as_json
    end

    delete '' do
      queue.clear
      json []
    end
  end

  namespace '/player' do
    put '/stop' do
      player.pause
      json :ok
    end

    put '/start' do
      player.play
      if track = player.current_track
        json track_as_json(track)
      else
        json :ok
      end
    end

    put '/next' do
      if track = player.play_next
        json track_as_json(track)
      else
        json :ok
      end
    end

    get '/track' do
      if track = player.current_track
        json track_as_json(track)
      else
        json :ok
      end
    end

    post '/track' do
      player.play(params[:uri])
      json track_as_json(params[:uri])
    end
  end

  namespace '/playlist' do
    get '' do
      json playlist.name
    end

    post '' do
      playlist.from_uri params[:uri]
      json playlist.name
    end

    get '/tracks' do
      json "current playlist tracks"
    end

    get '/shuffle' do
      json shuffle: playlist.shuffle?
    end

    put '/shuffle' do
      playlist.shuffle = true<commit_msg>json responses<commit_after>require 'sinatra'
require "sinatra/json"
require "sinatra/namespace"

class Spotbot::Web < Sinatra::Base
  helpers Sinatra::JSON
  register Sinatra::Namespace

  attr_reader :player, :queue, :playlist

  def initialize(player)
    @queue = Spotbot::Queue.instance
    @playlist = Spotbot::Playlist.instance
    @player = player
    super()
  end

  before do
    content_type 'application/json'
  end

  namespace '/queue' do
    get '/tracks' do
      json queue.all.map(&:as_json)
    end

    post '/tracks' do
      track = queue.add(params[:uri])
      json track.as_json
    end

    delete '' do
      queue.clear
      json []
    end
  end

  namespace '/player' do
    put '/stop' do
      player.pause
      json status: :ok
    end

    put '/start' do
      player.play
      if track = player.current_track
        json track_as_json(track)
      else
        json status: :ok
      end
    end

    put '/next' do
      if track = player.play_next
        json track_as_json(track)
      else
        json status: :ok
      end
    end

    get '/track' do
      if track = player.current_track
        json track_as_json(track)
      else
        json status: :ok
      end
    end

    post '/track' do
      player.play(params[:uri])
      json track_as_json(params[:uri])
    end
  end

  namespace '/playlist' do
    get '' do
      json playlist: playlist.name
    end

    post '' do
      playlist.from_uri params[:uri]
      json playlist: playlist.name
    end

    get '/tracks' do
      json "current playlist tracks"
    end

    get '/shuffle' do
      json shuffle: playlist.shuffle?
    end

    put '/shuffle' do
      playlist.shuffle = true
{'fraction_non_alphanumeric': 0.09012235153685468, 'fraction_numerical': 0.0, 'mean_word_length': 2.0089766606822264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '555549', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1043, 'n_words': 302}