implemented a few more requests

This commit is contained in:
Darrin Eden 2011-02-24 15:22:38 -08:00
parent 6c8fd4ec8a
commit 3a8382f666
6 changed files with 157 additions and 5 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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<Array~>
# * 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

View File

@ -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

View File

@ -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?