<commit_before>module Chaindrive
  class APIv1 < Grape::API
    version 'v1'

    namespace :webhook do
      namespace :gears do
        desc "Webhook for GitHub push-hook requests."
        post do
          error!('Bad Request', 400) unless params[:payload]
          payload = JSON.parse(params[:payload])
        end
      end
    end

    namespace :users do
      get do
        compare_etag(Time.now.day)        
        present User.all
      end

      get ':id' do
        compare_etag(Time.now.day)
        present User.first(:name => params[:id])
      end

      get ':id/gears' do
        compare_etag(Time.now.day)
        present User.first(:name => params[:id]).gears.all
      end
    end
    
    namespace :gears do
      desc "Return all gears inside the registry."
      get do
        compare_etag(Time.now.day)
        present Gear.all
      end

      desc "Return the Gear with specified `id`."
      get ':id' do
        compare_etag(Time.now.day)
        Gear.def_dataset_method(:by_created_at){reverse_order(:created_at)}
        gear = Gear.by_created_at.first(:name => params[:id])
        present gear
        gear.hit!
      end

      get ':id/:version' do
        compare_etag(Time.now.day)
        Gear.def_dataset_method(:by_created_at){reverse_order(:created_at)}
        gear = Gear.by_created_at.where(:name => params[:id], :version => params[:version])
        present gear
        gear.hit!
      end

      post do
        authenticate!
        error!('Bad Request', 400) unless params[:id]
        error!('Found', 302) if Gear.exists?(params[:id])
      end

    end
  end
end
<commit_msg>Add some proper 404 errors as necessary.<commit_after>module Chaindrive
  class APIv1 < Grape::API
    version 'v1'

    namespace :webhook do
      namespace :gears do
        desc "Webhook for GitHub push-hook requests."
        post do
          error!('Bad Request', 400) unless params[:payload]
          payload = JSON.parse(params[:payload])
        end
      end
    end

    namespace :users do
      get do
        compare_etag(Time.now.day)        
        present User.all
      end

      get ':id' do
        compare_etag(Time.now.day)

        user = User.first(:name => params[:id])

        error!('Not Found', 404) unless user

        present user
      end

      get ':id/gears' do
        compare_etag(Time.now.day)

        user = User.first(:name => params[:id]).eager(:gears)

        error!('Not Found', 404) unless user

        present user.gears.all
      end
    end
    
    namespace :gears do
      desc "Return all gears inside the registry."
      get do
        compare_etag(Time.now.day)
        present Gear.all
      end

      desc "Return the Gear with specified `id`."
      get ':id' do
        compare_etag(Time.now.day)

        Gear.def_dataset_method(:by_created_at){reverse_order(:created_at)}
        gear = Gear.by_created_at.first(:name => params[:id])

        error!('Not Found', 404) unless gear

        gear.hit!
        present gear
      end

      get ':id/:version' do
        compare_etag(Time.now.day)

        Gear.def_dataset_method(:by_created_at){reverse_order(:created_at)}
        gear = Gear.by_created_at.where(:name => params[:id], :version => params[:version])

        error!('Not Found', 404) unless gear

        gear.hit!
        present gear
      end

      post do
        authenticate!
        error!('Bad Request', 400) unless params[:id]
        error!('Found', 302) if Gear.exists?(params[:id])
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.10759672408924033, 'fraction_numerical': 0.010449025698955098, 'mean_word_length': 2.0247651579846284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '888529', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1061, 'n_words': 274}