module Api
  module V1
    class ClientsController < Api::V1::BaseController
      respond_to :json

      def create
        @client = Client.new(client_params)
        if @client.save
          @client.send_confirmation_email
          render :json => { :success => true, :client => @client.to_json }
        else
          render :json => { :errors => @client.errors.full_messages , :status => 422}.to_json
        end
      end

      private

      # Never trust parameters from the scary internet, only allow the white list through.
      def client_params
        params.require(:client).permit(:site_name, :site_token, :site_id, :university, :department, :email, :country, :url)
      end
    end
  end
end
