Module: JokerDMAPI::Contact

Included in:
Client
Defined in:
lib/joker-dmapi/contact.rb

Constant Summary collapse

CONTACT_REQUIRED =
[ :tld, :name, :email, :address, :city, :postal_code, :country, :phone ]
CONTACT_ALLOWED =
CONTACT_REQUIRED + [ :organization, :state, :fax ]
CONTACT_LENGTH_LIMIT =
%w(biz cn eu)

Instance Method Summary collapse

Instance Method Details

#contact_create(fields) ⇒ Object

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



76
77
78
# File 'lib/joker-dmapi/contact.rb', line 76

def contact_create(fields)
  query :contact_create, contact_prepare(fields)
end

#contact_create_result(proc_id) ⇒ Object

Check result of create contact

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



84
85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object

Delete contact Takes handle



124
125
126
# File 'lib/joker-dmapi/contact.rb', line 124

def contact_delete(handle)
  query 'contact-delete', { handle: handle }
end

#contact_info(handle) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object

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



116
117
118
119
120
# 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