dnsimple 2.2.0 → 3.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -1
  4. data/CHANGELOG.md +13 -2
  5. data/CONTRIBUTING.md +35 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +30 -82
  9. data/dnsimple.gemspec +2 -1
  10. data/lib/dnsimple.rb +0 -2
  11. data/lib/dnsimple/client.rb +64 -64
  12. data/lib/dnsimple/client/clients.rb +82 -58
  13. data/lib/dnsimple/client/contacts.rb +74 -37
  14. data/lib/dnsimple/client/domains.rb +82 -28
  15. data/lib/dnsimple/client/domains_email_forwards.rb +107 -0
  16. data/lib/dnsimple/client/identity.rb +38 -0
  17. data/lib/dnsimple/client/oauth.rb +42 -0
  18. data/lib/dnsimple/client/registrar.rb +64 -72
  19. data/lib/dnsimple/client/registrar_auto_renewal.rb +41 -0
  20. data/lib/dnsimple/client/registrar_whois_privacy.rb +74 -0
  21. data/lib/dnsimple/client/tlds.rb +88 -0
  22. data/lib/dnsimple/client/webhooks.rb +82 -0
  23. data/lib/dnsimple/client/zones.rb +68 -0
  24. data/lib/dnsimple/client/zones_records.rb +127 -0
  25. data/lib/dnsimple/default.rb +10 -17
  26. data/lib/dnsimple/error.rb +5 -8
  27. data/lib/dnsimple/extra.rb +1 -1
  28. data/lib/dnsimple/response.rb +80 -0
  29. data/lib/dnsimple/struct.rb +13 -14
  30. data/lib/dnsimple/struct/account.rb +13 -0
  31. data/lib/dnsimple/struct/contact.rb +6 -3
  32. data/lib/dnsimple/struct/domain.rb +10 -10
  33. data/lib/dnsimple/struct/domain_check.rb +16 -0
  34. data/lib/dnsimple/struct/email_forward.rb +11 -1
  35. data/lib/dnsimple/struct/oauth_token.rb +19 -0
  36. data/lib/dnsimple/struct/record.rb +25 -7
  37. data/lib/dnsimple/struct/tld.rb +22 -0
  38. data/lib/dnsimple/struct/user.rb +3 -7
  39. data/lib/dnsimple/struct/webhook.rb +13 -0
  40. data/lib/dnsimple/struct/whois_privacy.rb +8 -5
  41. data/lib/dnsimple/struct/zone.rb +25 -0
  42. data/lib/dnsimple/version.rb +1 -1
  43. data/spec/dnsimple/client/client_service_spec.rb +37 -0
  44. data/spec/dnsimple/client/contacts_spec.rb +108 -78
  45. data/spec/dnsimple/client/domains_email_forwards_spec.rb +190 -0
  46. data/spec/dnsimple/client/domains_spec.rb +121 -58
  47. data/spec/dnsimple/client/identity_spec.rb +56 -0
  48. data/spec/dnsimple/client/oauth_spec.rb +48 -0
  49. data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +80 -0
  50. data/spec/dnsimple/client/registrar_spec.rb +109 -122
  51. data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +119 -0
  52. data/spec/dnsimple/client/tlds_spec.rb +139 -0
  53. data/spec/dnsimple/client/webhooks_spec.rb +142 -0
  54. data/spec/dnsimple/client/zones_records_spec.rb +277 -0
  55. data/spec/dnsimple/client/zones_spec.rb +109 -0
  56. data/spec/dnsimple/client_spec.rb +34 -46
  57. data/spec/dnsimple/extra_spec.rb +22 -0
  58. data/spec/{files → fixtures.http}/badgateway.http +14 -14
  59. data/spec/fixtures.http/checkDomain/success.http +17 -0
  60. data/spec/fixtures.http/createContact/created.http +17 -0
  61. data/spec/fixtures.http/createDomain/created.http +16 -0
  62. data/spec/fixtures.http/createEmailForward/created.http +17 -0
  63. data/spec/fixtures.http/createWebhook/created.http +17 -0
  64. data/spec/fixtures.http/createZoneRecord/created.http +17 -0
  65. data/spec/fixtures.http/deleteContact/success.http +13 -0
  66. data/spec/fixtures.http/deleteDomain/success.http +13 -0
  67. data/spec/fixtures.http/deleteEmailForward/success.http +12 -0
  68. data/spec/fixtures.http/deleteWebhook/success.http +13 -0
  69. data/spec/fixtures.http/deleteZoneRecord/success.http +13 -0
  70. data/spec/fixtures.http/disableAutoRenewal/success.http +12 -0
  71. data/spec/fixtures.http/disableWhoisPrivacy/success.http +17 -0
  72. data/spec/fixtures.http/enableAutoRenewal/success.http +12 -0
  73. data/spec/fixtures.http/enableWhoisPrivacy/created.http +17 -0
  74. data/spec/fixtures.http/enableWhoisPrivacy/success.http +17 -0
  75. data/spec/fixtures.http/getContact/success.http +17 -0
  76. data/spec/fixtures.http/getDomain/success.http +16 -0
  77. data/spec/fixtures.http/getEmailForward/success.http +17 -0
  78. data/spec/fixtures.http/getTld/success.http +17 -0
  79. data/spec/fixtures.http/getTldExtendedAttributes/success-noattributes.http +17 -0
  80. data/spec/fixtures.http/getTldExtendedAttributes/success.http +17 -0
  81. data/spec/fixtures.http/getWebhook/success.http +17 -0
  82. data/spec/fixtures.http/getWhoisPrivacy/success.http +17 -0
  83. data/spec/fixtures.http/getZone/success.http +17 -0
  84. data/spec/fixtures.http/getZoneRecord/success.http +17 -0
  85. data/spec/fixtures.http/listContacts/success.http +17 -0
  86. data/spec/fixtures.http/listDomains/success.http +16 -0
  87. data/spec/fixtures.http/listEmailForwards/success.http +17 -0
  88. data/spec/fixtures.http/listTlds/success.http +17 -0
  89. data/spec/fixtures.http/listWebhooks/success.http +17 -0
  90. data/spec/fixtures.http/listZoneRecords/success.http +17 -0
  91. data/spec/fixtures.http/listZones/success.http +17 -0
  92. data/spec/fixtures.http/notfound-contact.http +12 -0
  93. data/spec/fixtures.http/notfound-domain.http +12 -0
  94. data/spec/fixtures.http/notfound-emailforward.http +12 -0
  95. data/spec/fixtures.http/notfound-record.http +12 -0
  96. data/spec/fixtures.http/notfound-webhook.http +12 -0
  97. data/spec/fixtures.http/notfound-zone.http +12 -0
  98. data/spec/fixtures.http/oauthAccessToken/success.http +17 -0
  99. data/spec/fixtures.http/pages-1of3.http +16 -0
  100. data/spec/fixtures.http/pages-2of3.http +16 -0
  101. data/spec/fixtures.http/pages-3of3.http +16 -0
  102. data/spec/fixtures.http/registerDomain/success.http +17 -0
  103. data/spec/fixtures.http/renewDomain/error-tooearly.http +15 -0
  104. data/spec/fixtures.http/renewDomain/success.http +17 -0
  105. data/spec/fixtures.http/resetDomainToken/success.http +17 -0
  106. data/spec/fixtures.http/response.http +16 -0
  107. data/spec/fixtures.http/transferDomain/error-indnsimple.http +15 -0
  108. data/spec/fixtures.http/transferDomain/error-missing-authcode.http +15 -0
  109. data/spec/fixtures.http/transferDomain/success.http +17 -0
  110. data/spec/fixtures.http/transferDomainOut/success.http +13 -0
  111. data/spec/fixtures.http/updateContact/success.http +17 -0
  112. data/spec/fixtures.http/updateZoneRecord/success.http +17 -0
  113. data/spec/fixtures.http/whoami/success.http +16 -0
  114. data/spec/fixtures.http/whoami/success_account.http +16 -0
  115. data/spec/fixtures.http/whoami/success_user.http +16 -0
  116. data/spec/spec_helper.rb +0 -6
  117. data/spec/support/helpers.rb +4 -4
  118. metadata +161 -238
  119. data/lib/dnsimple/client/certificates.rb +0 -100
  120. data/lib/dnsimple/client/domains_autorenewal.rb +0 -35
  121. data/lib/dnsimple/client/domains_forwards.rb +0 -71
  122. data/lib/dnsimple/client/domains_privacy.rb +0 -35
  123. data/lib/dnsimple/client/domains_records.rb +0 -90
  124. data/lib/dnsimple/client/domains_sharing.rb +0 -54
  125. data/lib/dnsimple/client/domains_zones.rb +0 -22
  126. data/lib/dnsimple/client/name_servers.rb +0 -71
  127. data/lib/dnsimple/client/services.rb +0 -37
  128. data/lib/dnsimple/client/services_domains.rb +0 -68
  129. data/lib/dnsimple/client/templates.rb +0 -88
  130. data/lib/dnsimple/client/templates_domains.rb +0 -23
  131. data/lib/dnsimple/client/templates_records.rb +0 -88
  132. data/lib/dnsimple/client/users.rb +0 -39
  133. data/lib/dnsimple/client/vanity_name_servers.rb +0 -39
  134. data/lib/dnsimple/compatibility.rb +0 -46
  135. data/lib/dnsimple/struct/certificate.rb +0 -56
  136. data/lib/dnsimple/struct/membership.rb +0 -22
  137. data/lib/dnsimple/struct/price.rb +0 -16
  138. data/lib/dnsimple/struct/service.rb +0 -19
  139. data/lib/dnsimple/struct/template.rb +0 -19
  140. data/lib/dnsimple/struct/template_record.rb +0 -24
  141. data/lib/dnsimple/struct/transfer_order.rb +0 -10
  142. data/spec/dnsimple/client/certificates_spec.rb +0 -196
  143. data/spec/dnsimple/client/domains_autorenewals_spec.rb +0 -72
  144. data/spec/dnsimple/client/domains_forwards_spec.rb +0 -146
  145. data/spec/dnsimple/client/domains_privacy_spec.rb +0 -74
  146. data/spec/dnsimple/client/domains_records_spec.rb +0 -191
  147. data/spec/dnsimple/client/domains_sharing_spec.rb +0 -109
  148. data/spec/dnsimple/client/domains_zones_spec.rb +0 -40
  149. data/spec/dnsimple/client/name_servers_spec.rb +0 -131
  150. data/spec/dnsimple/client/services_domains_spec.rb +0 -101
  151. data/spec/dnsimple/client/services_spec.rb +0 -69
  152. data/spec/dnsimple/client/templates_domains_spec.rb +0 -38
  153. data/spec/dnsimple/client/templates_records_spec.rb +0 -180
  154. data/spec/dnsimple/client/templates_spec.rb +0 -166
  155. data/spec/dnsimple/client/users_spec.rb +0 -70
  156. data/spec/dnsimple/client/vanity_name_servers_spec.rb +0 -61
  157. data/spec/dnsimple/compatibility_spec.rb +0 -57
  158. data/spec/files/2fa/error-badtoken.http +0 -22
  159. data/spec/files/2fa/error-required.http +0 -23
  160. data/spec/files/2fa/exchange-token.http +0 -22
  161. data/spec/files/certificates/configure/success.http +0 -19
  162. data/spec/files/certificates/get/success.http +0 -19
  163. data/spec/files/certificates/list/success.http +0 -19
  164. data/spec/files/certificates/notfound.http +0 -19
  165. data/spec/files/certificates/purchase/success.http +0 -19
  166. data/spec/files/certificates/submit/success.http +0 -19
  167. data/spec/files/contacts/contact/success.http +0 -19
  168. data/spec/files/contacts/contacts/success.http +0 -23
  169. data/spec/files/contacts/create_contact/badrequest-missingcontact.http +0 -19
  170. data/spec/files/contacts/create_contact/badrequest-validationerror.http +0 -19
  171. data/spec/files/contacts/create_contact/created.http +0 -22
  172. data/spec/files/contacts/delete_contact/success-204.http +0 -18
  173. data/spec/files/contacts/delete_contact/success.http +0 -19
  174. data/spec/files/contacts/notfound-contact.http +0 -19
  175. data/spec/files/contacts/update_contact/success.http +0 -21
  176. data/spec/files/domains/create_domain/created.http +0 -21
  177. data/spec/files/domains/create_forward/created.http +0 -22
  178. data/spec/files/domains/create_membership/success.http +0 -21
  179. data/spec/files/domains/create_record/created.http +0 -21
  180. data/spec/files/domains/delete_domain/success-204.http +0 -18
  181. data/spec/files/domains/delete_domain/success.http +0 -19
  182. data/spec/files/domains/delete_forward/success.http +0 -17
  183. data/spec/files/domains/delete_membership/success.http +0 -17
  184. data/spec/files/domains/delete_record/success-204.http +0 -18
  185. data/spec/files/domains/delete_record/success.http +0 -19
  186. data/spec/files/domains/disable_auto_renewal/success.http +0 -21
  187. data/spec/files/domains/disable_whois_privacy/success.http +0 -21
  188. data/spec/files/domains/domain/success.http +0 -21
  189. data/spec/files/domains/domains/success.http +0 -21
  190. data/spec/files/domains/enable_auto_renewal/success.http +0 -21
  191. data/spec/files/domains/enable_whois_privacy/success.http +0 -22
  192. data/spec/files/domains/forward/success.http +0 -21
  193. data/spec/files/domains/forwards/success.http +0 -21
  194. data/spec/files/domains/memberships/success.http +0 -21
  195. data/spec/files/domains/notfound-domain.http +0 -19
  196. data/spec/files/domains/notfound-forward.http +0 -19
  197. data/spec/files/domains/notfound-membership.http +0 -19
  198. data/spec/files/domains/record/success.http +0 -19
  199. data/spec/files/domains/records/success.http +0 -19
  200. data/spec/files/domains/update_record/success.http +0 -21
  201. data/spec/files/domains/zone/success.http +0 -21
  202. data/spec/files/nameservers/change/success.http +0 -23
  203. data/spec/files/nameservers/deregister/success.http +0 -17
  204. data/spec/files/nameservers/name_servers/success.http +0 -23
  205. data/spec/files/nameservers/notfound-domain.http +0 -19
  206. data/spec/files/nameservers/register/badrequest-valueerror.http +0 -19
  207. data/spec/files/nameservers/register/success.http +0 -21
  208. data/spec/files/nameservers/vanity_name_servers/disabled.http +0 -23
  209. data/spec/files/nameservers/vanity_name_servers/enabled.http +0 -23
  210. data/spec/files/registrar/check/available.http +0 -19
  211. data/spec/files/registrar/check/registered.http +0 -21
  212. data/spec/files/registrar/extended_attributes/success.http +0 -21
  213. data/spec/files/registrar/prices/success.http +0 -21
  214. data/spec/files/registrar/register/badrequest-missingdomain.http +0 -19
  215. data/spec/files/registrar/register/badrequest-missingregistrant.http +0 -19
  216. data/spec/files/registrar/register/success.http +0 -21
  217. data/spec/files/registrar/renew/badrequest-missingrenewal.http +0 -19
  218. data/spec/files/registrar/renew/badrequest-unable.http +0 -19
  219. data/spec/files/registrar/renew/success.http +0 -21
  220. data/spec/files/registrar/transfer/success.http +0 -21
  221. data/spec/files/services/applied/success.http +0 -21
  222. data/spec/files/services/apply/success.http +0 -21
  223. data/spec/files/services/available/success.http +0 -21
  224. data/spec/files/services/notfound-service.http +0 -19
  225. data/spec/files/services/service/success.http +0 -21
  226. data/spec/files/services/services/success.http +0 -21
  227. data/spec/files/services/unapply/success.http +0 -21
  228. data/spec/files/subscriptions/subscription/success.http +0 -21
  229. data/spec/files/templates/apply_template/success.http +0 -21
  230. data/spec/files/templates/create_template/created.http +0 -22
  231. data/spec/files/templates/delete_template/success-204.http +0 -21
  232. data/spec/files/templates/delete_template/success.http +0 -21
  233. data/spec/files/templates/notfound-template.http +0 -19
  234. data/spec/files/templates/template/success.http +0 -21
  235. data/spec/files/templates/templates/success.http +0 -21
  236. data/spec/files/templates/update_template/success.http +0 -21
  237. data/spec/files/templates_records/create_record/created.http +0 -22
  238. data/spec/files/templates_records/delete_record/success-204.http +0 -19
  239. data/spec/files/templates_records/delete_record/success.http +0 -21
  240. data/spec/files/templates_records/notfound-template-record.http +0 -19
  241. data/spec/files/templates_records/record/success.http +0 -21
  242. data/spec/files/templates_records/records/success.http +0 -21
  243. data/spec/files/templates_records/update_record/success.http +0 -21
  244. data/spec/files/users/user/success.http +0 -21
@@ -1,14 +1,9 @@
1
1
  module Dnsimple
2
2
  class Client
3
3
 
4
- # @return [Dnsimple::Client::CertificatesService] The certificate-related API proxy.
5
- def certificates
6
- @services[:certificates] ||= Client::CertificatesService.new(self)
7
- end
8
-
9
4
  # @return [Dnsimple::Client::ContactsService] The contact-related API proxy.
10
5
  def contacts
11
- @services[:contacts] ||= Client::ContactsService.new(self)
6
+ @services[:domains] ||= Client::ContactsService.new(self)
12
7
  end
13
8
 
14
9
  # @return [Dnsimple::Client::DomainsService] The domain-related API proxy.
@@ -16,9 +11,14 @@ module Dnsimple
16
11
  @services[:domains] ||= Client::DomainsService.new(self)
17
12
  end
18
13
 
19
- # @return [Dnsimple::Client::NameServersService] The name server-related API proxy.
20
- def name_servers
21
- @services[:name_servers] ||= Client::NameServersService.new(self)
14
+ # @return [Dnsimple::Client::IdentityService] The identity-related API proxy.
15
+ def identity
16
+ @services[:auth] ||= Client::IdentityService.new(self)
17
+ end
18
+
19
+ # @return [Dnsimple::Client::OauthService] The oauth-related API proxy.
20
+ def oauth
21
+ @services[:oauth] ||= Client::OauthService.new(self)
22
22
  end
23
23
 
24
24
  # @return [Dnsimple::Client::RegistrarService] The registrar-related API proxy.
@@ -26,100 +26,124 @@ module Dnsimple
26
26
  @services[:registrar] ||= Client::RegistrarService.new(self)
27
27
  end
28
28
 
29
- # @return [Dnsimple::Client::ServicesService] The service-related API proxy.
30
- def services
31
- @services[:services] ||= Client::ServicesService.new(self)
29
+ # @return [Dnsimple::Client::TldsService] The tld-related API proxy.
30
+ def tlds
31
+ @services[:tlds] ||= Client::TldsService.new(self)
32
32
  end
33
33
 
34
- # @return [Dnsimple::Client::TemplatesService] The template-related API proxy.
35
- def templates
36
- @services[:templates] ||= Client::TemplatesService.new(self)
34
+ # @return [Dnsimple::Client::ZonesService] The zone-related API proxy.
35
+ def zones
36
+ @services[:zones] ||= Client::ZonesService.new(self)
37
37
  end
38
38
 
39
- # @return [Dnsimple::Client::UsersService] The user-related API proxy.
40
- def users
41
- @services[:users] ||= Client::UsersService.new(self)
39
+ # @return [Dnsimple::Client::WebhooksService] The webhooks-related API proxy.
40
+ def webhooks
41
+ @services[:webhooks] ||= Client::WebhooksService.new(self)
42
42
  end
43
43
 
44
44
 
45
+ # @!class Struct
45
46
  class ClientService < ::Struct.new(:client)
46
- end
47
47
 
48
+ # Internal helper that loops over a paginated response and returns all the records in the collection.
49
+ #
50
+ # @api private
51
+ #
52
+ # @param [Symbol] method The client method to execute
53
+ # @param [Array] args The args to call the method with
54
+ # @return [Dnsimple::CollectionResponse]
55
+ def paginate(method, *args)
56
+ current_page = 0
57
+ total_pages = nil
58
+ collection = []
59
+ options = args.pop
60
+ response = nil
61
+
62
+ begin
63
+ current_page += 1
64
+ query = Extra.deep_merge(options, query: { page: current_page, per_page: 100 })
65
+
66
+ response = send(method, *(args + [query]))
67
+ total_pages ||= response.total_pages
68
+ collection.concat(response.data)
69
+ end while current_page < total_pages
48
70
 
49
- require 'dnsimple/client/certificates'
71
+ CollectionResponse.new(response.http_response, collection)
72
+ end
50
73
 
51
- class CertificatesService < ClientService
52
- include Client::Certificates
53
74
  end
54
75
 
55
76
 
56
- require 'dnsimple/client/contacts'
77
+ require_relative 'contacts'
57
78
 
58
79
  class ContactsService < ClientService
59
80
  include Client::Contacts
60
81
  end
61
82
 
62
83
 
63
- require 'dnsimple/client/domains'
64
- require 'dnsimple/client/domains_records'
65
- require 'dnsimple/client/domains_autorenewal'
66
- require 'dnsimple/client/domains_privacy'
67
- require 'dnsimple/client/domains_sharing'
68
- require 'dnsimple/client/domains_forwards'
69
- require 'dnsimple/client/domains_zones'
84
+ require_relative 'domains'
85
+ require_relative 'domains_email_forwards'
70
86
 
71
87
  class DomainsService < ClientService
72
88
  include Client::Domains
73
- include Client::DomainsRecords
74
- include Client::DomainsAutorenewal
75
- include Client::DomainsPrivacy
76
- include Client::DomainsSharing
77
- include Client::DomainsForwards
78
- include Client::DomainsZones
89
+ include Client::DomainsEmailForwards
79
90
  end
80
91
 
81
92
 
82
- require 'dnsimple/client/name_servers'
83
- require 'dnsimple/client/vanity_name_servers'
93
+ require_relative 'identity'
84
94
 
85
- class NameServersService < ClientService
86
- include Client::NameServers
87
- include Client::VanityNameServers
95
+ class IdentityService < ClientService
96
+ include Client::Identity
88
97
  end
89
98
 
90
99
 
91
- require 'dnsimple/client/registrar'
100
+ require_relative 'oauth'
101
+
102
+ class OauthService < ClientService
103
+ include Client::Oauth
104
+ end
105
+
106
+
107
+ require_relative 'registrar'
108
+ require_relative 'registrar_auto_renewal'
109
+ require_relative 'registrar_whois_privacy'
92
110
 
93
111
  class RegistrarService < ClientService
94
112
  include Client::Registrar
113
+ include Client::RegistrarAutoRenewal
114
+ include Client::RegistrarWhoisPrivacy
95
115
  end
96
116
 
97
117
 
98
- require 'dnsimple/client/services'
99
- require 'dnsimple/client/services_domains'
118
+ require_relative 'tlds'
100
119
 
101
- class ServicesService < ClientService
102
- include Client::Services
103
- include Client::ServicesDomains
120
+ class TldsService < ClientService
121
+ include Client::Tlds
104
122
  end
105
123
 
106
124
 
107
- require 'dnsimple/client/templates'
108
- require 'dnsimple/client/templates_domains'
109
- require 'dnsimple/client/templates_records'
125
+ require_relative 'zones'
126
+ require_relative 'zones_records'
110
127
 
111
- class TemplatesService < ClientService
112
- include Client::Templates
113
- include Client::TemplatesDomains
114
- include Client::TemplatesRecords
128
+ class ZonesService < ClientService
129
+ include Client::Zones
130
+ include Client::ZonesRecords
115
131
  end
116
132
 
133
+ require_relative 'webhooks'
117
134
 
118
- require 'dnsimple/client/users'
119
-
120
- class UsersService < ClientService
121
- include Client::Users
135
+ class WebhooksService < ClientService
136
+ include Client::Webhooks
122
137
  end
123
138
 
124
139
  end
140
+
141
+ # This module exposes static helpers for the API v2.
142
+ #
143
+ # Compared to the full, extended API methods provided by the various client services,
144
+ # these static methods return directly the underlying data objects.
145
+ # Therefore, it's not possible to access response metadata such as throttling or pagination info.
146
+ module V2
147
+ extend Client::Identity::StaticHelpers
148
+ end
125
149
  end
@@ -4,66 +4,99 @@ module Dnsimple
4
4
 
5
5
  # Lists the contacts in the account.
6
6
  #
7
- # @see http://developer.dnsimple.com/v1/contacts/#list
7
+ # @see https://developer.dnsimple.com/v2/contacts/#list
8
+ # @see #all_contacts
8
9
  #
9
- # @return [Array<Struct::Contact>]
10
+ # @example List contacts in the first page
11
+ # client.contacts.list(1010)
10
12
  #
11
- # @raise [RequestError] When the request fails.
12
- def contacts(options = {})
13
- response = client.get(Client.versioned("/contacts"), options)
13
+ # @example List contacts, provide a specific page
14
+ # client.contacts.list(1010, query: { page: 2 })
15
+ #
16
+ # @param [Fixnum] account_id the account ID
17
+ # @param [Hash] options the filtering and sorting option
18
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Contact>]
19
+ #
20
+ # @raise [Dnsimple::RequestError]
21
+ def contacts(account_id, options = {})
22
+ response = client.get(Client.versioned("/%s/contacts" % [account_id]), options)
14
23
 
15
- response.map { |r| Struct::Contact.new(r["contact"]) }
24
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Contact.new(r) })
16
25
  end
17
26
  alias :list :contacts
18
27
  alias :list_contacts :contacts
19
28
 
29
+ # Lists ALL the contacts in the account.
30
+ #
31
+ # This method is similar to {#contacts}, but instead of returning the results of a specific page
32
+ # it iterates all the pages and returns the entire collection.
33
+ #
34
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
35
+ # you send to the API server and you may eventually risk to hit the throttle limit.
36
+ #
37
+ # @see https://developer.dnsimple.com/v2/contacts/#list
38
+ # @see #contacts
39
+ #
40
+ # @param [Fixnum] account_id the account ID
41
+ # @param [Hash] options the filtering and sorting option
42
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Contact>]
43
+ #
44
+ # @raise [Dnsimple::RequestError]
45
+ def all_contacts(account_id, options = {})
46
+ paginate(:contacts, account_id, options)
47
+ end
48
+ alias :all :all_contacts
49
+
20
50
  # Creates a contact in the account.
21
51
  #
22
- # @see http://developer.dnsimple.com/v1/contacts/#create
52
+ # @see https://developer.dnsimple.com/v2/contacts/#create
23
53
  #
54
+ # @param [Fixnum] account_id the account ID
24
55
  # @param [Hash] attributes
25
- # @return [Struct::Contact]
56
+ # @param [Hash] options
57
+ # @return [Dnsimple::Response<Dnsimple::Struct::Contact>]
26
58
  #
27
- # @raise [RequestError] When the request fails.
28
- def create_contact(attributes = {}, options = {})
59
+ # @raise [Dnsimple::RequestError]
60
+ def create_contact(account_id, attributes, options = {})
29
61
  Extra.validate_mandatory_attributes(attributes, [:first_name, :last_name, :address1, :city, :state_province, :postal_code, :country, :phone, :email_address])
30
- options = options.merge(contact: attributes)
31
- response = client.post(Client.versioned("/contacts"), options)
62
+ response = client.post(Client.versioned("/%s/contacts" % [account_id]), attributes, options)
32
63
 
33
- Struct::Contact.new(response["contact"])
64
+ Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
34
65
  end
35
66
  alias :create :create_contact
36
67
 
37
68
  # Gets a contact from the account.
38
69
  #
39
- # @see http://developer.dnsimple.com/v1/contacts/#get
70
+ # @see https://developer.dnsimple.com/v2/contacts/#get
40
71
  #
41
- # @param [Fixnum] contact The contact id.
42
- # @return [Struct::Contact]
72
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
73
+ # @param [#to_s] contact_id the contact ID
74
+ # @param [Hash] options
75
+ # @return [Dnsimple::Response<Dnsimple::Struct::Contact>]
43
76
  #
44
- # @raise [NotFoundError]
45
- # @raise [RequestError] When the request fails.
46
- def contact(contact, options = {})
47
- response = client.get(Client.versioned("/contacts/#{contact}"), options)
77
+ # @raise [Dnsimple::NotFoundError]
78
+ # @raise [Dnsimple::RequestError]
79
+ def contact(account_id, contact_id, options = {})
80
+ response = client.get(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), options)
48
81
 
49
- Struct::Contact.new(response["contact"])
82
+ Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
50
83
  end
51
84
 
52
85
  # Updates a contact in the account.
53
86
  #
54
- # @see http://developer.dnsimple.com/v1/contacts/#update
87
+ # @see https://developer.dnsimple.com/v2/contacts/#update
55
88
  #
56
- # @param [Fixnum] contact The contact id.
89
+ # @param [Fixnum] account_id the account ID
90
+ # @param [#to_s] contact_id the contact ID
57
91
  # @param [Hash] attributes
58
- # @return [Struct::Contact]
92
+ # @param [Hash] options
93
+ # @return [Dnsimple::Response<Dnsimple::Struct::Contact>]
59
94
  #
60
- # @raise [NotFoundError]
61
- # @raise [RequestError] When the request fails.
62
- def update_contact(contact, attributes = {}, options = {})
63
- options = options.merge(contact: attributes)
64
- response = client.put(Client.versioned("/contacts/#{contact}"), options)
95
+ # @raise [Dnsimple::RequestError]
96
+ def update_contact(account_id, contact_id, attributes, options = {})
97
+ response = client.patch(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), attributes, options)
65
98
 
66
- Struct::Contact.new(response["contact"])
99
+ Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
67
100
  end
68
101
  alias :update :update_contact
69
102
 
@@ -71,15 +104,19 @@ module Dnsimple
71
104
  #
72
105
  # WARNING: this cannot be undone.
73
106
  #
74
- # @see http://developer.dnsimple.com/v1/contacts/#delete
107
+ # @see https://developer.dnsimple.com/v2/contacts/#delete
75
108
  #
76
- # @param [Fixnum] contact The contact id.
77
- # @return [void]
109
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
110
+ # @param [#to_s] contact_id the contact ID
111
+ # @param [Hash] options
112
+ # @return [Dnsimple::Response<nil>]
78
113
  #
79
- # @raise [NotFoundError]
80
- # @raise [RequestError] When the request fails.
81
- def delete_contact(contact, options = {})
82
- client.delete(Client.versioned("contacts/#{contact}"), options)
114
+ # @raise [Dnsimple::NotFoundError]
115
+ # @raise [Dnsimple::RequestError]
116
+ def delete_contact(account_id, contact_id, options = {})
117
+ response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), nil, options)
118
+
119
+ Dnsimple::Response.new(response, nil)
83
120
  end
84
121
  alias :delete :delete_contact
85
122
 
@@ -4,68 +4,122 @@ module Dnsimple
4
4
 
5
5
  # Lists the domains in the account.
6
6
  #
7
- # @see http://developer.dnsimple.com/v1/domains/#list
7
+ # @see https://developer.dnsimple.com/v2/domains/#list
8
+ # @see #all_domains
8
9
  #
10
+ # @example List domains in the first page
11
+ # client.domains.list(1010)
12
+ #
13
+ # @example List domains, provide a specific page
14
+ # client.domains.list(1010, query: { page: 2 })
15
+ #
16
+ # @param [Fixnum] account_id the account ID
9
17
  # @param [Hash] options the filtering and sorting option
10
- # @return [Array<Struct::Domain>]
18
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Domain>]
11
19
  #
12
- # @raise [RequestError] When the request fails.
13
- def domains(options = {})
14
- response = client.get(Client.versioned("/domains"), options)
20
+ # @raise [Dnsimple::RequestError]
21
+ def domains(account_id, options = {})
22
+ response = client.get(Client.versioned("/%s/domains" % [account_id]), options)
15
23
 
16
- response.map { |r| Struct::Domain.new(r["domain"]) }
24
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Domain.new(r) })
17
25
  end
18
26
  alias :list :domains
19
27
  alias :list_domains :domains
20
28
 
29
+ # Lists ALL the domains in the account.
30
+ #
31
+ # This method is similar to {#domains}, but instead of returning the results of a specific page
32
+ # it iterates all the pages and returns the entire collection.
33
+ #
34
+ # Please use this method carefully, as fetching the entire collection will increase the number of requests
35
+ # you send to the API server and you may eventually risk to hit the throttle limit.
36
+ #
37
+ # @see https://developer.dnsimple.com/v2/domains/#list
38
+ # @see #domains
39
+ #
40
+ # @param [Fixnum] account_id the account ID
41
+ # @param [Hash] options the filtering and sorting option
42
+ # @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Domain>]
43
+ #
44
+ # @raise [Dnsimple::RequestError]
45
+ def all_domains(account_id, options = {})
46
+ paginate(:domains, account_id, options)
47
+ end
48
+ alias :all :all_domains
49
+
21
50
  # Creates a domain in the account.
22
51
  #
23
- # @see http://developer.dnsimple.com/v1/domains/#create
52
+ # @see https://developer.dnsimple.com/v2/domains/#create
24
53
  #
54
+ # @param [Fixnum] account_id the account ID
25
55
  # @param [Hash] attributes
26
- # @return [Struct::Domain]
56
+ # @param [Hash] options
57
+ # @return [Dnsimple::Response<Dnsimple::Struct::Domain>]
27
58
  #
28
- # @raise [RequestError] When the request fails.
29
- def create_domain(attributes = {}, options = {})
59
+ # @raise [Dnsimple::RequestError]
60
+ def create_domain(account_id, attributes, options = {})
30
61
  Extra.validate_mandatory_attributes(attributes, [:name])
31
- options = options.merge({ domain: attributes })
32
- response = client.post(Client.versioned("/domains"), options)
62
+ options = options.merge(attributes)
63
+ response = client.post(Client.versioned("/%s/domains" % [account_id]), attributes, options)
33
64
 
34
- Struct::Domain.new(response["domain"])
65
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
35
66
  end
36
67
  alias :create :create_domain
37
68
 
38
69
  # Gets a domain from the account.
39
70
  #
40
- # @see http://developer.dnsimple.com/v1/domains/#get
71
+ # @see https://developer.dnsimple.com/v2/domains/#get
41
72
  #
42
- # @param [#to_s] domain The domain id or domain name.
43
- # @return [Struct::Domain]
73
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
74
+ # @param [#to_s] domain_id The domain ID or domain name
75
+ # @param [Hash] options
76
+ # @return [Dnsimple::Response<Dnsimple::Struct::Domain>]
44
77
  #
45
- # @raise [NotFoundError]
46
- # @raise [RequestError] When the request fails.
47
- def domain(domain, options = {})
48
- response = client.get(Client.versioned("/domains/#{domain}"), options)
78
+ # @raise [Dnsimple::NotFoundError]
79
+ # @raise [Dnsimple::RequestError]
80
+ def domain(account_id, domain_id, options = {})
81
+ response = client.get(Client.versioned("/%s/domains/%s" % [account_id, domain_id]), options)
49
82
 
50
- Struct::Domain.new(response["domain"])
83
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
51
84
  end
52
85
 
53
86
  # Deletes a domain from the account.
54
87
  #
55
88
  # WARNING: this cannot be undone.
56
89
  #
57
- # @see http://developer.dnsimple.com/v1/domains/#delete
90
+ # @see https://developer.dnsimple.com/v2/domains/#delete
58
91
  #
59
- # @param [#to_s] domain The domain id or domain name.
60
- # @return [void]
92
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
93
+ # @param [#to_s] domain_id The domain ID or domain name
94
+ # @param [Hash] options
95
+ # @return [Dnsimple::Response<nil>]
61
96
  #
62
- # @raise [NotFoundError]
63
- # @raise [RequestError] When the request fails.
64
- def delete_domain(domain, options = {})
65
- client.delete(Client.versioned("/domains/#{domain}"), options)
97
+ # @raise [Dnsimple::NotFoundError]
98
+ # @raise [Dnsimple::RequestError]
99
+ def delete_domain(account_id, domain_id, options = {})
100
+ response = client.delete(Client.versioned("/%s/domains/%s" % [account_id, domain_id]), nil, options)
101
+
102
+ Dnsimple::Response.new(response, nil)
66
103
  end
67
104
  alias :delete :delete_domain
68
105
 
106
+ # Resets the domain token.
107
+ #
108
+ # @see https://developer.dnsimple.com/v2/domains/#reset-token
109
+ #
110
+ # @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard
111
+ # @param [#to_s] domain_id The domain ID or domain name
112
+ # @param [Hash] options
113
+ # @return [Dnsimple::Response<nil>]
114
+ #
115
+ # @raise [Dnsimple::NotFoundError]
116
+ # @raise [Dnsimple::RequestError]
117
+ def reset_domain_token(account_id, domain_id, options = {})
118
+ response = client.post(Client.versioned("/%s/domains/%s/token" % [account_id, domain_id]), nil, options)
119
+
120
+ Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
121
+ end
122
+
69
123
  end
70
124
  end
71
125
  end