<commit_before>class GoogleAccount
  attr_reader :email

  class GoogleAppsAPIError < RuntimeError; end

  def initialize(email)
    @email = email
  end

  def exists?
    result = api.execute(
      api_method: directory.users.get,
      # This will find by primary email or aliases according to Google's documentation
      parameters: {userKey: full_email}
    )

    return false unless result.success?

    result.data.emails.map{|e| e['address']}.include? full_email
  end

  def available?
    !exists?
  end

  def create_or_update!(first_name, last_name, department, title, privacy)
    if exists?
      update! first_name, last_name, department, title, privacy
      :update
    else
      create! first_name, last_name, department, title, privacy
      :create
    end
  end

  def create!(first_name, last_name, department, title, privacy)
    params = {
      primaryEmail: full_email,
      password: <PASSWORD>,
      name: {
        familyName: last_name,
        givenName: first_name
      },
      organizations: [
        department: department,
        title: title
      ],
      includeInGlobalAddressList: !privacy
    }

    new_user = directory.users.insert.request_schema.new(params)

    result = api.execute api_method: directory.users.insert, body_object: new_user
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?

    true
  end

  def update!(first_name, last_name, department, title, privacy)
    params = {
      name: {
        givenName: first_name,
        familyName: last_name
      },
      organizations: [
        department: department,
        title: title
      ],
      includeInGlobalAddressList: !privacy
    }

    user_updates = directory.users.update.request_schema.new(params)

    result = api.execute api_method: directory.users.update, parameters: {userKey: full_email}, body_object: user_updates
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?

    true
  end

  def exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    result = api.execute( api_method: directory.members.get, parameters: {groupKey: group, memberKey: full_email} )
    return result.success?
  end

  def join!(group, role = 'MEMBER')
    return false unless exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    params = {email: full_email, role: role}

    new_member = directory.members.insert.request_schema.new(params)

    result = api.execute api_method: directory.members.insert, parameters: {groupKey: group}, body_object: new_member
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?
    return true if result.succes?
  end

  def leave!(group)
    return false if exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    result = api.execute api_method: directory.members.delete, parameters: {groupKey: group, memberKey: full_email}
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?
    return true if result.success?
  end

  def full_email
    GoogleAccount.full_email(email)
  end

  def self.full_email(email)
    if email.include? '@'
      email
    else
      "#{email}@#{Settings.google.domain}"
    end<commit_msg>Reverse the return false conditionals<commit_after>class GoogleAccount
  attr_reader :email

  class GoogleAppsAPIError < RuntimeError; end

  def initialize(email)
    @email = email
  end

  def exists?
    result = api.execute(
      api_method: directory.users.get,
      # This will find by primary email or aliases according to Google's documentation
      parameters: {userKey: full_email}
    )

    return false unless result.success?

    result.data.emails.map{|e| e['address']}.include? full_email
  end

  def available?
    !exists?
  end

  def create_or_update!(first_name, last_name, department, title, privacy)
    if exists?
      update! first_name, last_name, department, title, privacy
      :update
    else
      create! first_name, last_name, department, title, privacy
      :create
    end
  end

  def create!(first_name, last_name, department, title, privacy)
    params = {
      primaryEmail: full_email,
      password: <PASSWORD>,
      name: {
        familyName: last_name,
        givenName: first_name
      },
      organizations: [
        department: department,
        title: title
      ],
      includeInGlobalAddressList: !privacy
    }

    new_user = directory.users.insert.request_schema.new(params)

    result = api.execute api_method: directory.users.insert, body_object: new_user
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?

    true
  end

  def update!(first_name, last_name, department, title, privacy)
    params = {
      name: {
        givenName: first_name,
        familyName: last_name
      },
      organizations: [
        department: department,
        title: title
      ],
      includeInGlobalAddressList: !privacy
    }

    user_updates = directory.users.update.request_schema.new(params)

    result = api.execute api_method: directory.users.update, parameters: {userKey: full_email}, body_object: user_updates
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?

    true
  end

  def exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    result = api.execute( api_method: directory.members.get, parameters: {groupKey: group, memberKey: full_email} )
    return result.success?
  end

  def join!(group, role = 'MEMBER')
    return false if exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    params = {email: full_email, role: role}

    new_member = directory.members.insert.request_schema.new(params)

    result = api.execute api_method: directory.members.insert, parameters: {groupKey: group}, body_object: new_member
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?
    return true if result.succes?
  end

  def leave!(group)
    return false unless exists_in_group?(group)
    group = GoogleAccount.group_to_email(group)
    result = api.execute api_method: directory.members.delete, parameters: {groupKey: group, memberKey: full_email}
    raise GoogleAppsAPIError, result.data['error']['message'] unless result.success?
    return true if result.success?
  end

  def full_email
    GoogleAccount.full_email(email)
  end

  def self.full_email(email)
    if email.include? '@'
      email
    else
      "#{email}@#{Settings.google.<EMAIL>}"
    end
{'fraction_non_alphanumeric': 0.0955287654509385, 'fraction_numerical': 0.0, 'mean_word_length': 3.4016118200134318, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '314787', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1916, 'n_words': 477}