<commit_before>require "sinatra/base"
require "digest/md5"
require "json"
require "shnotes"

module Shnotes
  class App < Sinatra::Base
    include Helpers

    class << self
      attr_accessor :notes
    end

    @notes = Shnotes::Notes.new

    get "/" do
      App.notes.all_notes.to_json
    end

    get "/:id" do
      note = App.notes.all_notes[params[:id]]
      not_found "No such note" unless note
      note.to_json
    end

    post "/" do
      note = params[:note]
      error 400, "No note" unless note
      note.strip!
      error 400, "Not a valid note" if blank? note
      id = Digest::MD5.hexdigest(note)
      App.notes.put_note(id, note)<commit_msg>Return appropriate content type for responses<commit_after>require "sinatra/base"
require "digest/md5"
require "json"
require "shnotes"

module Shnotes
  class App < Sinatra::Base
    include Helpers

    class << self
      attr_accessor :notes
    end

    @notes = Shnotes::Notes.new

    before do
      content_type :json, :charset => "utf-8"
    end

    get "/" do
      App.notes.all_notes.to_json
    end

    get "/:id" do
      note = App.notes.all_notes[params[:id]]
      not_found "No such note" unless note
      note.to_json
    end

    post "/" do
      note = params[:note]
      error 400, "No note" unless note
      note.strip!
      error 400, "Not a valid note" if blank? note
      id = Digest::MD5.hexdigest(note)
      App.notes.put_note(id, note)
{'fraction_non_alphanumeric': 0.1050449205252246, 'fraction_numerical': 0.011748445058742226, 'mean_word_length': 2.4312796208530805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, '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': '4288919', 'n_tokens_mistral': 505, 'n_tokens_neox': 473, 'n_words': 137}