<commit_before>require 'httparty'

class VatNumberValidator < ActiveModel::EachValidator
  require 'vat_number_validator/configuration'
  require 'vat_number_validator/errors'

  def validate_each(record, attribute, value)
    unless valid?(value)
      record.errors.add(attribute, :incorrect_vat_number_format)
    end
  end

  private

  def base_uri
    use_https = Configuration.use_https
    protocol = use_https ? 'https' : 'http'
    "#{protocol}://apilayer.net/api"
  end

  def valid?(value)
    result = HTTParty.get(base_uri + '/validate', http_options(value))
    raise(APIError.new(result)) if result['success'] == false
    result['valid']
  end

  def http_options(value)
    {
      query: {
        access_key: Configuration.access_key,
        vat_number: value
      }
    }
  end
end<commit_msg>no reason to use local variable here<commit_after>require 'httparty'

class VatNumberValidator < ActiveModel::EachValidator
  require 'vat_number_validator/configuration'
  require 'vat_number_validator/errors'

  def validate_each(record, attribute, value)
    unless valid?(value)
      record.errors.add(attribute, :incorrect_vat_number_format)
    end
  end

  private

  def base_uri
    protocol = Configuration.use_https ? 'https' : 'http'
    "#{protocol}://apilayer.net/api"
  end

  def valid?(value)
    result = HTTParty.get(base_uri + '/validate', http_options(value))
    raise(APIError.new(result)) if result['success'] == false
    result['valid']
  end

  def http_options(value)
    {
      query: {
        access_key: Configuration.access_key,
        vat_number: value
      }
    }
  end
end
{'fraction_non_alphanumeric': 0.10497237569060773, 'fraction_numerical': 0.0, 'mean_word_length': 3.6045197740112993, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2238294', 'n_tokens_mistral': 524, 'n_tokens_neox': 515, 'n_words': 105}