<commit_before>require 'active_support'
require 'active_support/core_ext/array/conversions.rb' # so we can use to_sentence

class Profile
  include ActiveModel::Validations

  VALID_ENDPOINTS = {
    standard: '/silent/pay',
    create_payment_token: '/silent/token/create',
    update_payment_token: '/silent/token/update',
    iframe_standard: '/silent/embedded/pay',
    iframe_create_payment_token: 'silent/embedded/token/create',
    iframe_update_payment_token: '/silent/embedded/token/update'
  }

  attr_reader :profile_id, :name, :service, :access_key, :secret_key, :success_url,
              :transaction_type, :endpoint_type
  validates_presence_of :profile_id, :name, :service, :access_key, :secret_key, :success_url
  validates_inclusion_of :service, :in => %w(test live), allow_nil: false
  validates_inclusion_of :endpoint_type, :in => VALID_ENDPOINTS.keys, allow_nil: false

  def initialize(profile_id, profiles = CYBERSOURCE_PROFILES)
    @profile_id = profile_id
    @name = profiles[profile_id]['name']
    @service = profiles[profile_id]['service']
    @access_key = profiles[profile_id]['access_key']
    @secret_key = profiles[profile_id]['secret_key']
    @success_url = profiles[profile_id]['success_url']
    @transaction_type = profiles[profile_id]['transaction_type']
    @endpoint_type = profiles[profile_id]['endpoint_type'].to_sym

    unless self.valid?
      raise Exceptions::CybersourceryError, self.errors.full_messages.to_sentence
    end
  end

  def transaction_url(env = Rails.env)
    if env == 'test'
      "#{SORCERY_URL}#{VALID_ENDPOINTS[@endpoint_type]}"
    elsif @service == 'live'
      "https://secureacceptance.cybersource.com#{VALID_ENDPOINTS[@endpoint_type]}"
    elsif @service == 'test'
      "https://testsecureacceptance.cybersource.com#{VALID_ENDPOINTS[@endpoint_type]}"
    else<commit_msg>use a loop to assign all the instance variables from the config data<commit_after>require 'active_support'
require 'active_support/core_ext/array/conversions.rb' # so we can use to_sentence

class Profile
  include ActiveModel::Validations

  VALID_ENDPOINTS = {
    standard: '/silent/pay',
    create_payment_token: '/silent/token/create',
    update_payment_token: '/silent/token/update',
    iframe_standard: '/silent/embedded/pay',
    iframe_create_payment_token: 'silent/embedded/token/create',
    iframe_update_payment_token: '/silent/embedded/token/update'
  }

  attr_accessor :profile_id, :name, :service, :access_key, :secret_key, :success_url,
              :transaction_type, :endpoint_type
  validates_presence_of :profile_id, :name, :service, :access_key, :secret_key, :success_url
  validates_inclusion_of :service, :in => %w(test live), allow_nil: false
  validates_inclusion_of :endpoint_type, :in => VALID_ENDPOINTS.keys, allow_nil: false

  def initialize(profile_id, profiles = CYBERSOURCE_PROFILES)
    profiles[profile_id].each do |k,v|
      self.send "#{k}=", v
    end

    @profile_id = profile_id
    @endpoint_type = @endpoint_type.to_sym

    unless self.valid?
      raise Exceptions::CybersourceryError, self.errors.full_messages.to_sentence
    end
  end


  def transaction_url(env = Rails.env)
    if env == 'test'
      "#{SORCERY_URL}#{VALID_ENDPOINTS[@endpoint_type]}"
    elsif @service == 'live'
      "https://secureacceptance.cybersource.com#{VALID_ENDPOINTS[@endpoint_type]}"
    elsif @service == 'test'
      "https://testsecureacceptance.cybersource.com#{VALID_ENDPOINTS[@endpoint_type]}"
    else
{'fraction_non_alphanumeric': 0.11934745277618775, 'fraction_numerical': 0.0, 'mean_word_length': 4.923728813559322, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '75324', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1151, 'n_words': 202}