dynect 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
1
+ require 'rubygems'
2
+ gem 'soap4r'
3
+
4
+ require 'soap/rpc/driver'
5
+
6
+ class Dynect
7
+ # Provide the customer, user, and password information to intiate the SOAP connection.
8
+ # If desired, an alternate driver can be supplied to enable mocking or the use of different protocols.
9
+ def initialize(customer, user, password, driver = nil)
10
+ @driver = driver || setup_driver
11
+ @creds = {"cust" => customer, "user" => user, "pass" => password }
12
+
13
+ add_methods
14
+ end
15
+
16
+ # Lists the zones associated with the accout. Specify a zone to get information on a specific one
17
+ def list_zones(zone = nil)
18
+ args = @creds
19
+ args["zone"] = zone if zone
20
+
21
+ response = @driver.ZoneGet args
22
+ check_for_errors("when listing zone(s)", response)
23
+ response.zones
24
+ end
25
+
26
+ # Create a new zone
27
+ def create_zone(zone, type, options ={})
28
+ args = @creds.merge("zone" => zone, "type" => type)
29
+ args.merge!(options)
30
+
31
+ response = @driver.ZoneAdd args
32
+ check_for_errors("when creating a zone", response)
33
+ end
34
+
35
+ # Lists all the A records associated with the account.
36
+ #
37
+ # == Options
38
+ # * +node+ -- The fully qualified domain name of the node to retreive records from. Omit or enter an empty string to get the records of the root node
39
+ # * +record_id+ -- The ID of the record to retreive information of
40
+ #
41
+ # == Useage
42
+ #
43
+ # d = Dynect.new("customer", "username", "password")
44
+ # d.list_a_records("myzone.domain.com")
45
+ #
46
+ def list_a_records(zone, options ={})
47
+ args = @creds.merge("type" => "A", "zone" => zone)
48
+ args.merge!(options)
49
+
50
+ response = @driver.RecordGet args
51
+ check_for_errors("when listing records", response)
52
+ response.records
53
+ end
54
+
55
+ def add_a_record(zone, address, options = {})
56
+ args = @creds.merge("type" => "A", "zone" => zone, "rdata" => {"address" => address})
57
+ args.merge!(options)
58
+
59
+ response = @driver.RecordAdd args
60
+ check_for_errors("when adding an A record", response)
61
+ end
62
+
63
+ # Updates A records identified by the ID
64
+ def update_a_record(id, options = {})
65
+ args = @creds.merge("record_id" => id)
66
+ args.merge!(options)
67
+
68
+ response = @driver.RecordUpdate args
69
+ check_for_errors("when updating an A record", response)
70
+ end
71
+
72
+ # Deletes an A record identified by the ID
73
+ def delete_a_record(id)
74
+ response = @driver.RecordDelete @creds.merge("record_id" => id)
75
+ check_for_errors("when removing an A record", response)
76
+ end
77
+
78
+ # Lists the CNAME records associated with an account
79
+ def list_cname_records(zone, options ={})
80
+ args = @creds.merge("type" => "CNAME", "zone" => zone)
81
+ args.merge!(options)
82
+
83
+ response = @driver.RecordGet args
84
+ check_for_errors("when listing CNAME records", response)
85
+ response.records
86
+ end
87
+
88
+ # Adds a CNAME record for the specified zone
89
+ def add_cname_record(zone, hostname, options = {} )
90
+ args = @creds.merge("type" => "CNAME", "zone" => zone, "rdata" => {"cname" => hostname})
91
+ args.merge!(options)
92
+
93
+ response = @driver.RecordAdd args
94
+ check_for_errors("when adding a CNAME record", response)
95
+ end
96
+
97
+ def update_cname_record(id, options = {})
98
+ args = @creds.merge("id" => id)
99
+ args.merge!(options)
100
+
101
+ response = @driver.RecordUpdate args
102
+ check_for_errors("when updating a CNAME record", response)
103
+ end
104
+
105
+ def delete_cname_record(id)
106
+ response = @driver.RecordDelete @creds.merge("record_id" => id)
107
+ check_for_errors("when removing a CNAME record", response)
108
+ end
109
+
110
+ def update_soa(id, options = {})
111
+ args = @creds.merge("record_id" => id)
112
+ args.merge!(options)
113
+
114
+ response = @driver.RecordUpdate args
115
+ check_for_errors("when updating a SOA record", response)
116
+ end
117
+
118
+ def list_soa(zone, options = {})
119
+ args = @creds.merge("type" => "SOA", "zone" => zone)
120
+ args.merge!(options)
121
+
122
+ response = @driver.RecordGet args
123
+ check_for_errors("when listing SOA records", response)
124
+ response.records.first
125
+ end
126
+
127
+ private
128
+
129
+ def check_for_errors(message, response)
130
+ if response["errors"]
131
+ raise "#{message}, you got this error: #{response["errors"]["action"]}" unless response["errors"]["action"].nil?
132
+ end
133
+ response
134
+ end
135
+
136
+ def setup_driver
137
+ SOAP::RPC::Driver.new('https://api.dynect.net/soap/', '/DynectAPI/')
138
+ end
139
+
140
+ def add_methods
141
+ @driver.add_method("ZoneGet", "args")
142
+ @driver.add_method("ZoneAdd", "args")
143
+ @driver.add_method("RecordGet", "args")
144
+ @driver.add_method("RecordAdd", "args")
145
+ @driver.add_method("RecordUpdate", "args")
146
+ @driver.add_method("RecordDelete", "args")
147
+ end
148
+
149
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../lib/dynect.rb'
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe Dynect, "when used to manage A records" do
5
+
6
+ before(:each) do
7
+ @driver = mock("driver")
8
+ @driver.should_receive(:add_method).at_least(:once)
9
+
10
+ @d = Dynect.new("customer", "username", "password", @driver)
11
+
12
+ @result = mock("test")
13
+ @result.stub!(:errors).and_return(false)
14
+ @result.stub!(:[])
15
+ end
16
+
17
+ it "should be able to list records" do
18
+ @d.should respond_to(:list_a_records)
19
+ end
20
+
21
+ it "should be able to accept additional parameters to filter the records you want" do
22
+ @driver.should_receive(:RecordGet).and_return(@result)
23
+ @result.stub!(:records)
24
+ @d.list_a_records("myzone.domain.com")
25
+ end
26
+
27
+ it "should be able to add an A record" do
28
+ @d.should respond_to(:add_a_record)
29
+ end
30
+
31
+ it "should require zone, address information when adding an A record" do
32
+ @driver.should_receive(:RecordAdd).and_return(@result)
33
+ @d.add_a_record("test.domain.com", "192.168.1.1" )
34
+ end
35
+
36
+ it "should be able to accept additional parameters when creating an A record" do
37
+ @driver.should_receive(:RecordAdd).and_return(@result)
38
+ @d.add_a_record("test.domain.com", "192.168.1.1", "ttl" => "64")
39
+ end
40
+
41
+ it "should be able to update A records" do
42
+ @d.should respond_to(:update_a_record)
43
+ end
44
+
45
+ it "should require the A record id to update" do
46
+ @driver.should_receive(:RecordUpdate).and_return(@result)
47
+ @d.update_a_record("id")
48
+ end
49
+
50
+ it "should be able to accept additional parameters when updating an A record" do
51
+ @driver.should_receive(:RecordUpdate).and_return(@result)
52
+ @d.update_a_record("id", "address" => "192.168.1.1")
53
+ end
54
+
55
+ it "should be able to delete A records" do
56
+ @d.should respond_to(:delete_a_record)
57
+ end
58
+
59
+ it "should require the A record id to delete" do
60
+ @driver.should_receive(:RecordDelete).and_return(@result)
61
+ @d.delete_a_record("id")
62
+ end
63
+
64
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/../lib/dynect.rb'
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe Dynect, "when used to manage CNAME records" do
5
+
6
+ before(:each) do
7
+ @driver = mock("driver")
8
+ @driver.should_receive(:add_method).at_least(:once)
9
+
10
+ @d = Dynect.new("customer", "username", "password", @driver)
11
+
12
+ @result = mock("test")
13
+ @result.stub!(:errors).and_return(false)
14
+ @result.stub!(:[])
15
+ end
16
+
17
+ it "should be able to list records" do
18
+ @d.should respond_to(:list_cname_records)
19
+ end
20
+
21
+ it "should be able to accept additional parameters to filter the records you want" do
22
+ @driver.should_receive(:RecordGet).and_return(@result)
23
+ @result.stub!(:records)
24
+ @d.list_cname_records("zone.domain.com")
25
+ end
26
+
27
+ it "should be able to add an CNAME record" do
28
+ @d.should respond_to(:add_cname_record)
29
+ end
30
+
31
+ it "should require zone, hostname information when adding an CNAME record" do
32
+ @driver.should_receive(:RecordAdd).and_return(@result)
33
+ @d.add_cname_record("test.domain.com", "cname.domain.com" )
34
+ end
35
+
36
+ it "should be able to accept additional parameters when creating an CNAME record" do
37
+ @driver.should_receive(:RecordAdd).and_return(@result)
38
+ @d.add_cname_record("test.domain.com", "cname.domain.com")
39
+ end
40
+
41
+ it "should be able to update CNAME records" do
42
+ @d.should respond_to(:update_cname_record)
43
+ end
44
+
45
+ it "should require the CNAME record id to update" do
46
+ @driver.should_receive(:RecordUpdate).and_return(@result)
47
+ @d.update_cname_record("id")
48
+ end
49
+
50
+ it "should be able to accept additional parameters when updating an CNAME record" do
51
+ @driver.should_receive(:RecordUpdate).and_return(@result)
52
+ @d.update_cname_record("id", "address" => "192.168.1.1")
53
+ end
54
+
55
+ it "should be able to delete CNAME records" do
56
+ @d.should respond_to(:delete_cname_record)
57
+ end
58
+
59
+ it "should require the CNAME record id to delete" do
60
+ @driver.should_receive(:RecordDelete).and_return(@result)
61
+ @d.delete_cname_record("id")
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../lib/dynect.rb'
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+
5
+ describe Dynect, "when used to manage SOA" do
6
+
7
+ before(:each) do
8
+ @driver = mock("driver")
9
+ @driver.should_receive(:add_method).at_least(:once)
10
+
11
+ @d = Dynect.new("customer", "username", "password", @driver)
12
+
13
+ @result = mock("test")
14
+ @result.stub!(:errors).and_return(false)
15
+ @result.stub!(:[])
16
+ end
17
+
18
+ it "should be able to update SOA elements" do
19
+ @d.should respond_to(:update_soa)
20
+ end
21
+
22
+ it "should accept options to update" do
23
+ @driver.should_receive(:RecordUpdate).and_return(@result)
24
+ @d.update_soa("rname" => "root.domain.com")
25
+ end
26
+
27
+ it "should list SOA elements" do
28
+ @driver.should_receive(:RecordGet).and_return(@result)
29
+ @result.stub!(:records).and_return([])
30
+ @d.list_soa("foo.domain.com")
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../lib/dynect.rb'
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+
5
+ describe Dynect, "when used to manage zones" do
6
+
7
+ before(:each) do
8
+ @driver = mock("driver")
9
+ @driver.should_receive(:add_method).at_least(:once)
10
+
11
+ @d = Dynect.new("customer", "username", "password", @driver)
12
+
13
+ @result = mock("test")
14
+ @result.stub!(:errors).and_return(false)
15
+ @result.stub!(:[])
16
+ end
17
+
18
+ it "should have a list zones method" do
19
+ @d.should respond_to(:list_zones)
20
+ end
21
+
22
+ it "should be able to retireve info about a specific zone" do
23
+ @driver.should_receive(:ZoneGet).and_return(@result)
24
+ @result.stub!(:zones)
25
+ @d.list_zones("test.domain.com")
26
+ end
27
+
28
+ it "should call the driver when list zones is called" do
29
+ expected_creds = {"cust" => "customer", "user" => "username", "pass" => "password"}
30
+ @driver.should_receive(:ZoneGet).with(expected_creds).and_return(@result)
31
+ @result.stub!(:zones)
32
+ @d.list_zones
33
+ end
34
+
35
+ it "should have a create zone method" do
36
+ @d.should respond_to(:create_zone)
37
+ end
38
+
39
+ it "should require a zone name and type when creating a zone" do
40
+ @driver.should_receive(:ZoneAdd).and_return(@result)
41
+ @d.create_zone("test.domain.com", "primary")
42
+ end
43
+
44
+ it "should be able to accept additional parameters when creating a zone" do
45
+ @result.stub!(:call)
46
+ @driver.should_receive(:ZoneAdd).and_return(@result)
47
+
48
+ options = {"ttl" => "24", "data" => {"rname" => "test@example.com", "master" => "192.168.1.1"}}
49
+
50
+ @d.create_zone("test.domain.com", "primary", options).should_not raise_error
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Hoover
8
+ - Colin Harris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-01-02 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: soap4r
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ version:
34
+ description: Simple wrapper for Dynect SOAP API.
35
+ email: dave@obtiva.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/dynect.rb
44
+ has_rdoc: true
45
+ homepage: http://rubyforge.org/projects/dynect/
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: dynect
66
+ rubygems_version: 1.0.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Simple wrapper for Dynect SOAP API.
70
+ test_files:
71
+ - spec/dynec_a_record_spec.rb
72
+ - spec/dynec_cname_record_spec.rb
73
+ - spec/dynec_soa_record_spec.rb
74
+ - spec/dynect_zone_spec.rb