<commit_before>require 'sinatra/base'
require 'sinatra/cookies'
require 'sinatra/json'
require 'meda'
require 'meda/collector/connection'

module Meda
  module Collector

    # Extends Sinatra:Base to create a Sinatra application implementing the collector's REST API.
    # All operations are delegated to an instance of Meda::Collector::Connection, which implements
    # the desired operation on the given dataset.
    #
    # All routes require the dataset's token to be passed in the "dataset" parameter.
    class App < Sinatra::Base

      set :public_folder, 'static'

      helpers Sinatra::Cookies
      helpers Sinatra::JSON

      # @method get_index
      # @overload get "/"
      # Says hello and gives version number. Useful only to test if service is installed.
      get '/' do
        "Meda version #{Meda::VERSION}"
      end

      # @method get_static
      # @overload get "/static/:file"
      # Serves any files in the project's public directory, usually named "static"
      get '/static/:file' do
        path = File.join(settings.public_folder, params[:file])
        send_file(path)
      end

      # @method post_identify_json
      # @overload post "/identify.json"
      # Identifies the user, and returns a meda profile_id
      post '/identify.json', :provides => :json do
        identify_data = json_from_request
        print_out_params(identify_data)<commit_msg>Fix a duplicate profile_id problem on identify.json calls<commit_after>require 'sinatra/base'
require 'sinatra/cookies'
require 'sinatra/json'
require 'meda'
require 'meda/collector/connection'

module Meda
  module Collector

    # Extends Sinatra:Base to create a Sinatra application implementing the collector's REST API.
    # All operations are delegated to an instance of Meda::Collector::Connection, which implements
    # the desired operation on the given dataset.
    #
    # All routes require the dataset's token to be passed in the "dataset" parameter.
    class App < Sinatra::Base

      set :public_folder, 'static'

      helpers Sinatra::Cookies
      helpers Sinatra::JSON

      # @method get_index
      # @overload get "/"
      # Says hello and gives version number. Useful only to test if service is installed.
      get '/' do
        "Meda version #{Meda::VERSION}"
      end

      # @method get_static
      # @overload get "/static/:file"
      # Serves any files in the project's public directory, usually named "static"
      get '/static/:file' do
        path = File.join(settings.public_folder, params[:file])
        send_file(path)
      end

      # @method post_identify_json
      # @overload post "/identify.json"
      # Identifies the user, and returns a meda profile_id
      post '/identify.json', :provides => :json do
        identify_data = raw_json_from_request
        print_out_params(identify_data)
{'fraction_non_alphanumeric': 0.08385964912280702, 'fraction_numerical': 0.0, 'mean_word_length': 2.9985974754558207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1327934', 'n_tokens_mistral': 820, 'n_tokens_neox': 796, 'n_words': 278}