|
| 1 | +package move |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "encoding/json" |
| 7 | + "log" |
| 8 | + |
| 9 | + "github.com/hostinger/api-cli/api" |
| 10 | + "github.com/hostinger/api-cli/output" |
| 11 | + "github.com/hostinger/api-cli/utils" |
| 12 | + "github.com/spf13/cobra" |
| 13 | +) |
| 14 | + |
| 15 | +var AcceptIncomingCmd = &cobra.Command{ |
| 16 | + Use: "accept-incoming <domain>", |
| 17 | + Short: "Accept incoming domain move", |
| 18 | + Long: "Accept an incoming move for a specified domain.\n\nThe provided WHOIS profiles become the contacts of the domain, so they must belong\nto your account and satisfy the requirements of the TLD. Only the contact types the\ndomain actually uses are applied, but all four profile IDs have to be provided.\n\nThe move has to still be waiting for your decision, already accepted moves\ncannot be accepted again.\n\nAccepting does not complete the move. A confirmation email is sent to the email address of\nthe new owner contact, and the domain changes hands only after the change is confirmed from it.\nUntil then the move stays in the `activating` status, which can be followed with the\n[incoming move endpoint](#tag/domains-move).\n\nUse this endpoint to take ownership of a domain offered to you.", |
| 19 | + Args: cobra.MatchAll(cobra.ExactArgs(1)), |
| 20 | + Run: func(cmd *cobra.Command, args []string) { |
| 21 | + payload, err := json.Marshal(acceptIncomingBody(cmd)) |
| 22 | + if err != nil { |
| 23 | + log.Fatal(err) |
| 24 | + } |
| 25 | + r, err := api.Request().DomainsAcceptIncomingDomainMoveV1WithBodyWithResponse(context.TODO(), args[0], "application/json", bytes.NewReader(payload)) |
| 26 | + if err != nil { |
| 27 | + log.Fatal(err) |
| 28 | + } |
| 29 | + |
| 30 | + output.Format(cmd, r.Body, r.StatusCode()) |
| 31 | + }, |
| 32 | +} |
| 33 | + |
| 34 | +func init() { |
| 35 | + AcceptIncomingCmd.Flags().StringP("domain-contacts", "", "", "WHOIS profiles of the accepting account. Only the contact types required by the TLD are applied, but all four IDs must be provided. (JSON)") |
| 36 | + AcceptIncomingCmd.MarkFlagRequired("domain-contacts") |
| 37 | +} |
| 38 | + |
| 39 | +func acceptIncomingBody(cmd *cobra.Command) map[string]any { |
| 40 | + body := map[string]any{} |
| 41 | + domainContactsVal, _ := cmd.Flags().GetString("domain-contacts") |
| 42 | + body["domain_contacts"] = utils.JSONValue(domainContactsVal, "domain-contacts") |
| 43 | + return body |
| 44 | +} |
0 commit comments