<commit_before>require "google_drive"

module Api::V1
  class SignUpUpdatesController < BaseControllerV1
    skip_before_action :verify_authenticity_token, only: [:create]

    def create
      # https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
      config = File.read(File.join(Rails.root, 'config', 'gdrive.json.erb'))
      config = JSON.parse(ERB.new(config).result(binding))
      session = GoogleDrive::Session.from_service_account_key(config)

      sheet = session.spreadsheet_by_key(ENV["DRIVE_PRIVATE_KEY_ID"]).worksheets[0]

      response = {}
      if already_added(sheet)
        response = { success: false, msg: 'Already added' }
      elsif add_new_email(sheet)
        response = { success: true, msg: 'Email added' }
      else
        response = { success: false, msg: 'Unable to save the email' }<commit_msg>Fix small issue with signing in to googledrive session and accessing spreadsheet<commit_after>require "google_drive"

module Api::V1
  class SignUpUpdatesController < BaseControllerV1
    skip_before_action :verify_authenticity_token, only: [:create]

    def create
      # https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md
      config = File.read(File.join(Rails.root, 'config', 'gdrive.json.erb'))
      config = ERB.new(config).result(binding)
      session = GoogleDrive::Session.from_service_account_key(StringIO.new(config))

      sheet = session.spreadsheet_by_key(ENV["SPREADSHEETS_ID"]).worksheets[0]

      response = {}
      if already_added(sheet)
        response = { success: false, msg: 'Already added' }
      elsif add_new_email(sheet)
        response = { success: true, msg: 'Email added' }
      else
        response = { success: false, msg: 'Unable to save the email' }
{'fraction_non_alphanumeric': 0.1146067415730337, 'fraction_numerical': 0.0033707865168539327, 'mean_word_length': 3.7367021276595747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2136401', 'n_tokens_mistral': 566, 'n_tokens_neox': 546, 'n_words': 113}