Permalink
Browse files

create_record request

  • Loading branch information...
1 parent 2006ff3 commit 6c8fd4ec8a40b90913c7ac2bc877307775493355 @dje dje committed Feb 24, 2011
Showing with 67 additions and 16 deletions.
  1. +1 −0 lib/fog/dns/dnsimple.rb
  2. +46 −0 lib/fog/dns/requests/dnsimple/create_record.rb
  3. +20 −16 tests/dns/requests/dnsimple/dns_tests.rb
View
@@ -10,6 +10,7 @@ class DNS < Fog::Service
request :create_domain
request :get_domain
request :delete_domain
+ request :create_record
class Mock
# TODO
@@ -0,0 +1,46 @@
+module Fog
+ module DNSimple
+ class DNS
+ class Real
+
+ # Create a new host in the specified zone
+ #
+ # ==== Parameters
+ # * domain<~String>
+ # * name<~String>
+ # * type<~String>
+ # * content<~String>
+ # * options<~Hash> - optional
+ # * priority<~Integer>
+ # * ttl<~Integer>
+ # ==== Returns
+ # * response<~Excon::Response>:
+ # * body<~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 create_record(domain, name, type, content, options = {})
+
+ body = {
+ "record" => {
+ "name" => name,
+ "record_type" => type,
+ "content" => content } }
+
+ request( :body => body.to_json,
+ :expects => 201,
+ :method => 'POST',
+ :path => "/domains/#{domain}/records" )
+ end
+
+ end
+ end
+ end
+end
@@ -2,8 +2,6 @@
@domain = ''
@domain_count = 0
- @new_domains = []
- @new_records = []
def generate_unique_domain( with_trailing_dot = false)
#get time (with 1/100th of sec accuracy)
@@ -36,35 +34,41 @@ def generate_unique_domain( with_trailing_dot = false)
domain = generate_unique_domain
response = DNSimple[:dns].create_domain(domain)
if response.status == 201
- @new_domains << response.body
+ @domain = response.body["domain"]
end
response.status == 201
end
- test('get domain by id') do
+ test("get domain by id") do
pending if Fog.mocking?
- id = @new_domains.first["domain"]["id"]
- response = DNSimple[:dns].get_domain(id)
-
+ response = DNSimple[:dns].get_domain(@domain["id"])
response.status == 200
end
- test("delete #{@new_domains.count} domains created") do
+ test("create an A resource record") do
pending if Fog.mocking?
- result = true
+ domain = @domain["name"]
+ name = "www"
+ type = "A"
+ content = "1.2.3.4"
+ response = DNSimple[:dns].create_record(domain, name, type, content)
- @new_domains.each do |domain|
- name = domain["domain"]["name"]
- response = DNSimple[:dns].delete_domain(name)
- if response.status != 200
- result= false;
- end
+ if response.status == 201
+ @record = response.body
end
- result
+ response.status == 201
+
+ end
+
+ test("delete domain") do
+ pending if Fog.mocking?
+
+ response = DNSimple[:dns].delete_domain(@domain["name"])
+ response.status == 200
end
end

0 comments on commit 6c8fd4e

Please sign in to comment.