<commit_before>module Neighborly::Balanced
  class Customer
    def initialize(user, request_params)
      @user = user
      @request_params = request_params
    end

    def fetch
      current_customer_uri = @user.balanced_contributor.try(:uri)
      @customer          ||= if current_customer_uri
                               ::Balanced::Customer.find(current_customer_uri)
                             else
                               create_on_balanced
                             end
    end

    def update!
      fetch.name    = user_params.try(:[], :name)
      fetch.address = { line1:         user_params.try(:[], :address_street),
                         city:         user_params.try(:[], :address_city),
                         state:        user_params.try(:[], :address_state),
                         postal_code:  user_params.try(:[], :address_zip_code)
                       }
      fetch.save

      if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include? user_params.try(:delete, :update_address)
        @user.update!(user_params.try(:delete!, 'name'))
      end
    end

    private
    def create_on_balanced
      customer = ::Balanced::Customer.new(meta:    { user_id: @user.id },
                                          name:    @user.display_name,
                                          email:   @user.email,
                                          address: {
                                            line1:        @user.address_street,
                                            city:         @user.address_city,
                                            state:        @user.address_state,<commit_msg>Rename create_on_balanced method to create!<commit_after>module Neighborly::Balanced
  class Customer
    def initialize(user, request_params)
      @user = user
      @request_params = request_params
    end

    def fetch
      current_customer_uri = @user.balanced_contributor.try(:uri)
      @customer          ||= if current_customer_uri
                               ::Balanced::Customer.find(current_customer_uri)
                             else
                               create!
                             end
    end

    def update!
      fetch.name    = user_params.try(:[], :name)
      fetch.address = { line1:         user_params.try(:[], :address_street),
                         city:         user_params.try(:[], :address_city),
                         state:        user_params.try(:[], :address_state),
                         postal_code:  user_params.try(:[], :address_zip_code)
                       }
      fetch.save

      if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include? user_params.try(:delete, :update_address)
        @user.update!(user_params.try(:delete!, 'name'))
      end
    end

    private
    def create!
      customer = ::Balanced::Customer.new(meta:    { user_id: @user.id },
                                          name:    @user.display_name,
                                          email:   @user.email,
                                          address: {
                                            line1:        @user.address_street,
                                            city:         @user.address_city,
                                            state:        @user.address_state,
{'fraction_non_alphanumeric': 0.08962829736211031, 'fraction_numerical': 0.001199040767386091, 'mean_word_length': 1.2172757475083056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2546351', 'n_tokens_mistral': 798, 'n_tokens_neox': 774, 'n_words': 141}