zerigo_dns 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/zerigo_dns.rb +34 -2
  2. data/spec/lib/host_spec.rb +27 -0
  3. metadata +2 -1
data/lib/zerigo_dns.rb CHANGED
@@ -43,8 +43,9 @@ module Zerigo
43
43
 
44
44
 
45
45
  class Zone < Base
46
+ # Find or Create Zone
46
47
  def self.find_or_create(domain)
47
- zones = Zerigo::DNS::Zone.find(:all)
48
+ zones = find(:all)
48
49
  zone = nil
49
50
  zones.each do |z|
50
51
  if z.domain == domain
@@ -54,7 +55,7 @@ module Zerigo
54
55
  end
55
56
 
56
57
  unless zone
57
- zone = Zerigo::DNS::Zone.create(:domain=> domain, :ns_type=>'pri_sec')
58
+ zone = create(:domain=> domain, :ns_type=>'pri_sec')
58
59
  end
59
60
  zone
60
61
  end
@@ -62,6 +63,37 @@ module Zerigo
62
63
  end
63
64
 
64
65
  class Host < Base
66
+
67
+ # Update or Create Host for a zone
68
+ def self.update_or_create(zone, hostname, type, data)
69
+ hosts = find(:all)
70
+ host = nil
71
+ hosts.each do |h|
72
+ if h.hostname == hostname
73
+ host = h
74
+ break;
75
+ end
76
+ end
77
+
78
+ if host
79
+ # update
80
+ host.host_type = type
81
+ host.data = data
82
+ host.ttl = 86400
83
+ host.save
84
+ else
85
+ # creatae
86
+ host = create(
87
+ :zone_id => zone,
88
+ :hostname => hostname,
89
+ :host_type => type,
90
+ :data => data,
91
+ :ttl=>86400
92
+ )
93
+ end
94
+ host
95
+ end
96
+
65
97
  end
66
98
 
67
99
  end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Zerigo::DNS::Host.update_or_create" do
4
+
5
+ it 'should create host' do
6
+ Zerigo::DNS::Host.stub!(:find).and_return([])
7
+ Zerigo::DNS::Host.stub!(:create).and_return(:success => true)
8
+
9
+ Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10')[:success].should be_true
10
+ end
11
+
12
+ it 'should update host' do
13
+ jackhq = mock('Zerigo::DNS::Host')
14
+ jackhq.stub!(:hostname).and_return('www')
15
+ jackhq.stub!(:host_type=)
16
+ jackhq.stub!(:data=)
17
+ jackhq.stub!(:ttl=)
18
+ jackhq.stub!(:save).and_return(true)
19
+
20
+ Zerigo::DNS::Host.stub!(:find).and_return([jackhq])
21
+ Zerigo::DNS::Host.stub!(:create).and_return(:success => false)
22
+
23
+ Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10').hostname == 'www'
24
+ end
25
+
26
+
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerigo_dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Wilson
@@ -77,6 +77,7 @@ signing_key:
77
77
  specification_version: 3
78
78
  summary: Zerigo DNS Gem
79
79
  test_files:
80
+ - spec/lib/host_spec.rb
80
81
  - spec/lib/zone_spec.rb
81
82
  - spec/spec_helper.rb
82
83
  - test/helper.rb