diff --git a/lib/fog/dns/dnsimple.rb b/lib/fog/dns/dnsimple.rb index f1b00385e..e54f23f51 100644 --- a/lib/fog/dns/dnsimple.rb +++ b/lib/fog/dns/dnsimple.rb @@ -11,6 +11,9 @@ module Fog request :get_domain request :delete_domain request :create_record + request :list_records + request :update_record + request :delete_record class Mock # TODO diff --git a/lib/fog/dns/requests/dnsimple/create_record.rb b/lib/fog/dns/requests/dnsimple/create_record.rb index e3dfb9370..e3e2c7a8e 100644 --- a/lib/fog/dns/requests/dnsimple/create_record.rb +++ b/lib/fog/dns/requests/dnsimple/create_record.rb @@ -32,7 +32,9 @@ module Fog "record" => { "name" => name, "record_type" => type, - "content" => content } } + "content" => content } } + + body["record"].merge!(options) request( :body => body.to_json, :expects => 201, diff --git a/lib/fog/dns/requests/dnsimple/delete_record.rb b/lib/fog/dns/requests/dnsimple/delete_record.rb new file mode 100644 index 000000000..2d9b0e59e --- /dev/null +++ b/lib/fog/dns/requests/dnsimple/delete_record.rb @@ -0,0 +1,21 @@ +module Fog + module DNSimple + class DNS + class Real + + # Delete the record with the given ID for the given domain. + # + # ==== Parameters + # * domain<~String> + # * record_id<~String> + def delete_record(domain, record_id) + + request( :expects => 200, + :method => "DELETE", + :path => "/domains/#{domain}/records/#{record_id}" ) + end + + end + end + end +end diff --git a/lib/fog/dns/requests/dnsimple/list_records.rb b/lib/fog/dns/requests/dnsimple/list_records.rb new file mode 100644 index 000000000..5eb470d6f --- /dev/null +++ b/lib/fog/dns/requests/dnsimple/list_records.rb @@ -0,0 +1,32 @@ +module Fog + module DNSimple + class DNS + class Real + + # Get the list of records for the specific domain. + # + # ==== Parameters + # * domain<~String> + # ==== Returns + # * response<~Excon::Response>: + # * records + # * name<~String> + # * ttl<~Integer> + # * created_at<~String> + # * special_type<~String> + # * updated_at<~String> + # * domain_id<~Integer> + # * id<~Integer> + # * content<~String> + # * record_type<~String> + # * prio<~Integer> + def list_records(domain) + request( :expects => 200, + :method => "GET", + :path => "/domains/#{domain}/records" ) + end + + end + end + end +end diff --git a/lib/fog/dns/requests/dnsimple/update_record.rb b/lib/fog/dns/requests/dnsimple/update_record.rb new file mode 100644 index 000000000..4d2317cff --- /dev/null +++ b/lib/fog/dns/requests/dnsimple/update_record.rb @@ -0,0 +1,42 @@ +module Fog + module DNSimple + class DNS + class Real + + # Update the given record for the given domain. + # + # ==== Parameters + # * domain<~String> + # * record_id<~String> + # * options<~Hash> - optional + # * type<~String> + # * content<~String> + # * priority<~Integer> + # * ttl<~Integer> + # ==== Returns + # * response<~Excon::Response>: + # * record<~Hash> + # * name<~String> + # * ttl<~Integer> + # * created_at<~String> + # * special_type<~String> + # * updated_at<~String> + # * domain_id<~Integer> + # * id<~Integer> + # * content<~String> + # * record_type<~String> + # * prio<~Integer> + def update_record(domain, record_id, options) + + body = { "record" => options } + + request( :body => body.to_json, + :expects => 200, + :method => "PUT", + :path => "/domains/#{domain}/records/#{record_id}" ) + end + + end + end + end +end diff --git a/tests/dns/requests/dnsimple/dns_tests.rb b/tests/dns/requests/dnsimple/dns_tests.rb index da4f3571d..5c1318190 100644 --- a/tests/dns/requests/dnsimple/dns_tests.rb +++ b/tests/dns/requests/dnsimple/dns_tests.rb @@ -15,9 +15,9 @@ Shindo.tests('DNSimple::dns | DNS requests', ['dnsimple', 'dns']) do domain end - tests( 'success') do + tests("success") do - test('get current domain count') do + test("get current domain count") do pending if Fog.mocking? response = DNSimple[:dns].list_domains() @@ -28,7 +28,7 @@ Shindo.tests('DNSimple::dns | DNS requests', ['dnsimple', 'dns']) do response.status == 200 end - test('create domain') do + test("create domain") do pending if Fog.mocking? domain = generate_unique_domain @@ -57,13 +57,65 @@ Shindo.tests('DNSimple::dns | DNS requests', ['dnsimple', 'dns']) do response = DNSimple[:dns].create_record(domain, name, type, content) if response.status == 201 - @record = response.body + @record = response.body["record"] end response.status == 201 end + test("create a MX record") do + pending if Fog.mocking? + + domain = @domain["name"] + name = "" + type = "MX" + content = "mail.#{domain}" + options = { :ttl => 60, :prio => 10 } + response = DNSimple[:dns].create_record(domain, name, type, content, options) + + response.status == 201 + end + + test("update a record") do + pending if Fog.mocking? + + domain = @domain["name"] + record_id = @record["id"] + options = { :content => "2.3.4.5", :ttl => 600 } + response = DNSimple[:dns].update_record(domain, record_id, options) + response.status == 200 + end + + test("list records") do + pending if Fog.mocking? + + response = DNSimple[:dns].list_records(@domain["name"]) + + if response.status == 200 + @records = response.body + end + + (response.status == 200) and (response.body.size == 2) + end + + test("delete records") do + pending if Fog.mocking? + domain = @domain["name"] + + result = true + @records.each do |record| + response = DNSimple[:dns].delete_record(domain, record["record"]["id"]) + if(response.status != 200) + result = false + break + end + end + + result + end + + test("delete domain") do pending if Fog.mocking?