class NamecheapApi::Response

Attributes

raw_body[RW]

Public Class Methods

new(body) click to toggle source
# File lib/namecheap_api/response.rb, line 7
def initialize(body)
  @raw_body = body
end

Public Instance Methods

command() click to toggle source
# File lib/namecheap_api/response.rb, line 11
def command
  doc.css('RequestedCommand').text
end
doc() click to toggle source
# File lib/namecheap_api/response.rb, line 21
def doc
  @doc ||= Nokogiri::XML(raw_body)
end
results() click to toggle source
# File lib/namecheap_api/response.rb, line 15
def results
  doc.css('CommandResponse > *').map do |result|
    clean_hash_keys(result.to_h)
  end
end

Private Instance Methods

clean_hash_keys(hash) click to toggle source
# File lib/namecheap_api/response.rb, line 27
def clean_hash_keys(hash)
  hash.map do |key, value|
    clean_key = key
      .gsub(/(?:([A-Za-z\d])|^)()(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
      .chop
      .downcase.to_sym
    { clean_key => value }
  end.inject(:merge)
end