/
registrar.ex
647 lines (466 loc) · 23 KB
/
registrar.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
defmodule Dnsimple.Registrar do
@moduledoc """
Provides functions to interact with the
[registrar endpoints](https://developer.dnsimple.com/v2/registrar/).
See:
- https://developer.dnsimple.com/v2/registrar/
- https://developer.dnsimple.com/v2/registrar/auto-renewal/
- https://developer.dnsimple.com/v2/registrar/whois-privacy/
- https://developer.dnsimple.com/v2/registrar/delegation/
"""
@moduledoc section: :api
alias Dnsimple.Client
alias Dnsimple.DomainCheck
alias Dnsimple.DomainPremiumPrice
alias Dnsimple.DomainPrice
alias Dnsimple.DomainRegistration
alias Dnsimple.DomainRenewal
alias Dnsimple.DomainTransfer
alias Dnsimple.RegistrantChange
alias Dnsimple.RegistrantChangeCheck
alias Dnsimple.Response
alias Dnsimple.TransferLock
alias Dnsimple.VanityNameServer
alias Dnsimple.WhoisPrivacy
alias Dnsimple.WhoisPrivacyRenewal
@doc """
Checks if a domain name is available to be registered and whether premium
pricing applies to that domain name.
See:
- https://developer.dnsimple.com/v2/registrar/#check
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.check_domain(client, account_id = 1010, domain_id = "example.com")
"""
@spec check_domain(Client.t, String.t, String.t, keyword()) :: {:ok|:error, Response.t}
def check_domain(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/check")
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainCheck{}})
end
@doc """
Gets the premium price for a domain.
See:
- https://developer.dnsimple.com/v2/registrar/#getDomainPremiumPrice
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_premium_price(client, account_id = "1010", domain_id = "example.com")
{:ok, response} = Dnsimple.Registrar.get_domain_premium_price(client, account_id = "1010", domain_id = "example.com", %{action: "registration"})
{:ok, response} = Dnsimple.Registrar.get_domain_premium_price(client, account_id = "1010", domain_id = "example.com", %{action: "renewal"})
{:ok, response} = Dnsimple.Registrar.get_domain_premium_price(client, account_id = "1010", domain_id = "example.com", %{action: "transfer"})
"""
@spec get_domain_premium_price(Client.t, String.t, String.t, map(), keyword()) :: {:ok|:error, Response.t}
@deprecated "Use get_domain_prices/4 instead"
def get_domain_premium_price(client, account_id, domain_name, params \\ %{}, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/premium_price")
options = Keyword.put(options, :action, Map.get(params, :action))
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainPremiumPrice{}})
end
@doc """
Get prices for a domain.
See:
- https://developer.dnsimple.com/v2/registrar/#getDomainPrices
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_prices(client, account_id = "1010", domain_id = "example.com")
"""
@spec get_domain_prices(Client.t, String.t, String.t, keyword()) :: {:ok|:error, Response.t}
def get_domain_prices(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/prices")
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainPrice{}})
end
@doc """
Registers a domain.
See:
- https://developer.dnsimple.com/v2/registrar/#registerDomain
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.register_domain(client, account_id = 1010, domain_id = "example.com", %{
registrant_id: 1,
privacy: true,
auto_renew: false,
})
"""
@spec register_domain(Client.t, String.t, String.t, Keyword.t, Keyword.t) :: {:ok|:error, Response.t}
def register_domain(client, account_id, domain_name, attributes \\ [], options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/registrations")
Client.post(client, url, attributes, options)
|> Response.parse(%{"data" => %DomainRegistration{}})
end
@doc """
Retrieve the details of an existing domain registration.
See:
- https://developer.dnsimple.com/v2/registrar/#getDomainRegistration
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_registration(client, account_id = 1010, domain_id = "example.com", registration_id = 1)
"""
@spec get_domain_registration(Client.t, String.t | integer, String.t, String.t | integer, Keyword.t) :: {:ok|:error, Response.t}
def get_domain_registration(client, account_id, domain_name, registration_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/registrations/#{registration_id}")
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainRegistration{}})
end
@doc """
Renews a domain.
See:
- https://developer.dnsimple.com/v2/registrar/#renewDomain
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.renew_domain(client, account_id = 1010, domain_id = "example.com")
{:ok, response} = Dnsimple.Registrar.renew_domain(client, account_id = 1010, domain_id = "example.com", %{period: 5})
"""
@spec renew_domain(Client.t, String.t, String.t, Keyword.t, Keyword.t) :: {:ok|:error, Response.t}
def renew_domain(client, account_id, domain_name, attributes \\ [], options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/renewals")
Client.post(client, url, attributes, options)
|> Response.parse(%{"data" => %DomainRenewal{}})
end
@doc """
Retrieve the details of an existing domain renewal.
See:
- https://developer.dnsimple.com/v2/registrar/#getDomainRenewal
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_renewal(client, account_id = 1010, domain_id = "example.com", renewal_id = 1)
"""
@spec get_domain_renewal(Client.t, String.t | integer, String.t, String.t | integer, Keyword.t) :: {:ok|:error, Response.t}
def get_domain_renewal(client, account_id, domain_name, renewal_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/renewals/#{renewal_id}")
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainRenewal{}})
end
@doc """
Starts the transfer of a domain to DNSimple.
See:
- https://developer.dnsimple.com/v2/registrar/#transferDomain
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.transfer_domain(client, account_id = 1010, domain_id = "example.com", %{
registrant_id: 1,
auth_code: "XXXXXXXXX",
privacy: true,
auto_renew: true,
})
"""
@spec transfer_domain(Client.t, String.t, String.t, Keyword.t, Keyword.t) :: {:ok|:error, Response.t}
def transfer_domain(client, account_id, domain_name, attributes \\ [], options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfers")
Client.post(client, url, attributes, options)
|> Response.parse(%{"data" => %DomainTransfer{}})
end
@doc """
Retrieves the details of an existing domain transfer.
See:
- https://developer.dnsimple.com/v2/registrar/#getDomainTransfer
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_transfer(client, account_id = 1010, domain_name = "example.com", transfer_id = 42)
"""
@spec get_domain_transfer(Client.t, String.t | integer, String.t, String.t | integer, Keyword.t) :: {:ok|:error, Response.t}
def get_domain_transfer(client, account_id, domain_name, domain_transfer_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfers/#{domain_transfer_id}")
Client.get(client, url, options)
|> Response.parse(%{"data" => %DomainTransfer{}})
end
@doc """
Cancels an in progress domain transfer.
See:
- https://developer.dnsimple.com/v2/registrar/#cancelDomainTransfer
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.cancel_domain_transfer(client, account_id = 1010, domain_name = "example.com", transfer_id = 42)
"""
@spec cancel_domain_transfer(Client.t, String.t | integer, String.t, String.t | integer, Keyword.t) :: {:ok|:error, Response.t}
def cancel_domain_transfer(client, account_id, domain_name, domain_transfer_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfers/#{domain_transfer_id}")
Client.delete(client, url, options)
|> Response.parse(%{"data" => %DomainTransfer{}})
end
@doc """
Requests the transfer of a domain out of DNSimple.
See:
- https://developer.dnsimple.com/v2/registrar/#authorizeDomainTransferOut
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.transfer_domain_out(client, account_id = 1010, domain_id = "example.com")
"""
@spec transfer_domain_out(Client.t, String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def transfer_domain_out(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/authorize_transfer_out")
Client.post(client, url, Client.empty_body(), options)
|> Response.parse(nil)
end
@doc """
Enables auto-renewal for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/auto-renewal/#enableDomainAutoRenewal
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.enable_domain_auto_renewal(client, account_id = 1010, domain_id = "example.com")
"""
@spec enable_domain_auto_renewal(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def enable_domain_auto_renewal(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/auto_renewal")
Client.put(client, url, Client.empty_body(), options)
|> Response.parse(nil)
end
@doc """
Disables auto-renewal for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/auto-renewal/#disableDomainAutoRenewal
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.disable_domain_auto_renewal(client, account_id = 1010, domain_id = "example.com")
"""
@spec disable_domain_auto_renewal(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def disable_domain_auto_renewal(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/auto_renewal")
Client.delete(client, url, options)
|> Response.parse(nil)
end
@doc """
Enables transfer lock for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/transfer_lock/#enableDomainTransferLock
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.enable_domain_transfer_lock(client, account_id = 1010, domain_id = "example.com")
"""
@spec enable_domain_transfer_lock(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def enable_domain_transfer_lock(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfer_lock")
Client.post(client, url, Client.empty_body(), options)
|> Response.parse(%{"data" => %TransferLock{}})
end
@doc """
Disables transfer lock for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/transfer_lock/#disableDomainTransferLock
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.disable_domain_transfer_lock(client, account_id = 1010, domain_id = "example.com")
"""
@spec disable_domain_transfer_lock(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def disable_domain_transfer_lock(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfer_lock")
Client.delete(client, url, options)
|> Response.parse(%{"data" => %TransferLock{}})
end
@doc """
Retrieves the transfer lock status for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/transfer_lock/#getDomainTransferLock
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_transfer_lock(client, account_id = 1010, domain_id = "example.com")
"""
@spec get_domain_transfer_lock(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def get_domain_transfer_lock(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/transfer_lock")
Client.get(client, url, options)
|> Response.parse(%{"data" => %TransferLock{}})
end
@doc """
Returns the whois privacy of the domain.
See:
- https://developer.dnsimple.com/v2/registrar/whois-privacy/#getWhoisPrivacy
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_whois_privacy(client, account_id = 1010, domain_id = "example.com")
"""
@spec get_whois_privacy(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def get_whois_privacy(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
Client.get(client, url, options)
|> Response.parse(%{"data" => %WhoisPrivacy{}})
end
@doc """
Enables whois privacy for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/whois-privacy/#enableWhoisPrivacy
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.enable_whois_privacy(client, account_id = 1010, domain_id = "example.com")
"""
@spec enable_whois_privacy(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def enable_whois_privacy(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
Client.put(client, url, Client.empty_body(), options)
|> Response.parse(%{"data" => %WhoisPrivacy{}})
end
@doc """
Disables whois privacy for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/whois-privacy/#disableWhoisPrivacy
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.disable_whois_privacy(client, account_id = 1010, domain_id = "example.com")
"""
@spec disable_whois_privacy(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def disable_whois_privacy(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/whois_privacy")
Client.delete(client, url, options)
|> Response.parse(%{"data" => %WhoisPrivacy{}})
end
@doc """
Renews whois privacy for the domain.
See:
- https://developer.dnsimple.com/v2/registrar/whois-privacy/#renewWhoisPrivacy
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.renew_whois_privacy(client, account_id = 1010, domain_id = "example.com")
"""
@spec renew_whois_privacy(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def renew_whois_privacy(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/whois_privacy/renewals")
Client.post(client, url, options)
|> Response.parse(%{"data" => %WhoisPrivacyRenewal{}})
end
@doc """
Returns the name servers the domain is delegating to.
See:
- https://developer.dnsimple.com/v2/registrar/delegation/#getDomainDelegation
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_domain_delegation(client, account_id = 1010, domain_id = "example.com")
"""
@spec get_domain_delegation(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def get_domain_delegation(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/delegation")
Client.get(client, url, options)
|> Response.parse(%{"data" => []})
end
@doc """
Changes the domain's name servers and returns them.
See:
- https://developer.dnsimple.com/v2/registrar/delegation/#changeDomainDelegation
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.change_domain_delegation(client, account_id = 1010, domain_id = "example.com", [
"ns1.provider.com",
"ns2.provider.com",
"ns3.provider.com",
"ns4.provider.com",
])
"""
@spec change_domain_delegation(Client.t, integer | String.t, String.t, list(), keyword()) :: {:ok|:error, Response.t}
def change_domain_delegation(client, account_id, domain_name, name_servers, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/delegation")
Client.put(client, url, name_servers, options)
|> Response.parse(%{"data" => []})
end
@doc """
Delegates the domain to vanity name servers.
See:
- https://developer.dnsimple.com/v2/registrar/delegation/#changeDomainDelegationToVanity
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.change_domain_delegation_to_vanity(client, account_id = 1010, domain_id = "example.com", [
"ns1.example.com",
"ns2.example.com",
"ns3.example.com",
"ns4.example.com",
])
"""
@spec change_domain_delegation_to_vanity(Client.t, integer | String.t, String.t, list(), keyword()) :: {:ok|:error, Response.t}
def change_domain_delegation_to_vanity(client, account_id, domain_name, name_servers, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/delegation/vanity")
Client.put(client, url, name_servers, options)
|> Response.parse(%{"data" => [%VanityNameServer{}]})
end
@doc """
Reverts all the operations performed to delegate to vanity name servers and
delegates the domain back to DNSimple's name servers (if DNSimple is the
registrar of the domain).
See:
- https://developer.dnsimple.com/v2/registrar/delegation/#changeDomainDelegationFromVanity
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.change_domain_delegation_from_vanity(client, account_id = 1010, domain_id = "example.com")
"""
@spec change_domain_delegation_from_vanity(Client.t, integer | String.t, String.t, Keyword.t) :: {:ok|:error, Response.t}
def change_domain_delegation_from_vanity(client, account_id, domain_name, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/domains/#{domain_name}/delegation/vanity")
Client.delete(client, url, options)
|> Response.parse(nil)
end
@doc """
Retrieves the requirements of a registrant change
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.check_registrant_change(client, account_id = 1010, %{
contact_id: 1,
domain_id: "example.com",
})
"""
@spec check_registrant_change(Client.t, integer | String.t, Keyword.t, Keyword.t) :: {:ok|:error, Response.t}
def check_registrant_change(client, account_id, attributes, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/registrant_changes/check")
Client.post(client, url, attributes, options)
|> Response.parse(%{"data" => %RegistrantChangeCheck{}})
end
@doc """
Retrieves the details of an existing registrant change.
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.get_registrant_change(client, account_id = 1010, registrant_change_id = 1)
"""
@spec get_registrant_change(Client.t, integer | String.t, integer, Keyword.t) :: {:ok|:error, Response.t}
def get_registrant_change(client, account_id, registrant_change_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/registrant_changes/#{registrant_change_id}")
Client.get(client, url, options)
|> Response.parse(%{"data" => %RegistrantChange{}})
end
@doc """
Start registrant change.
## Examples:
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.create_registrant_change(client, account_id = 1010, %{
contact_id: 1,
domain_id: "example.com",
extended_attributes: %{
"x-fake-attribute" => "value",
}
})
"""
@spec create_registrant_change(Client.t, integer | String.t, Keyword.t, Keyword.t) :: {:ok|:error, Response.t}
def create_registrant_change(client, account_id, attributes, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/registrant_changes")
Client.post(client, url, attributes, options)
|> Response.parse(%{"data" => %RegistrantChange{}})
end
@doc """
List registrant changes in the account.
## Examples
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.list_registrant_changes(client, account_id = 1010)
"""
@spec list_registrant_changes(Client.t, integer | String.t, Keyword.t) :: {:ok|:error, Response.t}
def list_registrant_changes(client, account_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/registrant_changes")
Client.get(client, url, options)
|> Response.parse(%{"data" => [%RegistrantChange{}]})
end
@doc """
Cancel an ongoing registrant change from the account.
## Examples
client = %Dnsimple.Client{access_token: "a1b2c3d4"}
{:ok, response} = Dnsimple.Registrar.delete_registrant_change(client, account_id = 1010, registrant_change_id = 1)
"""
@spec delete_registrant_change(Client.t, integer | String.t, integer, Keyword.t) :: {:ok|:error, Response.t}
def delete_registrant_change(client, account_id, registrant_change_id, options \\ []) do
url = Client.versioned("/#{account_id}/registrar/registrant_changes/#{registrant_change_id}")
{state, response } = Client.delete(client, url, options)
cond do
response.status_code == 204 ->
{state, response} |> Response.parse(nil)
response.status_code == 202 ->
{state, response} |> Response.parse(%{"data" => %RegistrantChange{}})
true ->
{state, response} |> Response.parse(nil)
end
end
end