dnsimple 2.0.0.alpha2 → 2.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.markdown +6 -2
  3. data/README.markdown +32 -30
  4. data/dnsimple.gemspec +1 -2
  5. data/lib/dnsimple.rb +2 -13
  6. data/lib/dnsimple/client.rb +164 -53
  7. data/lib/dnsimple/client/certificates_service.rb +98 -0
  8. data/lib/dnsimple/client/client_service.rb +8 -0
  9. data/lib/dnsimple/client/contacts_service.rb +82 -0
  10. data/lib/dnsimple/client/domains_service.rb +333 -0
  11. data/lib/dnsimple/client/name_servers_service.rb +69 -0
  12. data/lib/dnsimple/client/registrars_service.rb +105 -0
  13. data/lib/dnsimple/client/services_service.rb +95 -0
  14. data/lib/dnsimple/client/templates_service.rb +180 -0
  15. data/lib/dnsimple/client/users_service.rb +37 -0
  16. data/lib/dnsimple/compatibility.rb +46 -0
  17. data/lib/dnsimple/default.rb +86 -0
  18. data/lib/dnsimple/error.rb +7 -11
  19. data/lib/dnsimple/extra.rb +54 -0
  20. data/lib/dnsimple/struct.rb +29 -0
  21. data/lib/dnsimple/struct/certificate.rb +56 -0
  22. data/lib/dnsimple/struct/contact.rb +61 -0
  23. data/lib/dnsimple/struct/domain.rb +40 -0
  24. data/lib/dnsimple/struct/email_forward.rb +14 -0
  25. data/lib/dnsimple/struct/extended_attribute.rb +39 -0
  26. data/lib/dnsimple/struct/membership.rb +22 -0
  27. data/lib/dnsimple/struct/price.rb +16 -0
  28. data/lib/dnsimple/struct/record.rb +22 -0
  29. data/lib/dnsimple/struct/service.rb +19 -0
  30. data/lib/dnsimple/struct/template.rb +19 -0
  31. data/lib/dnsimple/struct/template_record.rb +24 -0
  32. data/lib/dnsimple/struct/transfer_order.rb +10 -0
  33. data/lib/dnsimple/struct/user.rb +17 -0
  34. data/lib/dnsimple/struct/whois_privacy.rb +19 -0
  35. data/lib/dnsimple/version.rb +1 -1
  36. data/spec/dnsimple/client/certificates_service_spec.rb +196 -0
  37. data/spec/dnsimple/client/contacts_service_spec.rb +179 -0
  38. data/spec/dnsimple/client/domains_service_spec.rb +662 -0
  39. data/spec/dnsimple/client/name_servers_service_spec.rb +131 -0
  40. data/spec/dnsimple/client/registrars_service_spec.rb +160 -0
  41. data/spec/dnsimple/client/services_service_spec.rb +162 -0
  42. data/spec/dnsimple/client/templates_service_spec.rb +371 -0
  43. data/spec/dnsimple/client/users_service_spec.rb +70 -0
  44. data/spec/dnsimple/client_spec.rb +108 -99
  45. data/spec/dnsimple/compatibility_spec.rb +57 -0
  46. data/spec/files/2fa/exchange-token.http +8 -11
  47. data/spec/files/badgateway.http +14 -0
  48. data/spec/files/certificates/configure/success.http +19 -0
  49. data/spec/files/certificates/index/success.http +1 -1
  50. data/spec/files/certificates/notfound.http +19 -0
  51. data/spec/files/certificates/purchase/success.http +19 -0
  52. data/spec/files/certificates/show/success.http +1 -1
  53. data/spec/files/certificates/submit/success.http +19 -0
  54. data/spec/files/contacts/create/badrequest-missingcontact.http +19 -0
  55. data/spec/files/contacts/create/badrequest-validationerror.http +19 -0
  56. data/spec/files/contacts/create/created.http +22 -0
  57. data/spec/files/contacts/delete/success-204.http +18 -0
  58. data/spec/files/{extended_attributes/com.http → contacts/delete/success.http} +5 -5
  59. data/spec/files/{domains/auto_renewal_enable → contacts/index}/success.http +6 -6
  60. data/spec/files/contacts/notfound.http +19 -0
  61. data/spec/files/contacts/update/success.http +21 -0
  62. data/spec/files/domains/create/created.http +21 -0
  63. data/spec/files/domains/index/success.http +11 -9
  64. data/spec/files/domains/notfound.http +11 -9
  65. data/spec/files/domains/show/success.http +12 -10
  66. data/spec/files/domains_autorenewal/disable/success.http +21 -0
  67. data/spec/files/domains_autorenewal/enable/success.http +21 -0
  68. data/spec/files/domains_autorenewal/notfound-domain.http +19 -0
  69. data/spec/files/domains_forwards/create/created.http +22 -0
  70. data/spec/files/domains_forwards/delete/success.http +17 -0
  71. data/spec/files/domains_forwards/get/success.http +21 -0
  72. data/spec/files/domains_forwards/list/success.http +21 -0
  73. data/spec/files/domains_forwards/notfound-domain.http +19 -0
  74. data/spec/files/domains_forwards/notfound.http +19 -0
  75. data/spec/files/domains_records/create/created.http +21 -0
  76. data/spec/files/domains_records/delete/success-204.http +18 -0
  77. data/spec/files/{contacts/show/notfound.http → domains_records/delete/success.http} +9 -7
  78. data/spec/files/{records → domains_records}/index/success.http +0 -0
  79. data/spec/files/{records/show → domains_records}/notfound.http +1 -1
  80. data/spec/files/{records → domains_records}/show/success.http +0 -0
  81. data/spec/files/domains_records/update/success.http +21 -0
  82. data/spec/files/domains_sharing/create/success.http +21 -0
  83. data/spec/files/domains_sharing/delete/success.http +17 -0
  84. data/spec/files/domains_sharing/list/success.http +21 -0
  85. data/spec/files/domains_sharing/notfound-domain.http +19 -0
  86. data/spec/files/domains_sharing/notfound.http +19 -0
  87. data/spec/files/domains_whois_privacy/disable/success.http +21 -0
  88. data/spec/files/domains_whois_privacy/enable/success.http +22 -0
  89. data/spec/files/domains_zones/get/success.http +21 -0
  90. data/spec/files/domains_zones/notfound-domain.http +19 -0
  91. data/spec/files/{domains/auto_renewal_disable/notfound.http → nameservers/change/success.http} +23 -21
  92. data/spec/files/nameservers/deregister/success.http +17 -0
  93. data/spec/files/{domains/auto_renewal_enable/notfound.http → nameservers/list/success.http} +23 -21
  94. data/spec/files/nameservers/notfound-domain.http +19 -0
  95. data/spec/files/nameservers/register/badrequest-valueerror.http +19 -0
  96. data/spec/files/nameservers/register/success.http +21 -0
  97. data/spec/files/registrars/check/available.http +19 -0
  98. data/spec/files/registrars/check/registered.http +21 -0
  99. data/spec/files/registrars/register/badrequest-missingdomain.http +19 -0
  100. data/spec/files/registrars/register/badrequest-missingregistrant.http +19 -0
  101. data/spec/files/registrars/register/success.http +21 -0
  102. data/spec/files/registrars/renew/badrequest-missingrenewal.http +19 -0
  103. data/spec/files/registrars/renew/badrequest-unable.http +19 -0
  104. data/spec/files/registrars/renew/success.http +21 -0
  105. data/spec/files/registrars/transfer/success.http +21 -0
  106. data/spec/files/registrars_extended_attributes/list/success.http +21 -0
  107. data/spec/files/registrars_prices/list/success.http +21 -0
  108. data/spec/files/services/applied/success.http +21 -0
  109. data/spec/files/services/apply/success.http +21 -0
  110. data/spec/files/services/available/success.http +21 -0
  111. data/spec/files/services/index/success.http +21 -0
  112. data/spec/files/services/notfound.http +19 -0
  113. data/spec/files/services/show/success.http +21 -0
  114. data/spec/files/services/unapply/success.http +21 -0
  115. data/spec/files/subscription/show/success.http +21 -0
  116. data/spec/files/templates/apply/success.http +21 -0
  117. data/spec/files/templates/create/created.http +22 -0
  118. data/spec/files/templates/delete/success-204.http +21 -0
  119. data/spec/files/templates/delete/success.http +21 -0
  120. data/spec/files/templates/index/success.http +21 -0
  121. data/spec/files/templates/notfound.http +19 -0
  122. data/spec/files/templates/show/success.http +12 -10
  123. data/spec/files/templates/update/success.http +21 -0
  124. data/spec/files/templates_records/create/created.http +22 -0
  125. data/spec/files/templates_records/delete/success-204.http +19 -0
  126. data/spec/files/templates_records/delete/success.http +21 -0
  127. data/spec/files/templates_records/index/success.http +21 -0
  128. data/spec/files/templates_records/notfound.http +19 -0
  129. data/spec/files/templates_records/show/success.http +21 -0
  130. data/spec/files/templates_records/update/success.http +21 -0
  131. data/spec/files/users/user/success.http +21 -0
  132. data/spec/spec_helper.rb +0 -2
  133. metadata +206 -73
  134. data/lib/dnsimple/base.rb +0 -10
  135. data/lib/dnsimple/certificate.rb +0 -143
  136. data/lib/dnsimple/contact.rb +0 -157
  137. data/lib/dnsimple/domain.rb +0 -252
  138. data/lib/dnsimple/extended_attribute.rb +0 -52
  139. data/lib/dnsimple/record.rb +0 -94
  140. data/lib/dnsimple/service.rb +0 -42
  141. data/lib/dnsimple/template.rb +0 -65
  142. data/lib/dnsimple/template_record.rb +0 -80
  143. data/lib/dnsimple/transfer_order.rb +0 -34
  144. data/lib/dnsimple/user.rb +0 -50
  145. data/spec/dnsimple/certificate_spec.rb +0 -59
  146. data/spec/dnsimple/contact_spec.rb +0 -45
  147. data/spec/dnsimple/domain_spec.rb +0 -241
  148. data/spec/dnsimple/extended_attributes_spec.rb +0 -54
  149. data/spec/dnsimple/record_spec.rb +0 -51
  150. data/spec/dnsimple/template_spec.rb +0 -31
  151. data/spec/dnsimple/user_spec.rb +0 -70
  152. data/spec/files/account/user/success.http +0 -19
  153. data/spec/files/certificates/show/notfound.http +0 -17
  154. data/spec/files/domains/auto_renewal_disable/success.http +0 -23
  155. data/spec/files/domains/create/success.http +0 -19
  156. data/spec/files/extended_attributes/ca.http +0 -19
  157. data/spec/files/extended_attributes/success.http +0 -19
  158. data/spec/files/templates/show/notfound.http +0 -17
data/lib/dnsimple/base.rb DELETED
@@ -1,10 +0,0 @@
1
- module Dnsimple
2
- class Base
3
- def initialize(attributes = {})
4
- attributes.each do |key, value|
5
- m = "#{key}=".to_sym
6
- self.send(m, value) if self.respond_to?(m)
7
- end
8
- end
9
- end
10
- end
@@ -1,143 +0,0 @@
1
- module Dnsimple
2
-
3
- # Represents an SSL certificate that has been purchased.
4
- #
5
- # The certificate must also be submitted using the #submit method
6
- # before the Certificate Authority will issue a signed certificate.
7
- class Certificate < Base
8
-
9
- # The Fixnum certificate ID in DNSimple.
10
- attr_accessor :id
11
-
12
- # The Fixnum associated domain ID.
13
- attr_accessor :domain_id
14
-
15
- # The Fixnum associated contact ID.
16
- attr_accessor :contact_id
17
-
18
- # The String subdomain on the certificate.
19
- attr_accessor :name
20
-
21
- # The String state.
22
- attr_accessor :state
23
-
24
- # The String Certificate Signing Request.
25
- attr_accessor :csr
26
-
27
- # The String SSL certificate.
28
- # It is set only if the order issued by the Certificate Authority.
29
- attr_accessor :ssl_certificate
30
-
31
- # The String private key.
32
- # It is set only if DNSimple generated the Certificate Signing Request.
33
- attr_accessor :private_key
34
-
35
- # The String approver email address
36
- # It is set only if the state is submitted.
37
- attr_accessor :approver_email
38
-
39
- # The Array of all emails that can be used to approve the certificate.
40
- # It is set only if the state is configured.
41
- attr_accessor :approver_emails
42
-
43
- # The Date the certificate was create in DNSimple.
44
- attr_accessor :created_at
45
-
46
- # The Date the certificate was last updated in DNSimple.
47
- attr_accessor :updated_at
48
-
49
- # The Date the certificate was configured.
50
- attr_accessor :configured_at
51
-
52
- # The Date the certificate will expire.
53
- attr_accessor :expires_on
54
-
55
- # The associated Domain.
56
- attr_accessor :domain
57
-
58
-
59
- # Purchases a certificate under the given domain with the given name.
60
- #
61
- # The name will be appended to the domain name, and thus should only be the subdomain part.
62
- #
63
- # Invoking this method DNSimple will immediately charge
64
- # your credit card on file at DNSimple for the full certificate price.
65
- #
66
- # For wildcard certificates an asterisk must appear in the name.
67
- #
68
- # @example Purchase a single-hostname certificate
69
- # Dnsimple::Certificate.purchase(domain, 'www', contact)
70
- #
71
- # @example Purchase a wildcard certificate
72
- # Dnsimple::Certificate.purchase(domain, '*', contact)
73
- #
74
- def self.purchase(domain, name, contact, options={})
75
- certificate_hash = {
76
- :name => name,
77
- :contact_id => contact.id
78
- }
79
-
80
- options.merge!({:body => {:certificate => certificate_hash}})
81
-
82
- response = Client.post("/v1/domains/#{domain.name}/certificates", options)
83
-
84
- case response.code
85
- when 201
86
- new({ :domain => domain }.merge(response["certificate"]))
87
- when 406
88
- raise RecordExists, "Certificate for #{domain.name} already exists"
89
- else
90
- raise RequestError.new("Error purchasing certificate", response)
91
- end
92
- end
93
-
94
- # Get an array of all certificates for the given domain.
95
- def self.all(domain, options={})
96
- response = Client.get("/v1/domains/#{domain.name}/certificates", options)
97
-
98
- case response.code
99
- when 200
100
- response.map { |r| new({:domain => domain}.merge(r["certificate"])) }
101
- else
102
- raise RequestError.new("Error listing certificates", response)
103
- end
104
- end
105
-
106
- # Find a specific certificate for the given domain.
107
- def self.find(domain, id, options = {})
108
- response = Client.get("/v1/domains/#{domain.name}/certificates/#{id}", options)
109
-
110
- case response.code
111
- when 200
112
- new({:domain => domain}.merge(response["certificate"]))
113
- when 404
114
- raise RecordNotFound, "Could not find certificate #{id} for domain #{domain.name}"
115
- else
116
- raise RequestError.new("Error finding certificate", response)
117
- end
118
- end
119
-
120
-
121
- # Get the fully-qualified domain name for the certificate. This is the
122
- # domain.name joined with the certificate name, separated by a period.
123
- def fqdn
124
- [name, domain.name].delete_if { |p| p !~ BLANK_REGEX }.join(".")
125
- end
126
-
127
- def submit(approver_email, options={})
128
- raise Error, "Approver email is required" unless approver_email
129
-
130
- options.merge!(:body => {:certificate => {:approver_email => approver_email}})
131
-
132
- response = Client.put("/v1/domains/#{domain.name}/certificates/#{id}/submit", options)
133
-
134
- case response.code
135
- when 200
136
- Certificate.new({ :domain => domain }.merge(response["certificate"]))
137
- else
138
- raise RequestError.new("Error submitting certificate", response)
139
- end
140
- end
141
-
142
- end
143
- end
@@ -1,157 +0,0 @@
1
- module Dnsimple
2
-
3
- # Represents a contact.
4
- class Contact < Base
5
-
6
- Aliases = {
7
- 'first' => 'first_name',
8
- 'last' => 'last_name',
9
- 'state' => 'state_province',
10
- 'province' => 'state_province',
11
- 'state_or_province' => 'state_province',
12
- 'email' => 'email_address',
13
- }
14
-
15
- # The contact ID in DNSimple
16
- attr_accessor :id
17
-
18
- # The contact first name
19
- attr_accessor :first_name
20
-
21
- # The contact last name
22
- attr_accessor :last_name
23
-
24
- # The contact's job title
25
- attr_accessor :job_title
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
-
42
- # The contact street address
43
- attr_accessor :address1
44
-
45
- # Apartment or suite number
46
- attr_accessor :address2
47
-
48
- # The city name
49
- attr_accessor :city
50
-
51
- # The state or province name
52
- attr_accessor :state_province
53
-
54
- # The contact postal code
55
- attr_accessor :postal_code
56
-
57
- # The contact country (as a 2-character country code)
58
- attr_accessor :country
59
-
60
- # When the contact was created in DNSimple
61
- attr_accessor :created_at
62
-
63
- # When the contact was last updated in DNSimple
64
- attr_accessor :updated_at
65
-
66
-
67
- # Map an aliased field name to it's real name. For example, if you
68
- # pass "first" it will be resolved to "first_name", "email" is resolved
69
- # to "email_address" and so on.
70
- def self.resolve(name)
71
- Contact::Aliases[name.to_s] || name
72
- end
73
-
74
- def self.resolve_attributes(attributes)
75
- resolved_attributes = {}
76
- attributes.each do |k, v|
77
- resolved_attributes[resolve(k)] = v
78
- end
79
- resolved_attributes
80
- end
81
-
82
- # Create the contact with the given attributes in DNSimple.
83
- # This method returns a Contact instance of the contact is created
84
- # and raises an error otherwise.
85
- def self.create(attributes, options={})
86
- contact_hash = resolve_attributes(attributes)
87
-
88
- options.merge!({:body => {:contact => contact_hash}})
89
- response = Client.post("/v1/contacts", options)
90
-
91
- case response.code
92
- when 201
93
- new(response["contact"])
94
- else
95
- raise RequestError.new("Error creating contact", response)
96
- end
97
- end
98
-
99
- def self.find(id, options={})
100
- response = Client.get("/v1/contacts/#{id}", options)
101
-
102
- case response.code
103
- when 200
104
- new(response["contact"])
105
- when 404
106
- raise RecordNotFound, "Could not find contact #{id}"
107
- else
108
- raise RequestError.new("Error finding contact", response)
109
- end
110
- end
111
-
112
- def self.all(options={})
113
- response = Client.get("/v1/contacts", options)
114
-
115
- case response.code
116
- when 200
117
- response.map { |r| new(r["contact"]) }
118
- else
119
- raise RequestError.new("Error listing contacts", response)
120
- end
121
- end
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[Contact.resolve(attribute)] = self.send(attribute)
133
- end
134
-
135
- options.merge!({:body => {:contact => contact_hash}})
136
-
137
- response = 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.
148
- #
149
- # WARNING: this cannot be undone.
150
- #
151
- def delete(options={})
152
- Client.delete("/v1/contacts/#{id}", options)
153
- end
154
- alias :destroy :delete
155
-
156
- end
157
- end
@@ -1,252 +0,0 @@
1
- module Dnsimple
2
- class Domain < Base
3
-
4
- # The Fixnum domain ID in DNSimple.
5
- attr_accessor :id
6
-
7
- # The Fixnum associated user ID.
8
- attr_accessor :user_id
9
-
10
- # The Fixnum associated registrant ID.
11
- attr_accessor :registrant_id
12
-
13
- # The String name.
14
- attr_accessor :name
15
-
16
- # The String state.
17
- attr_accessor :state
18
-
19
- # The String API token
20
- attr_accessor :token
21
-
22
- # Is the domain set to auto renew?
23
- attr_accessor :auto_renew
24
-
25
- # Is the whois information protected?
26
- attr_accessor :whois_protected
27
-
28
- # The Date the domain will expire.
29
- attr_accessor :expires_on
30
-
31
- # The Date the domain was created in DNSimple.
32
- attr_accessor :created_at
33
-
34
- # The Date the domain was last update in DNSimple.
35
- attr_accessor :updated_at
36
-
37
-
38
- # Lists the domains in the DNSimple account.
39
- #
40
- # @return [Array<Domain>]
41
- def self.list(options = {})
42
- response = Client.get("/v1/domains", options)
43
-
44
- case response.code
45
- when 200
46
- response.map { |r| new(r["domain"]) }
47
- else
48
- raise RequestError.new("Error listing domains", response)
49
- end
50
- end
51
-
52
- def self.all(*args); list(*args); end
53
-
54
- # Creates the domain in the DNSimple account.
55
- #
56
- # @param [String] name The domain name.
57
- #
58
- # @return [Domain] The newly created domain.
59
- # @raise [RequestError] When the request fails.
60
- def self.create(name)
61
- options = { body: { domain: { name: name }}}
62
-
63
- response = Client.post("/v1/domains", options)
64
-
65
- case response.code
66
- when 201
67
- new(response["domain"])
68
- else
69
- raise RequestError.new("Error creating domain", response)
70
- end
71
- end
72
-
73
- # Gets a specific domain in the account.
74
- #
75
- # @param [Fixnum,String] id Either the numeric ID or the fully-qualified domain name.
76
- #
77
- # @return [Domain] The domain.
78
- # @raise [RecordNotFound] When the domain doesn't exist.
79
- # @raise [RequestError] When the request fails.
80
- def self.find(id)
81
- response = Client.get("/v1/domains/#{id}")
82
-
83
- case response.code
84
- when 200
85
- new(response["domain"])
86
- when 404
87
- raise RecordNotFound, "Could not find domain #{id}"
88
- else
89
- raise RequestError.new("Error finding domain", response)
90
- end
91
- end
92
-
93
- # Deletes a specific domain from the account.
94
- #
95
- # WARNING: this cannot be undone.
96
- #
97
- # @param [Fixnum,String] id Either the numeric ID or the fully-qualified domain name.
98
- #
99
- # @return [void]
100
- # @raise [RecordNotFound] When the domain doesn't exist.
101
- # @raise [RequestError] When the request fails.
102
- def self.delete(id)
103
- response = Client.delete("/v1/domains/#{id}")
104
-
105
- case response.code
106
- when 200, 204
107
- true
108
- when 404
109
- raise RecordNotFound, "Could not find domain #{id}"
110
- else
111
- raise RequestError.new("Error deleting domain", response)
112
- end
113
- end
114
-
115
- # Check the availability of a name
116
- def self.check(name, options={})
117
- response = Client.get("/v1/domains/#{name}/check", options)
118
-
119
- case response.code
120
- when 200
121
- "registered"
122
- when 404
123
- "available"
124
- else
125
- raise RequestError.new("Error checking availability", response)
126
- end
127
- end
128
-
129
- # Purchase a domain name.
130
- def self.register(name, registrant={}, extended_attributes={}, options={})
131
- body = {:domain => {:name => name}}
132
- if registrant
133
- if registrant[:id]
134
- body[:domain][:registrant_id] = registrant[:id]
135
- else
136
- body.merge!(:contact => Contact.resolve_attributes(registrant))
137
- end
138
- end
139
- body.merge!(:extended_attribute => extended_attributes)
140
- options.merge!({:body => body})
141
-
142
- response = Client.post("/v1/domain_registrations", options)
143
-
144
- case response.code
145
- when 201
146
- return Domain.new(response["domain"])
147
- else
148
- raise RequestError.new("Error registering domain", response)
149
- end
150
- end
151
-
152
-
153
- # Enable auto_renew on the domain
154
- def enable_auto_renew
155
- return if auto_renew
156
- auto_renew!(:post)
157
- end
158
-
159
- # Disable auto_renew on the domain
160
- def disable_auto_renew
161
- return unless auto_renew
162
- auto_renew!(:delete)
163
- end
164
-
165
- # Deletes this domain from the account.
166
- #
167
- # WARNING: this cannot be undone.
168
- #
169
- # @see .delete
170
- def delete
171
- self.class.delete(name)
172
- end
173
- alias :destroy :delete
174
-
175
- # Apply the given named template to the domain. This will add
176
- # all of the records in the template to the domain.
177
- def apply(template, options={})
178
- options.merge!(:body => {})
179
- template = resolve_template(template)
180
-
181
- Client.post("/v1/domains/#{name}/templates/#{template.id}/apply", options)
182
- end
183
-
184
- def resolve_template(template)
185
- case template
186
- when Template
187
- template
188
- else
189
- Template.find(template)
190
- end
191
- end
192
-
193
- def applied_services(options={})
194
- response = Client.get("/v1/domains/#{name}/applied_services", options)
195
-
196
- case response.code
197
- when 200
198
- response.map { |r| Service.new(r["service"]) }
199
- else
200
- raise RequestError.new("Error listing applied services", response)
201
- end
202
- end
203
-
204
- def available_services(options={})
205
- response = Client.get("/v1/domains/#{name}/available_services", options)
206
-
207
- case response.code
208
- when 200
209
- response.map { |r| Service.new(r["service"]) }
210
- else
211
- raise RequestError.new("Error listing available services", response)
212
- end
213
- end
214
-
215
- def add_service(id_or_short_name, options={})
216
- options.merge!(:body => {:service => {:id => id_or_short_name}})
217
- response = Client.post("/v1/domains/#{name}/applied_services", options)
218
-
219
- case response.code
220
- when 200
221
- true
222
- else
223
- raise RequestError.new("Error adding service", response)
224
- end
225
- end
226
-
227
- def remove_service(id, options={})
228
- response = Client.delete("/v1/domains/#{name}/applied_services/#{id}", options)
229
-
230
- case response.code
231
- when 200
232
- true
233
- else
234
- raise RequestError.new("Error removing service", response)
235
- end
236
- end
237
-
238
-
239
- private
240
-
241
- def auto_renew!(method)
242
- response = Client.send(method, "/v1/domains/#{name}/auto_renewal")
243
- case response.code
244
- when 200
245
- self.auto_renew = response['domain']['auto_renew']
246
- else
247
- raise RequestError.new("Error setting auto_renew", response)
248
- end
249
- end
250
-
251
- end
252
- end