module JokerDMAPI::Contact

Constants

CONTACT_ALLOWED
CONTACT_LENGTH_LIMIT
CONTACT_REQUIRED

Public Instance Methods

contact_create(fields) click to toggle source

Create new contact

Takes contact's fields as hash:

:tld

the TLD to use new contact

:name

the contact's name

:organization

the contact's organization name

:address

an array containing from one to three elements with contact's address

:city

the contact's city

:state

the contact's state

:postal_code

the contact's postal code

:country

the contact's country code (UA)

:email

the contact's email address

:phone

the contact's voice phone number

:fax

the contact's fax number

Returned is a hash of response:

:headers
:proc_id

process ID (used at check result)

:tracking_id

tracking ID

# File lib/joker-dmapi/contact.rb, line 76
def contact_create(fields)
  query :contact_create, contact_prepare(fields)
end
contact_create_result(proc_id) click to toggle source

Check result of create contact

Get proc_id Returned contact's handle name (and delete result) or nil if don't ready

# File lib/joker-dmapi/contact.rb, line 84
def contact_create_result(proc_id)
  result = parse_attributes(result_retrieve(proc_id)[:body].split("\n\n", 1)[0])
  return nil unless result.has_key? :completion_status
  case result[:completion_status]
    when 'ack' then
      result_delete proc_id
      result[:object_name]
    when 'nack' then
      raise_response response
    else
      nil
  end
end
contact_delete(handle) click to toggle source

Delete contact Takes handle

# File lib/joker-dmapi/contact.rb, line 124
def contact_delete(handle)
  query 'contact-delete', { handle: handle }
end
contact_info(handle) click to toggle source

Returns the information about a contact or nil if not exists

Takes handler as string

Returned is a hash:

:name

the contact's name

:organization

the contact's organization name

:address

an array containing from one to three elements with contact's address

:city

the contact's city

:state

the contact's state

:postal_code

the contact's postal code

:country

the contact's country code (UA)

:email

the contact's email address

:phone

the contact's voice phone number

:fax

the contact's fax number

:handle

the contact's handler from Joker

:created_date

the date and time of contact created

:modified_date

the date and time of contact modified

# File lib/joker-dmapi/contact.rb, line 27
def contact_info(handle)
  response = query_no_raise :query_whois, contact: handle
  case response[:headers][:status_code]
    when '2303' then nil
    when '0' then
      result = {}
      response[:body].split("\n").each do |line|
        line.slice! /^contact\./
        line_parsed = parse_line(line)
        next if line_parsed.is_a? String
        key, value = line_parsed.first
        case key
          when :name then next if value == "- -"
          when :address_1, :address_2, :address_3 then
            result[:address] = [] unless result.has_key? :address
            result[:address] << value
          when :state then next if value == "--"
          when :organization then next if value == "-" or value.empty?
          when :created_date, :modified_date then
            result[key] = DateTime.parse value
          else
            result.merge! line_parsed
        end
      end
      result
    else
      raise_response response
  end
end
contact_update(handle, fields) click to toggle source

Update contact

Takes handle to select contact and contact's fields as hash:

:name

the contact's name

:organization

the contact's organization name

:address

an array containing from one to three elements with contact's address

:city

the contact's city

:state

the contact's state

:postal_code

the contact's postal code

:country

the contact's country code (UA)

:email

the contact's email address

:phone

the contact's voice phone number

:fax

the contact's fax number

Returned is a hash of response:

:headers
:proc_id

process ID (used at check result)

:tracking_id

tracking ID

# File lib/joker-dmapi/contact.rb, line 116
def contact_update(handle, fields)
  fields = contact_prepare(fields)
  fields[:handle] = handle
  query 'contact-modify', fields
end

Private Instance Methods

contact_prepare(fields) click to toggle source
# File lib/joker-dmapi/contact.rb, line 130
def contact_prepare(fields)
  raise ArgumentError, "Required fields not found" unless (CONTACT_REQUIRED - fields.keys).empty?
  raise ArgumentError, "TLD must be one of accepted" unless self.tlds.include? fields[:tld]
  if CONTACT_LENGTH_LIMIT.include? fields[:tld]
    [ :name, :organization, :city, :state ].each do |field|
      next unless fields.has_key? field
      fields[field] = fields[field][0...30] # only 30 allowed
    end
    if fields.has_key? :address
      fields[:address].map! { |addr| addr[0...30] }
    end
  end
  fields = fields.keep_if { |key, value| CONTACT_ALLOWED.include? key }
  if fields.has_key? :organization and !fields[:organization].empty?
    fields[:individual] = 'No'
  else
    fields[:individual] = 'Yes'
  end
  unless fields[:address].size > 0 and fields[:address].size <= 3
    raise ArgumentError, "From one to three lines of address allowed"
  end
  (1..3).each do |index|
    fields["address-" + index.to_s] = fields[:address][index-1].nil? ? '' : fields[:address][index-1]
  end
  fields.delete :address
  fields
end