<commit_before>require 'httpclient'
module EnomApi
  def self.included(base)
    base.send :extend, ClassMethods
  end
  
  module ClassMethods
    def manage_with_enom
      send :include, InstanceMethods
    end
  end
  
  module InstanceMethods
    @@raw_config = File.read(RAILS_ROOT + "/config/enom_config.yml")
    @@enom_config = YAML.load(@@raw_config)[RAILS_ENV].symbolize_keys
    @@url = @@enom_config[:url]
    @@values = {
      'UID' => @@enom_config[:username],
      'PW' => @@enom_config[:password],
      'ResponseType' => "XML"
    }
    
    def expiration_date
      get_single_item('GetDomainExp', 'ExpirationDate').to_datetime
    end
    
    def nameservers
      get_collection_of_items('GetDNS', 'dns')
    end
    
    def nameservers=(nameservers)    
    end
    
    def registrant_contact     
    end
    
    def registrant_contact=(contact)     
    end
    
    def technical_contact     
    end
    
    def technical_contact=(contact)    
    end
    
    def administrative_contact     
    end
    
    def administrative_contact=(contact)     
    end
    
    def locked?
      get_single_item('GetRegLock', 'reg-lock') == true
    end
    
    def locked=(locked)
      set_single_item()
    end
    
    private
    
    def get_single_item(enom_command, xml_field_name)
      response = api_call(enom_command)
      REXML::XPath.first(response, "//#{xml_field_name}").text
    end
    
    def get_collection_of_items(enom_command, xml_field_name)
      response = api_call(enom_command)
      items = []
      response.elements.each("interface-response/#{xml_field_name}") { |element| 
        items << element.text
      }
      return items
    end
    
    def set_single_item(enom_command)
    
    end
    
    def set_collection_of_items(enom_command)
    
    end
    
    def api_call(enom_command)
      split = name.split('.')
      sld = split.first
      tld = split.last
      values = @@values.merge!({
        'Command' => enom_command,<commit_msg>Method dedicated to handling getting contact data (yet to be written)<commit_after>require 'httpclient'
module EnomApi
  def self.included(base)
    base.send :extend, ClassMethods
  end
  
  module ClassMethods
    def manage_with_enom
      send :include, InstanceMethods
    end
  end
  
  module InstanceMethods
    @@raw_config = File.read(RAILS_ROOT + "/config/enom_config.yml")
    @@enom_config = YAML.load(@@raw_config)[RAILS_ENV].symbolize_keys
    @@url = @@enom_config[:url]
    @@values = {
      'UID' => @@enom_config[:username],
      'PW' => @@enom_config[:password],
      'ResponseType' => "XML"
    }
    
    def expiration_date
      get_single_item('GetDomainExp', 'ExpirationDate').to_datetime
    end
    
    def nameservers
      get_collection_of_items('GetDNS', 'dns')
    end
    
    def nameservers=(nameservers)    
    end
    
    def registrant_contact
      get_contact_info_for("Registrant")
    end
    
    def registrant_contact=(contact)
      set_contact_info_for("Registrant", contact)
    end
    
    def billing_contact
      get_contact_info_for("Billing")
    end
    
    def billing_contact=(contact)
      set_contact_info_for("Billing", contact)
    end
    
    def technical_contact
      get_contact_info_for("Technical")  
    end
    
    def technical_contact=(contact)
      set_contact_info_for("Technical", contact)
    end
    
    def administrative_contact
      get_contact_info_for("Administrative")
    end
    
    def administrative_contact=(contact)
      set_contact_info_for("Administrative", contact)  
    end
    
    def locked?
      get_single_item('GetRegLock', 'reg-lock') == true
    end
    
    def locked=(locked)
      set_single_item()
    end
    
    private
    
    def get_single_item(enom_command, xml_field_name)
      response = api_call(enom_command)
      REXML::XPath.first(response, "//#{xml_field_name}").text
    end
    
    def get_collection_of_items(enom_command, xml_field_name)
      response = api_call(enom_command)
      items = []
      response.elements.each("interface-response/#{xml_field_name}") { |element| 
        items << element.text
      }
      return items
    end
    
    def get_contact_info_for(contact_type)
      
    end
    
    def set_contact_info_for(contact_type, contact_data)
      
    end
    
    def set_single_item(enom_command)
    
    end
    
    def set_collection_of_items(enom_command)
    
    end
    
    def api_call(enom_command)
      split = name.split('.')
      sld = split.first
      tld = split.last
      values = @@values.merge!({
        'Command' => enom_command,
{'fraction_non_alphanumeric': 0.09355464539771502, 'fraction_numerical': 0.0, 'mean_word_length': 2.5178165276724793, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '1823323', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1510, 'n_words': 266}