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
@@ -0,0 +1,105 @@
1
+ module Dnsimple
2
+ class Client
3
+ class RegistrarsService < ClientService
4
+
5
+ # Checks the availability of a domain name.
6
+ #
7
+ # @see http://developer.dnsimple.com/domains/registry/#check
8
+ #
9
+ # @param [#to_s] name The domain name to check.
10
+ #
11
+ # @return [String] "available" or "registered"
12
+ # @raise [RequestError] When the request fails.
13
+ def check(name, options={})
14
+ begin
15
+ client.get("v1/domains/#{name}/check", options)
16
+ "registered"
17
+ rescue RecordNotFound
18
+ "available"
19
+ end
20
+ end
21
+
22
+ # Registers a domain.
23
+ #
24
+ # @see http://developer.dnsimple.com/domains/registry/#register
25
+ #
26
+ # @param [#to_s] name The domain name to register.
27
+ # @param [Fixnum] registrant_id The id of the contact to use as registrant.
28
+ # @param [Hash] extended_attributes
29
+ # @param [Hash] options
30
+ #
31
+ # @return [Struct::Domain]
32
+ # @raise [RequestError] When the request fails.
33
+ def register(name, registrant_id, extended_attributes = {}, options = {})
34
+ options = Extra.deep_merge(options, { domain: { name: name, registrant_id: registrant_id }, extended_attribute: extended_attributes })
35
+ response = client.post("v1/domain_registrations", options)
36
+
37
+ Struct::Domain.new(response["domain"])
38
+ end
39
+
40
+ # Transfers a domain.
41
+ #
42
+ # @see http://developer.dnsimple.com/domains/registry/#transfer
43
+ #
44
+ # @param [#to_s] name The domain name to register.
45
+ # @param [String] auth_code
46
+ # @param [Fixnum] registrant_id The id of the contact to use as registrant.
47
+ # @param [Hash] extended_attributes
48
+ # @param [Hash] options
49
+ #
50
+ # @return [Struct::TransferOrder]
51
+ # @raise [RequestError] When the request fails.
52
+ def transfer(name, auth_code, registrant_id, extended_attributes = {}, options = {})
53
+ options = Extra.deep_merge(options, { domain: { name: name, registrant_id: registrant_id }, extended_attribute: extended_attributes, transfer_order: { authinfo: auth_code }})
54
+ response = client.post("v1/domain_transfers", options)
55
+
56
+ Struct::TransferOrder.new(response["transfer_order"])
57
+ end
58
+
59
+ # Renew a domain.
60
+ #
61
+ # @see http://developer.dnsimple.com/domains/registry/#renew
62
+ #
63
+ # @param [#to_s] name The domain name to renew.
64
+ # @param [Hash] options
65
+ #
66
+ # @return [Struct::Domain]
67
+ # @raise [RequestError] When the request fails.
68
+ def renew(name, options = {})
69
+ options = Extra.deep_merge(options, { domain: { name: name }})
70
+ response = client.post("v1/domain_renewals", options)
71
+
72
+ Struct::Domain.new(response["domain"])
73
+ end
74
+
75
+
76
+ # List the extended attributes for a TLD.
77
+ #
78
+ # @see http://developer.dnsimple.com/registrar/extended-attributes/#list
79
+ #
80
+ # @param [#to_s] tld The TLD name.
81
+ #
82
+ # @return [Array<Struct::ExtendedAttribute>]
83
+ # @raise [RequestError] When the request fails.
84
+ def list_extended_attributes(tld)
85
+ response = client.get("v1/extended_attributes/#{tld}")
86
+
87
+ response.map { |r| Struct::ExtendedAttribute.new(r) }
88
+ end
89
+
90
+
91
+ # List all the TLD prices.
92
+ #
93
+ # @see http://developer.dnsimple.com/registrar/prices/#list
94
+ #
95
+ # @return [Array<Struct::Price>]
96
+ # @raise [RequestError] When the request fails.
97
+ def list_prices
98
+ response = client.get("v1/prices")
99
+
100
+ response.map { |r| Struct::Price.new(r["price"]) }
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,95 @@
1
+ module Dnsimple
2
+ class Client
3
+ class ServicesService < ClientService
4
+
5
+ # Lists the supported services.
6
+ #
7
+ # @see http://developer.dnsimple.com/services/#list
8
+ #
9
+ # @return [Array<Struct::Service>]
10
+ # @raise [RequestError] When the request fails.
11
+ def list
12
+ response = client.get("v1/services")
13
+
14
+ response.map { |r| Struct::Service.new(r["service"]) }
15
+ end
16
+
17
+ # Gets a service.
18
+ #
19
+ # @see http://developer.dnsimple.com/services/#get
20
+ #
21
+ # @param [Fixnum] service The service id.
22
+ #
23
+ # @return [Struct::Service]
24
+ # @raise [RecordNotFound]
25
+ # @raise [RequestError] When the request fails.
26
+ def find(service)
27
+ response = client.get("v1/services/#{service}")
28
+
29
+ Struct::Service.new(response["service"])
30
+ end
31
+
32
+ # Lists the services applied to a domain.
33
+ #
34
+ # @see http://developer.dnsimple.com/services/#applied
35
+ #
36
+ # @param [#to_s] domain The domain id or domain name.
37
+ #
38
+ # @return [Array<Struct::Service>]
39
+ # @raise [RecordNotFound]
40
+ # @raise [RequestError] When the request fails.
41
+ def applied(domain)
42
+ response = client.get("v1/domains/#{domain}/applied_services")
43
+
44
+ response.map { |r| Struct::Service.new(r["service"]) }
45
+ end
46
+
47
+ # Lists the services not applied to a domain.
48
+ #
49
+ # @see http://developer.dnsimple.com/services/#available
50
+ #
51
+ # @param [#to_s] domain The domain id or domain name.
52
+ #
53
+ # @return [Array<Struct::Service>]
54
+ # @raise [RecordNotFound]
55
+ # @raise [RequestError] When the request fails.
56
+ def available(domain)
57
+ response = client.get("v1/domains/#{domain}/available_services")
58
+
59
+ response.map { |r| Struct::Service.new(r["service"]) }
60
+ end
61
+
62
+ # Applies a service to a domain.
63
+ #
64
+ # @see http://developer.dnsimple.com/services/#apply
65
+ #
66
+ # @param [#to_s] domain The domain id or domain name.
67
+ # @param [Fixnum] service The service id.
68
+ #
69
+ # @return [void]
70
+ # @raise [RecordNotFound]
71
+ # @raise [RequestError] When the request fails.
72
+ def apply(domain, service)
73
+ options = { service: { id: service }}
74
+ response = client.post("v1/domains/#{domain}/applied_services", options)
75
+ response.code == 200
76
+ end
77
+
78
+ # Un-applies a service from a domain.
79
+ #
80
+ # @see http://developer.dnsimple.com/services/#unapply
81
+ #
82
+ # @param [#to_s] domain The domain id or domain name.
83
+ # @param [Fixnum] service The service id.
84
+ #
85
+ # @return [void]
86
+ # @raise [RecordNotFound]
87
+ # @raise [RequestError] When the request fails.
88
+ def unapply(domain, service)
89
+ response = client.delete("v1/domains/#{domain}/applied_services/#{service}")
90
+ response.code == 200
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,180 @@
1
+ module Dnsimple
2
+ class Client
3
+ class TemplatesService < ClientService
4
+
5
+ # Lists the templates in the account.
6
+ #
7
+ # @see http://developer.dnsimple.com/templates/#list
8
+ #
9
+ # @return [Array<Struct::Template>]
10
+ # @raise [RequestError] When the request fails.
11
+ def list
12
+ response = client.get("v1/templates")
13
+
14
+ response.map { |r| Struct::Template.new(r["dns_template"]) }
15
+ end
16
+
17
+ # Creates a template in the account.
18
+ #
19
+ # @see http://developer.dnsimple.com/templates/#create
20
+ #
21
+ # @param [Hash] attributes
22
+ #
23
+ # @return [Struct::Template]
24
+ # @raise [RequestError] When the request fails.
25
+ def create(attributes = {})
26
+ Extra.validate_mandatory_attributes(attributes, [:name, :short_name])
27
+ options = { dns_template: attributes }
28
+ response = client.post("v1/templates", options)
29
+
30
+ Struct::Template.new(response["dns_template"])
31
+ end
32
+
33
+ # Gets a template from the account.
34
+ #
35
+ # @see http://developer.dnsimple.com/templates/#get
36
+ #
37
+ # @param [#to_s] template The template id or short-name.
38
+ #
39
+ # @return [Struct::Template]
40
+ # @raise [RecordNotFound]
41
+ # @raise [RequestError] When the request fails.
42
+ def find(template)
43
+ response = client.get("v1/templates/#{template}")
44
+
45
+ Struct::Template.new(response["dns_template"])
46
+ end
47
+
48
+ # Updates a template in the account.
49
+ #
50
+ # @see http://developer.dnsimple.com/templates/#update
51
+ #
52
+ # @param [#to_s] template The template id or short-name.
53
+ # @param [Hash] attributes
54
+ #
55
+ # @return [Struct::Template]
56
+ # @raise [RecordNotFound]
57
+ # @raise [RequestError] When the request fails.
58
+ def update(template, attributes = {})
59
+ options = { dns_template: attributes }
60
+ response = client.put("v1/templates/#{template}", options)
61
+
62
+ Struct::Template.new(response["dns_template"])
63
+ end
64
+
65
+ # Deletes a template from the account.
66
+ #
67
+ # WARNING: this cannot be undone.
68
+ #
69
+ # @see http://developer.dnsimple.com/templates/#delete
70
+ #
71
+ # @param [#to_s] template The template id or short-name.
72
+ #
73
+ # @return [void]
74
+ # @raise [RecordNotFound]
75
+ # @raise [RequestError] When the request fails.
76
+ def delete(template)
77
+ client.delete("v1/templates/#{template}")
78
+ end
79
+
80
+
81
+ # Applies the template to the domain.
82
+ #
83
+ # @see http://developer.dnsimple.com/templates/#apply
84
+ #
85
+ # @param [#to_s] domain The domain id or domain name.
86
+ # @param [#to_s] template The template id or short-name.
87
+ #
88
+ # @return [void]
89
+ # @raise [RecordNotFound]
90
+ # @raise [RequestError] When the request fails.
91
+ def apply(domain, template)
92
+ response = client.post("v1/domains/#{domain}/templates/#{template}/apply")
93
+ response.code == 200
94
+ end
95
+
96
+
97
+ # Lists the records for a template.
98
+ #
99
+ # @see http://developer.dnsimple.com/templates/records/#list
100
+ #
101
+ # @param [#to_s] template The template id or short-name.
102
+ #
103
+ # @return [Array<Struct::TemplateRecord>]
104
+ # @raise [RecordNotFound]
105
+ # @raise [RequestError] When the request fails.
106
+ def list_records(template)
107
+ response = client.get("v1/templates/#{template}/records")
108
+
109
+ response.map { |r| Struct::TemplateRecord.new(r["dns_template_record"]) }
110
+ end
111
+
112
+ # Creates a record for a template.
113
+ #
114
+ # @see http://developer.dnsimple.com/templates/records/#create
115
+ #
116
+ # @param [#to_s] template The template id or short-name.
117
+ # @param [Hash] attributes
118
+ #
119
+ # @return [Struct::TemplateRecord]
120
+ # @raise [RecordNotFound]
121
+ # @raise [RequestError] When the request fails.
122
+ def create_record(template, attributes = {})
123
+ Extra.validate_mandatory_attributes(attributes, [:name, :record_type, :content])
124
+ options = { dns_template_record: attributes }
125
+ response = client.post("v1/templates/#{template}/records", options)
126
+
127
+ Struct::TemplateRecord.new(response["dns_template_record"])
128
+ end
129
+
130
+ # Gets a record for a template.
131
+ #
132
+ # @see http://developer.dnsimple.com/templates/records/#delete
133
+ #
134
+ # @param [#to_s] template The template id or short-name.
135
+ # @param [Fixnum] record The record id.
136
+ #
137
+ # @return [Struct::TemplateRecord]
138
+ # @raise [RecordNotFound]
139
+ # @raise [RequestError] When the request fails.
140
+ def find_record(template, record)
141
+ response = client.get("v1/templates/#{template}/records/#{record}")
142
+
143
+ Struct::TemplateRecord.new(response["dns_template_record"])
144
+ end
145
+
146
+ # Updates a record for a template.
147
+ #
148
+ # @see http://developer.dnsimple.com/templates/#update
149
+ #
150
+ # @param [#to_s] template The template id or short-name.
151
+ # @param [Fixnum] record The record id.
152
+ # @param [Hash] attributes
153
+ #
154
+ # @return [Struct::TemplateRecord]
155
+ # @raise [RecordNotFound]
156
+ # @raise [RequestError] When the request fails.
157
+ def update_record(template, record, attributes = {})
158
+ options = { dns_template_record: attributes }
159
+ response = client.put("v1/templates/#{template}/records/#{record}", options)
160
+
161
+ Struct::TemplateRecord.new(response["dns_template_record"])
162
+ end
163
+
164
+ # Deletes a record for a template.
165
+ #
166
+ # @see http://developer.dnsimple.com/templates/records/#get
167
+ #
168
+ # @param [#to_s] template The template id or short-name.
169
+ # @param [Fixnum] record The record id.
170
+ #
171
+ # @return [Template]
172
+ # @raise [RecordNotFound]
173
+ # @raise [RequestError] When the request fails.
174
+ def delete_record(template, record)
175
+ client.delete("v1/templates/#{template}/records/#{record}")
176
+ end
177
+
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,37 @@
1
+ module Dnsimple
2
+ class Client
3
+ class UsersService < ClientService
4
+
5
+ # Fetches the information about the authenticated user.
6
+ #
7
+ # @return [Struct::User] The authenticated user.
8
+ # @raise [RequestError] When the request fails.
9
+ def user
10
+ response = client.get("v1/user")
11
+
12
+ Struct::User.new(response["user"])
13
+ end
14
+
15
+ # Requests a new two-factor authentication exchange token.
16
+ #
17
+ # The exchange-token is required to validate API requests
18
+ # using HTTP Basic Authentication when the account has two-factor authentication enabled.
19
+ #
20
+ # @see http://developer.dnsimple.com/authentication/#twofa
21
+ #
22
+ # @example Request an Exchange Token
23
+ # Dnsimple::User.two_factor_exchange_token('0000000')
24
+ # # => "cda038832591e34f5df642ce2b61dc78"
25
+ #
26
+ # @param [String] otp_token the two-factor one time (OTP) token.
27
+ #
28
+ # @return [String] The two-factor API exchange token.
29
+ # @raise [AuthenticationFailed] if the provided OTP token is invalid.
30
+ def exchange_token(otp_token)
31
+ response = client.get("v1/user", headers: { Client::HEADER_2FA_STRICT => "1", Client::HEADER_OTP_TOKEN => otp_token })
32
+ response.headers[Client::HEADER_EXCHANGE_TOKEN]
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ module Dnsimple
2
+
3
+ # {Client} backwards compatibility
4
+ module Compatibility
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.class_eval do
8
+ class << self
9
+ attr_accessor :base_uri, :username, :password, :exchange_token, :api_token, :domain_api_token
10
+ end
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def client
16
+ options = {}
17
+ options[:api_endpoint] = base_uri if base_uri
18
+ options[:username] = username if username
19
+ options[:password] = password if password
20
+ options[:api_token] = api_token if api_token
21
+ options[:domain_api_token] = domain_api_token if domain_api_token
22
+ options[:exchange_token] = exchange_token if exchange_token
23
+
24
+ new(options)
25
+ end
26
+
27
+ def get(*args)
28
+ client.get(*args)
29
+ end
30
+
31
+ def post(*args)
32
+ client.post(*args)
33
+ end
34
+
35
+ def put(*args)
36
+ client.put(*args)
37
+ end
38
+
39
+ def delete(*args)
40
+ client.delete(*args)
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end