<commit_before>
module Notifiable
  
  class DeviceTokensController < Notifiable.api_controller_class
    
    before_filter :ensure_current_notifiable_user, :only => :destroy
    
    def create
      @device_token = DeviceToken.find_or_create_by(:token => params[:token])
      @device_token.provider = params[:provider]
      @device_token.user_id = current_notifiable_user.id if current_notifiable_user

      if @device_token.save
        head :status => :ok
      else
        render :json => { :errors => @device_token.errors.full_messages }, :status => :internal_server_error
      end
    end

    def destroy
      @device_token = DeviceToken.where(:token => params[:token]).first
      if !@device_token
        head :status => :not_found        
      elsif !@device_token.user.eql?(current_notifiable_user)
        head :status => :unauthorized
      elsif @device_token.destroy
        head :status => :ok
      else
        render :json => { :errors => @device_token.errors.full_messages }, :status => :internal_server_error<commit_msg>Update create method in device_tokens_controller<commit_after>
module Notifiable
  
  class DeviceTokensController < Notifiable.api_controller_class
    
    before_filter :ensure_current_notifiable_user, :only => :destroy
    
    def create
      if params[:device_id]
        @device_token = DeviceToken.find_or_create_by(:device_id => params[:device_id])
        @device_token.token = params[:token]                
      else
        @device_token = DeviceToken.find_or_create_by(:token => params[:token]) 
        @device_token.device_id = params[:device_id]                       
      end
      
      @device_token.provider = params[:provider]
      @device_token.user_id = current_notifiable_user.id if current_notifiable_user

      if @device_token.save
        head :status => :ok
      else
        render :json => { :errors => @device_token.errors.full_messages }, :status => :internal_server_error
      end
    end

    def destroy
      @device_token = DeviceToken.where(:token => params[:token]).first
      if !@device_token
        head :status => :not_found        
      elsif !@device_token.user.eql?(current_notifiable_user)
        head :status => :unauthorized
      elsif @device_token.destroy
        head :status => :ok
      else
        render :json => { :errors => @device_token.errors.full_messages }, :status => :internal_server_error
{'fraction_non_alphanumeric': 0.09748038000826105, 'fraction_numerical': 0.0, 'mean_word_length': 2.9064516129032256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '251612', 'n_tokens_mistral': 692, 'n_tokens_neox': 689, 'n_words': 138}