<commit_before>class SpiritHTTPServer < Sinatra::Base
  get '/devices' do
    content_type :json
    devices = spirit.devices
    serializer = ActiveModel::ArraySerializer.new(devices, each_serializer: DeviceSerializer)
    serializer.to_json
  end

  get '/devices/:id' do
    content_type :json
    device = Device.read(params[:id])
    serializer = DeviceSerializer.new(device)
    serializer.to_json
  end

  put '/devices/:id' do
    json = JSON.parse(request.body.read)
    device = Device.read(params[:id])
    adapter = device.device_adapter
    device.update_attributes(json.fetch('state', {}))
    adapter.apply(device)
  end

  get '/presets' do
    content_type :json
    presets = spirit.presets
    serializer = ActiveModel::ArraySerializer.new(presets, each_serializer: PresetSerializer)
    serializer.to_json
  end

  get '/presets/:id' do
    content_type :json
    device = Preset.read(params[:id])
    serializer = PresetSerializer.new(device)
    serializer.to_json
  end

  get '/adapters' do
    content_type :json
    adapters = Adapter::Base.all
    serializer = ActiveModel::ArraySerializer.new(adapters, each_serializer: AdapterSerializer)
    serializer.to_json
  end
  def spirit
    settings.spirit
  end
end<commit_msg>Add individual adapter to http api server<commit_after>class SpiritHTTPServer < Sinatra::Base
  get '/devices' do
    content_type :json
    devices = spirit.devices
    serializer = ActiveModel::ArraySerializer.new(devices, each_serializer: DeviceSerializer)
    serializer.to_json
  end

  get '/devices/:id' do
    content_type :json
    device = Device.read(params[:id])
    serializer = DeviceSerializer.new(device)
    serializer.to_json
  end

  put '/devices/:id' do
    json = JSON.parse(request.body.read)
    device = Device.read(params[:id])
    adapter = device.device_adapter
    device.update_attributes(json.fetch('state', {}))
    adapter.apply(device)
  end

  get '/presets' do
    content_type :json
    presets = spirit.presets
    serializer = ActiveModel::ArraySerializer.new(presets, each_serializer: PresetSerializer)
    serializer.to_json
  end

  get '/presets/:id' do
    content_type :json
    device = Preset.read(params[:id])
    serializer = PresetSerializer.new(device)
    serializer.to_json
  end

  get '/adapters' do
    content_type :json
    adapters = Adapter::Base.all
    serializer = ActiveModel::ArraySerializer.new(adapters, each_serializer: AdapterSerializer)
    serializer.to_json
  end

  get '/adapters/:id' do
    content_type :json
    device = Adapter::Base.read(params[:id])
    serializer = AdapterSerializer.new(device)
    serializer.to_json
  end

  def spirit
    settings.spirit
  end
end
{'fraction_non_alphanumeric': 0.09929603556872917, 'fraction_numerical': 0.0, 'mean_word_length': 3.679376083188908, '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': '7374168', 'n_tokens_mistral': 852, 'n_tokens_neox': 839, 'n_words': 178}