Class: ValueDomainDdns::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/value-domain-ddns/core.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Core

Returns a new instance of Core.



7
8
9
# File 'lib/value-domain-ddns/core.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#get_ipObject



15
16
17
# File 'lib/value-domain-ddns/core.rb', line 15

def get_ip()
  open(ValueDomainDdns::GET_IP_URL).read
end

#submit_paramsObject



19
20
21
22
23
24
25
26
# File 'lib/value-domain-ddns/core.rb', line 19

def submit_params
  {
    'd' => @config[:domain],
    'p' => @config[:password],
    'h' => @config[:hostname],
    'i' => @config[:ip]
  }
end

#syncObject



28
29
30
31
32
33
34
# File 'lib/value-domain-ddns/core.rb', line 28

def sync()
  query_string = submit_params.map { |k, v|
    URI.encode(k.to_s) + '=' + URI.encode(v.to_s)
  }.join('&')
  submit_url = ValueDomainDdns::SUBMIT_BASE_URL + '?' + query_string
  open(URI.parse(submit_url)).read
end

#validateObject



11
12
13
# File 'lib/value-domain-ddns/core.rb', line 11

def validate
  !!@config[:domain] && !!@config[:password] && !!@config[:hostname]
end