dnsimple-ruby 1.4.1 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -3
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -0
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +2 -4
  7. data/dnsimple-ruby.gemspec +3 -6
  8. data/features/README.md +9 -0
  9. data/lib/dnsimple/certificate.rb +37 -36
  10. data/lib/dnsimple/client.rb +7 -4
  11. data/lib/dnsimple/contact.rb +49 -48
  12. data/lib/dnsimple/domain.rb +79 -79
  13. data/lib/dnsimple/extended_attribute.rb +1 -1
  14. data/lib/dnsimple/record.rb +7 -12
  15. data/lib/dnsimple/service.rb +2 -2
  16. data/lib/dnsimple/template.rb +11 -17
  17. data/lib/dnsimple/template_record.rb +4 -4
  18. data/lib/dnsimple/transfer_order.rb +1 -1
  19. data/lib/dnsimple/user.rb +6 -14
  20. data/lib/dnsimple/version.rb +1 -1
  21. data/spec/ci/.dnsimple.test +1 -1
  22. data/spec/dnsimple/certificate_spec.rb +40 -30
  23. data/spec/dnsimple/client_spec.rb +9 -9
  24. data/spec/dnsimple/contact_spec.rb +34 -26
  25. data/spec/dnsimple/domain_spec.rb +21 -74
  26. data/spec/dnsimple/extended_attributes_spec.rb +42 -9
  27. data/spec/dnsimple/record_spec.rb +35 -43
  28. data/spec/dnsimple/template_spec.rb +27 -5
  29. data/spec/dnsimple/user_spec.rb +22 -14
  30. data/spec/files/certificates/index/success.http +19 -0
  31. data/spec/files/certificates/show/notfound.http +17 -0
  32. data/spec/files/certificates/show/success.http +19 -0
  33. data/spec/files/contacts/show/notfound.http +17 -0
  34. data/spec/files/contacts/show/success.http +19 -0
  35. data/spec/files/domains/show/notfound.http +17 -0
  36. data/spec/files/domains/show/success.http +19 -0
  37. data/spec/files/extended_attributes/ca.http +19 -0
  38. data/spec/files/extended_attributes/com.http +19 -0
  39. data/spec/files/extended_attributes/success.http +19 -0
  40. data/spec/files/records/index/success.http +19 -0
  41. data/spec/files/records/show/notfound.http +17 -0
  42. data/spec/files/records/show/success.http +19 -0
  43. data/spec/files/templates/show/notfound.http +17 -0
  44. data/spec/files/templates/show/success.http +19 -0
  45. data/spec/files/users/me/success.http +19 -0
  46. data/spec/spec_helper.rb +14 -17
  47. data/spec/support/helpers.rb +15 -0
  48. data/spec/support/webmock.rb +11 -0
  49. metadata +65 -84
  50. data/features/README +0 -12
  51. data/fixtures/vcr_cassettes/DNSimple_Certificate/_all.yml +0 -57
  52. data/fixtures/vcr_cassettes/DNSimple_Certificate/_purchase.yml +0 -57
  53. data/fixtures/vcr_cassettes/DNSimple_Certificate/_submit.yml +0 -57
  54. data/fixtures/vcr_cassettes/DNSimple_Contact/a_new_contact.yml +0 -50
  55. data/fixtures/vcr_cassettes/DNSimple_Contact/an_existing_contact.yml +0 -50
  56. data/fixtures/vcr_cassettes/DNSimple_Domain/_all.yml +0 -149
  57. data/fixtures/vcr_cassettes/DNSimple_Domain/applying_templates.yml +0 -246
  58. data/fixtures/vcr_cassettes/DNSimple_Domain/creating_a_new_domain.yml +0 -51
  59. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_id.yml +0 -51
  60. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_name.yml +0 -51
  61. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_a_new_registrant_contact.yml +0 -52
  62. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_an_existing_contact.yml +0 -52
  63. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_ca.yml +0 -273
  64. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_com.yml +0 -46
  65. data/fixtures/vcr_cassettes/DNSimple_Record/_all.yml +0 -195
  66. data/fixtures/vcr_cassettes/DNSimple_Record/creating_a_new_record.yml +0 -51
  67. data/fixtures/vcr_cassettes/DNSimple_Record/find_a_record.yml +0 -51
  68. data/fixtures/vcr_cassettes/DNSimple_Template/a_template.yml +0 -53
  69. data/fixtures/vcr_cassettes/DNSimple_User/_me.yml +0 -49
  70. data/spec/README +0 -10
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ad2f0f53848ebf458ce24ef1c93ffcc13987d20
4
+ data.tar.gz: 8dc6ab4a793415fa47675c1b32b98a9cdf8188e1
5
+ SHA512:
6
+ metadata.gz: 9047c85d1d90c5da44eacf36e79cd729e346efaed3defb34340bf482605d763bad9099ee2446af89787de2bb64149a51953f36bd61ae7d4743616f34a9d1a2eb
7
+ data.tar.gz: cde66935f2047f166573598bc7358d7785b659e0aedbec6693dda775186ed4418adba10b348b656e65a3eb889daf01ee90bafd399d247578377e331b48e880e1
data/.gitignore CHANGED
@@ -1,6 +1,3 @@
1
- turbulence
2
- .rvmrc
3
-
4
1
  # Bundler
5
2
  .bundle
6
3
  pkg/*
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3
1
+ ruby-2.0
data/.travis.yml CHANGED
@@ -4,4 +4,5 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1.0
7
8
  env: DNSIMPLE_TEST_CONFIG=spec/ci/.dnsimple.test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## Release 1.5.1
4
+
5
+ - FIXED: Invalid base URI.
6
+
7
+ ## Release 1.5.0
8
+
9
+ - CHANGED: Added support for versioned API (GH-33)
10
+
3
11
  ## Release 1.4.0
4
12
 
5
13
  - CHANGED: Normalized exception handling. No more RuntimeError.
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # DNSimple Ruby Client
1
+ # DNSimple Ruby Client [![Build Status](https://secure.travis-ci.org/aetrion/dnsimple-ruby.png)](http://travis-ci.org/aetrion/dnsimple-ruby)
2
2
 
3
- A Ruby command line utility and wrapper for the [DNSimple API](https://dnsimple.com/documentation/api).
4
-
5
- [![Build Status](https://secure.travis-ci.org/aetrion/dnsimple-ruby.png)](http://travis-ci.org/aetrion/dnsimple-ruby)
3
+ A Ruby command line utility and wrapper for the [DNSimple API](http://developer.dnsimple.com/).
6
4
 
7
5
  [DNSimple](https://dnsimple.com/) provides DNS hosting
8
6
  and domain registration that is simple and friendly.
@@ -15,18 +15,15 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.extra_rdoc_files = %w( README.md CHANGELOG.md LICENSE )
18
- s.executables = `git ls-files -- bin/*`.split("\n").collect { |f|
19
- File.basename(f)
20
- }
18
+ s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
21
19
 
22
- s.add_runtime_dependency 'httparty', '>= 0'
20
+ s.add_dependency 'httparty', RUBY_VERSION < "1.9.3" ? [">= 0.10", "< 0.12"] : "~> 0.12"
23
21
 
24
22
  s.add_development_dependency 'rake'
25
23
  s.add_development_dependency 'aruba'
26
24
  s.add_development_dependency 'cucumber'
27
- s.add_development_dependency 'fakeweb'
28
25
  s.add_development_dependency 'mocha'
29
26
  s.add_development_dependency 'rspec'
30
- s.add_development_dependency 'vcr'
31
27
  s.add_development_dependency 'yard'
28
+ s.add_development_dependency 'webmock'
32
29
  end
@@ -0,0 +1,9 @@
1
+ Before running the DNSimple Ruby Client cucumber feature files, you must do the following:
2
+
3
+ 1. If you haven't already go to https://sandbox.dnsimple.com and create an account. Activate your account to the Platinum level using the credit card number of "1".
4
+
5
+ 2. Create a file in your home directory called .dnsimple.test and include the following:
6
+
7
+ username: YOUR_USERNAME
8
+ password: YOUR_PASSWORD
9
+ base_uri: https://api.sandbox.dnsimple.com/
@@ -14,57 +14,36 @@ module DNSimple
14
14
  # The subdomain on the certificate
15
15
  attr_accessor :name
16
16
 
17
- # The private key, if DNSimple generated the Certificate Signing Request
18
- attr_accessor :private_key
19
-
20
- # The SSL certificate, if it has been issued by the Certificate Authority
21
- attr_accessor :ssl_certificate
22
-
23
17
  # The Certificate Signing Request
24
18
  attr_accessor :csr
25
19
 
26
- # The Certificate status
27
- attr_accessor :certificate_status
28
-
29
- # The date the Certificate order was placed
30
- attr_accessor :order_date
20
+ # The SSL certificate, if it has been issued by the Certificate Authority
21
+ attr_accessor :ssl_certificate
31
22
 
32
- # The date the Certificate will expire
33
- attr_accessor :expiration_date
23
+ # The private key, if DNSimple generated the Certificate Signing Request
24
+ attr_accessor :private_key
34
25
 
35
26
  # The approver email address
36
27
  attr_accessor :approver_email
37
28
 
38
- # An array of all emails that can be used to approve the certificate
39
- attr_accessor :available_approver_emails
40
-
41
29
  # When the certificate was purchased
42
30
  attr_accessor :created_at
43
31
 
44
32
  # When the certificate was last updated
45
33
  attr_accessor :updated_at
46
34
 
35
+ # An array of all emails that can be used to approve the certificate
36
+ attr_accessor :available_approver_emails
47
37
 
48
- # Get the fully-qualified domain name for the certificate. This is the
49
- # domain.name joined with the certificate name, separated by a period.
50
- def fqdn
51
- [name, domain.name].delete_if { |p| p !~ DNSimple::BLANK_REGEX }.join(".")
52
- end
53
-
54
- def submit(approver_email, options={})
55
- raise DNSimple::Error, "Approver email is required" unless approver_email
38
+ # The Certificate status
39
+ attr_accessor :certificate_status
56
40
 
57
- options.merge!(:body => {:certificate => {:approver_email => approver_email}})
41
+ # The date the Certificate order was placed
42
+ attr_accessor :order_date
58
43
 
59
- response = DNSimple::Client.put("domains/#{domain.name}/certificates/#{id}/submit", options)
44
+ # The date the Certificate will expire
45
+ attr_accessor :expiration_date
60
46
 
61
- case response.code
62
- when 200
63
- Certificate.new({ :domain => domain }.merge(response["certificate"]))
64
- else
65
- raise RequestError.new("Error submitting certificate", response)
66
- end
67
- end
68
47
 
69
48
  # Purchase a certificate under the given domain with the given name. The
70
49
  # name will be appended to the domain name, and thus should only be the
@@ -86,7 +65,7 @@ module DNSimple
86
65
 
87
66
  options.merge!({:body => {:certificate => certificate_hash}})
88
67
 
89
- response = DNSimple::Client.post("domains/#{domain.name}/certificates", options)
68
+ response = DNSimple::Client.post("/v1/domains/#{domain.name}/certificates", options)
90
69
 
91
70
  case response.code
92
71
  when 201
@@ -100,7 +79,7 @@ module DNSimple
100
79
 
101
80
  # Get an array of all certificates for the given domain.
102
81
  def self.all(domain, options={})
103
- response = DNSimple::Client.get("domains/#{domain.name}/certificates", options)
82
+ response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates", options)
104
83
 
105
84
  case response.code
106
85
  when 200
@@ -112,7 +91,7 @@ module DNSimple
112
91
 
113
92
  # Find a specific certificate for the given domain.
114
93
  def self.find(domain, id, options = {})
115
- response = DNSimple::Client.get("domains/#{domain.name}/certificates/#{id}", options)
94
+ response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates/#{id}", options)
116
95
 
117
96
  case response.code
118
97
  when 200
@@ -124,5 +103,27 @@ module DNSimple
124
103
  end
125
104
  end
126
105
 
106
+
107
+ # Get the fully-qualified domain name for the certificate. This is the
108
+ # domain.name joined with the certificate name, separated by a period.
109
+ def fqdn
110
+ [name, domain.name].delete_if { |p| p !~ DNSimple::BLANK_REGEX }.join(".")
111
+ end
112
+
113
+ def submit(approver_email, options={})
114
+ raise DNSimple::Error, "Approver email is required" unless approver_email
115
+
116
+ options.merge!(:body => {:certificate => {:approver_email => approver_email}})
117
+
118
+ response = DNSimple::Client.put("/v1/domains/#{domain.name}/certificates/#{id}/submit", options)
119
+
120
+ case response.code
121
+ when 200
122
+ Certificate.new({ :domain => domain }.merge(response["certificate"]))
123
+ else
124
+ raise RequestError.new("Error submitting certificate", response)
125
+ end
126
+ end
127
+
127
128
  end
128
129
  end
@@ -3,6 +3,9 @@ require 'yaml'
3
3
  module DNSimple
4
4
  class Client
5
5
 
6
+ API_BASE_URI = "https://api.dnsimple.com/"
7
+
8
+
6
9
  def self.debug?
7
10
  @debug
8
11
  end
@@ -39,7 +42,7 @@ module DNSimple
39
42
  #
40
43
  # @return [String] The qualified API base uri.
41
44
  def self.base_uri
42
- @base_uri ||= "https://dnsimple.com"
45
+ @base_uri ||= API_BASE_URI.chomp("/")
43
46
  end
44
47
 
45
48
  # Sets the qualified API base uri.
@@ -67,13 +70,13 @@ module DNSimple
67
70
 
68
71
  def self.load_credentials(path = config_path)
69
72
  begin
70
- credentials = YAML.load(File.new(File.expand_path(path)))
73
+ credentials = YAML.load_file(File.expand_path(path))
71
74
  self.username ||= credentials['username']
72
75
  self.password ||= credentials['password']
73
76
  self.api_token ||= credentials['api_token']
74
77
  self.base_uri = credentials['site'] if credentials['site']
75
78
  self.base_uri = credentials['base_uri'] if credentials['base_uri']
76
- self.http_proxy = { :addr => credentials['proxy_addr'], :port => credentials['proxy_port'] }
79
+ self.http_proxy = { :addr => credentials['proxy_addr'], :port => credentials['proxy_port'] } if credentials['proxy_addr'] || credentials['proxy_port']
77
80
  @credentials_loaded = true
78
81
  puts "Credentials loaded from #{path}"
79
82
  rescue => error
@@ -127,7 +130,7 @@ module DNSimple
127
130
  end
128
131
 
129
132
  def self.request(method, path, options)
130
- response = HTTParty.send(method, "#{base_uri}/#{path}",
133
+ response = HTTParty.send(method, "#{base_uri}#{path}",
131
134
  standard_options.merge(options))
132
135
 
133
136
  if response.code == 401
@@ -15,19 +15,30 @@ module DNSimple
15
15
  # The contact ID in DNSimple
16
16
  attr_accessor :id
17
17
 
18
- # The name of the organization in which the contact works
19
- # (may be omitted)
20
- attr_accessor :organization_name
21
-
22
18
  # The contact first name
23
19
  attr_accessor :first_name
24
20
 
25
21
  # The contact last name
26
22
  attr_accessor :last_name
27
23
 
28
- # The contact's job title (may be omitted)
24
+ # The contact's job title
29
25
  attr_accessor :job_title
30
26
 
27
+ # The name of the organization in which the contact works
28
+ attr_accessor :organization_name
29
+
30
+ # The contact email address
31
+ attr_accessor :email_address
32
+
33
+ # The contact phone number
34
+ attr_accessor :phone
35
+
36
+ # The contact phone extension (may be omitted)
37
+ attr_accessor :phone_ext
38
+
39
+ # The contact fax number (may be omitted)
40
+ attr_accessor :fax
41
+
31
42
  # The contact street address
32
43
  attr_accessor :address1
33
44
 
@@ -46,52 +57,12 @@ module DNSimple
46
57
  # The contact country (as a 2-character country code)
47
58
  attr_accessor :country
48
59
 
49
- # The contact email address
50
- attr_accessor :email_address
51
-
52
- # The contact phone number
53
- attr_accessor :phone
54
-
55
- # The contact phone extension (may be omitted)
56
- attr_accessor :phone_ext
57
-
58
- # The contact fax number (may be omitted)
59
- attr_accessor :fax
60
-
61
60
  # When the contact was created in DNSimple
62
61
  attr_accessor :created_at
63
62
 
64
63
  # When the contact was last updated in DNSimple
65
64
  attr_accessor :updated_at
66
65
 
67
- def name
68
- [first_name, last_name].join(' ')
69
- end
70
-
71
- def save(options={})
72
- contact_hash = {}
73
- %w(first_name last_name organization_name job_title address1 address2 city
74
- state_province postal_code country email_address phone phone_ext fax).each do |attribute|
75
- contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute)
76
- end
77
-
78
- options.merge!({:body => {:contact => contact_hash}})
79
-
80
- response = DNSimple::Client.put("contacts/#{id}", options)
81
-
82
- case response.code
83
- when 200
84
- return self
85
- else
86
- raise RequestError.new("Error updating contact", response)
87
- end
88
- end
89
-
90
- # Delete the contact from DNSimple. WARNING: this cannot be undone.
91
- def delete(options={})
92
- DNSimple::Client.delete("contacts/#{id}", options)
93
- end
94
- alias :destroy :delete
95
66
 
96
67
  # Map an aliased field name to it's real name. For example, if you
97
68
  # pass "first" it will be resolved to "first_name", "email" is resolved
@@ -115,7 +86,7 @@ module DNSimple
115
86
  contact_hash = resolve_attributes(attributes)
116
87
 
117
88
  options.merge!({:body => {:contact => contact_hash}})
118
- response = DNSimple::Client.post("contacts", options)
89
+ response = DNSimple::Client.post("/v1/contacts", options)
119
90
 
120
91
  case response.code
121
92
  when 201
@@ -126,7 +97,7 @@ module DNSimple
126
97
  end
127
98
 
128
99
  def self.find(id, options={})
129
- response = DNSimple::Client.get("contacts/#{id}", options)
100
+ response = DNSimple::Client.get("/v1/contacts/#{id}", options)
130
101
 
131
102
  case response.code
132
103
  when 200
@@ -139,7 +110,7 @@ module DNSimple
139
110
  end
140
111
 
141
112
  def self.all(options={})
142
- response = DNSimple::Client.get("contacts", options)
113
+ response = DNSimple::Client.get("/v1/contacts", options)
143
114
 
144
115
  case response.code
145
116
  when 200
@@ -149,5 +120,35 @@ module DNSimple
149
120
  end
150
121
  end
151
122
 
123
+
124
+ def name
125
+ [first_name, last_name].join(' ')
126
+ end
127
+
128
+ def save(options={})
129
+ contact_hash = {}
130
+ %w(first_name last_name organization_name job_title address1 address2 city
131
+ state_province postal_code country email_address phone phone_ext fax).each do |attribute|
132
+ contact_hash[DNSimple::Contact.resolve(attribute)] = self.send(attribute)
133
+ end
134
+
135
+ options.merge!({:body => {:contact => contact_hash}})
136
+
137
+ response = DNSimple::Client.put("/v1/contacts/#{id}", options)
138
+
139
+ case response.code
140
+ when 200
141
+ return self
142
+ else
143
+ raise RequestError.new("Error updating contact", response)
144
+ end
145
+ end
146
+
147
+ # Delete the contact from DNSimple. WARNING: this cannot be undone.
148
+ def delete(options={})
149
+ DNSimple::Client.delete("/v1/contacts/#{id}", options)
150
+ end
151
+ alias :destroy :delete
152
+
152
153
  end
153
154
  end
@@ -1,7 +1,6 @@
1
1
  module DNSimple
2
-
3
- # Represents a single domain.
4
2
  class Domain < Base
3
+
5
4
  # The domain ID in DNSimple
6
5
  attr_accessor :id
7
6
 
@@ -17,80 +16,10 @@ module DNSimple
17
16
  # The current known name server status
18
17
  attr_accessor :name_server_status
19
18
 
20
- # Delete the domain from DNSimple. WARNING: this cannot
21
- # be undone.
22
- def delete(options={})
23
- DNSimple::Client.delete("domains/#{name}", options)
24
- end
25
- alias :destroy :delete
26
-
27
- # Apply the given named template to the domain. This will add
28
- # all of the records in the template to the domain.
29
- def apply(template, options={})
30
- options.merge!(:body => {})
31
- template = resolve_template(template)
32
-
33
- DNSimple::Client.post("domains/#{name}/templates/#{template.id}/apply", options)
34
- end
35
-
36
- #:nodoc:
37
- def resolve_template(template)
38
- case template
39
- when DNSimple::Template
40
- template
41
- else
42
- DNSimple::Template.find(template)
43
- end
44
- end
45
-
46
- def applied_services(options={})
47
- response = DNSimple::Client.get("domains/#{name}/applied_services", options)
48
-
49
- case response.code
50
- when 200
51
- response.map { |r| DNSimple::Service.new(r["service"]) }
52
- else
53
- raise RequestError.new("Error listing applied services", response)
54
- end
55
- end
56
-
57
- def available_services(options={})
58
- response = DNSimple::Client.get("domains/#{name}/available_services", options)
59
-
60
- case response.code
61
- when 200
62
- response.map { |r| DNSimple::Service.new(r["service"]) }
63
- else
64
- raise RequestError.new("Error listing available services", response)
65
- end
66
- end
67
-
68
- def add_service(id_or_short_name, options={})
69
- options.merge!(:body => {:service => {:id => id_or_short_name}})
70
- response = DNSimple::Client.post("domains/#{name}/applied_services", options)
71
-
72
- case response.code
73
- when 200
74
- true
75
- else
76
- raise RequestError.new("Error adding service", response)
77
- end
78
- end
79
-
80
- def remove_service(id, options={})
81
- response = DNSimple::Client.delete("domains/#{name}/applied_services/#{id}", options)
82
-
83
- case response.code
84
- when 200
85
- true
86
- else
87
- raise RequestError.new("Error removing service", response)
88
- end
89
- end
90
19
 
91
20
  # Check the availability of a name
92
21
  def self.check(name, options={})
93
- response = DNSimple::Client.get("domains/#{name}/check", options)
22
+ response = DNSimple::Client.get("/v1/domains/#{name}/check", options)
94
23
 
95
24
  case response.code
96
25
  when 200
@@ -108,7 +37,7 @@ module DNSimple
108
37
  def self.create(name, options={})
109
38
  options.merge!({:body => {:domain => {:name => name}}})
110
39
 
111
- response = DNSimple::Client.post("domains", options)
40
+ response = DNSimple::Client.post("/v1/domains", options)
112
41
 
113
42
  case response.code
114
43
  when 201
@@ -131,7 +60,7 @@ module DNSimple
131
60
  body.merge!(:extended_attribute => extended_attributes)
132
61
  options.merge!({:body => body})
133
62
 
134
- response = DNSimple::Client.post("domain_registrations", options)
63
+ response = DNSimple::Client.post("/v1/domain_registrations", options)
135
64
 
136
65
  case response.code
137
66
  when 201
@@ -143,9 +72,8 @@ module DNSimple
143
72
 
144
73
  # Find a specific domain in the account either by the numeric ID
145
74
  # or by the fully-qualified domain name.
146
- def self.find(id_or_name, options={})
147
- id = id_or_name
148
- response = DNSimple::Client.get("domains/#{id}", options)
75
+ def self.find(id, options={})
76
+ response = DNSimple::Client.get("/v1/domains/#{id}", options)
149
77
 
150
78
  case response.code
151
79
  when 200
@@ -159,7 +87,7 @@ module DNSimple
159
87
 
160
88
  # Get all domains for the account.
161
89
  def self.all(options={})
162
- response = DNSimple::Client.get("domains", options)
90
+ response = DNSimple::Client.get("/v1/domains", options)
163
91
 
164
92
  case response.code
165
93
  when 200
@@ -169,5 +97,77 @@ module DNSimple
169
97
  end
170
98
  end
171
99
 
100
+
101
+ # Delete the domain from DNSimple. WARNING: this cannot
102
+ # be undone.
103
+ def delete(options={})
104
+ DNSimple::Client.delete("/v1/domains/#{name}", options)
105
+ end
106
+ alias :destroy :delete
107
+
108
+ # Apply the given named template to the domain. This will add
109
+ # all of the records in the template to the domain.
110
+ def apply(template, options={})
111
+ options.merge!(:body => {})
112
+ template = resolve_template(template)
113
+
114
+ DNSimple::Client.post("/v1/domains/#{name}/templates/#{template.id}/apply", options)
115
+ end
116
+
117
+ #:nodoc:
118
+ def resolve_template(template)
119
+ case template
120
+ when DNSimple::Template
121
+ template
122
+ else
123
+ DNSimple::Template.find(template)
124
+ end
125
+ end
126
+
127
+ def applied_services(options={})
128
+ response = DNSimple::Client.get("/v1/domains/#{name}/applied_services", options)
129
+
130
+ case response.code
131
+ when 200
132
+ response.map { |r| DNSimple::Service.new(r["service"]) }
133
+ else
134
+ raise RequestError.new("Error listing applied services", response)
135
+ end
136
+ end
137
+
138
+ def available_services(options={})
139
+ response = DNSimple::Client.get("/v1/domains/#{name}/available_services", options)
140
+
141
+ case response.code
142
+ when 200
143
+ response.map { |r| DNSimple::Service.new(r["service"]) }
144
+ else
145
+ raise RequestError.new("Error listing available services", response)
146
+ end
147
+ end
148
+
149
+ def add_service(id_or_short_name, options={})
150
+ options.merge!(:body => {:service => {:id => id_or_short_name}})
151
+ response = DNSimple::Client.post("/v1/domains/#{name}/applied_services", options)
152
+
153
+ case response.code
154
+ when 200
155
+ true
156
+ else
157
+ raise RequestError.new("Error adding service", response)
158
+ end
159
+ end
160
+
161
+ def remove_service(id, options={})
162
+ response = DNSimple::Client.delete("/v1/domains/#{name}/applied_services/#{id}", options)
163
+
164
+ case response.code
165
+ when 200
166
+ true
167
+ else
168
+ raise RequestError.new("Error removing service", response)
169
+ end
170
+ end
171
+
172
172
  end
173
173
  end