Skip to content
Browse files

implemented a few more requests

  • Loading branch information...
1 parent 6c8fd4e commit 3a8382f666c1e1656573bd07e13cf3c97cdc6251 @dje dje committed Feb 24, 2011
View
3 lib/fog/dns/dnsimple.rb
@@ -11,6 +11,9 @@ class DNS < Fog::Service
request :get_domain
request :delete_domain
request :create_record
+ request :list_records
+ request :update_record
+ request :delete_record
class Mock
# TODO
View
4 lib/fog/dns/requests/dnsimple/create_record.rb
@@ -32,7 +32,9 @@ def create_record(domain, name, type, content, options = {})
"record" => {
"name" => name,
"record_type" => type,
- "content" => content } }
+ "content" => content } }
+
+ body["record"].merge!(options)
request( :body => body.to_json,
:expects => 201,
View
21 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
View
32 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<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
42 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
View
60 tests/dns/requests/dnsimple/dns_tests.rb
@@ -15,9 +15,9 @@ def generate_unique_domain( with_trailing_dot = false)
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 @@ def generate_unique_domain( with_trailing_dot = false)
response.status == 200
end
- test('create domain') do
+ test("create domain") do
pending if Fog.mocking?
domain = generate_unique_domain
@@ -57,13 +57,65 @@ def generate_unique_domain( with_trailing_dot = false)
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?

0 comments on commit 3a8382f

Please sign in to comment.
Something went wrong with that request. Please try again.