Class: InternetBS::DomainRecords

Inherits:
Base
  • Object
show all
Defined in:
lib/internetbs/domain_records.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#add(dns_record) ⇒ Object



7
8
9
# File 'lib/internetbs/domain_records.rb', line 7

def add(dns_record)
  set_record :add, dns_record
end

#fetchObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/internetbs/domain_records.rb', line 11

def fetch
  ensure_attribute_has_value :domain
  return false if @errors.any?
  
  params = {'domain' => @domain}
  params.merge!({'filtertype' => @filter_type}) if @filter_type
    
  response = Client.get('/domain/dnsrecord/list', params)
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)

    @status = hash['status']
    @transaction_id = hash['transactid']
    
    if @status == 'SUCCESS'
      hash['records'].each do |record|
        @list << DomainRecord.new(
          :name  => record['name'],
          :value => record['value'],
          :ttl   => record['ttl'],
          :type  => record['type']
        )
      end
    else
      set_errors(response)
      return false
    end
    
    return true
  else
    set_errors(response)
    return false
  end
end

#remove(dns_record) ⇒ Object



49
50
51
# File 'lib/internetbs/domain_records.rb', line 49

def remove(dns_record)
  set_record :remove, dns_record
end

#update(current_dns_record, new_dns_record) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/internetbs/domain_records.rb', line 53

def update(current_dns_record, new_dns_record)
  @errors.clear
  
  unless current_dns_record.valid? && new_dns_record.valid?
    current_dns_record.each do |err|
      @errors << "current: #{err}"
    end
    
    new_dns_record.each do |err|
      @errors << "new: #{err}"
    end
    
    return false
  end
  
  params = {
    'fullrecordname' => current_dns_record.full_record_name,
    'type' => current_dns_record.type
  }

  if current_dns_record.value && dns_record.value
    params.merge!({ 
      'currentvalue' => current_dns_record.value, 
      'newvalue' => new_dns_record.value 
    })
  end
  
  if current_dns_record.ttl && \
     new_dns_record.ttl && \
     current_dns_record.ttl == new_dns_record.ttl
    params.merge!({ 
      'currentttl' => current_dns_record.ttl, 
      'newttl' => new_dns_record.ttl 
    })
  end
  
  if current_dns_record.type == 'MX' && \
     current_dns_record.priority && \
     new_dns_record.priority && 
     current_dns_record.priority == new_dns_record.priority
    params.merge!({ 
      'currentpriority' => current_dns_record.priority, 
      'newpriority' => new_dns_record.priority 
    })
  end
  
  response = Client.post("/domain/dnsrecord/update", params)
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)

    @status = hash['status']
    @transaction_id = hash['transactid']
    
    unless @status == 'SUCCESS'
      set_errors(response)
      return false
    end
    
    return true
  else
    set_errors(response)
    return false
  end
end