Skip to content

Commit

Permalink
Add RestoreDomain and GetDomainRestore methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kntsoriano committed Feb 22, 2024
1 parent 02feb5f commit e970867
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dnsimple/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,20 @@ func (s *RegistrarService) RestoreDomain(ctx context.Context, accountID string,
renewalResponse.HTTPResponse = resp
return renewalResponse, nil
}

// GetDomainRestore gets the details of an existing domain restore.
//
// See https://developer.dnsimple.com/v2/registrar/#getDomainRestore
func (s *RegistrarService) GetDomainRestore(ctx context.Context, accountID string, domainName string, domainRestoreID string) (*DomainRestoreResponse, error) {
var err error
path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/restores/%v", accountID, domainName, domainRestoreID))
res := &DomainRestoreResponse{}

resp, err := s.client.get(ctx, path, res)
if err != nil {
return nil, err
}

res.HTTPResponse = resp
return res, nil
}
25 changes: 25 additions & 0 deletions dnsimple/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,28 @@ func TestRegistrarService_RestoreDomain(t *testing.T) {
assert.Equal(t, int64(43), restore.ID)
assert.Equal(t, int64(214), restore.DomainID)
}

func TestRegistrarService_GetDomainRestore(t *testing.T) {
setupMockServer()
defer teardownMockServer()

mux.HandleFunc("/v2/1010/registrar/domains/bingo.pizza/restores/1", func(w http.ResponseWriter, r *http.Request) {
httpResponse := httpResponseFixture(t, "/api/getDomainRestore/success.http")

testMethod(t, r, "GET")
testHeaders(t, r)

w.WriteHeader(httpResponse.StatusCode)
_, _ = io.Copy(w, httpResponse.Body)
})

checkResponse, err := client.Registrar.GetDomainRestore(context.Background(), "1010", "bingo.pizza", "1")

assert.NoError(t, err)
check := checkResponse.Data
assert.Equal(t, check.ID, int64(1))
assert.Equal(t, check.DomainID, int64(999))
assert.Equal(t, check.State, "restored")
assert.Equal(t, check.CreatedAt, "2016-12-09T19:46:45Z")
assert.Equal(t, check.UpdatedAt, "2016-12-12T19:46:45Z")
}
20 changes: 20 additions & 0 deletions fixtures.http/api/getDomainRestore/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
HTTP/1.1 201 Created
Server: nginx
Date: Fri, 09 Dec 2016 19:46:57 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2394
X-RateLimit-Reset: 1481315245
ETag: W/"179d85ea8a26a3d5dc76e42de2d7918e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: ba6f2707-5df0-4ffa-b91b-51d4460bab8e
X-Runtime: 13.571302
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000

{"data":{"id":1,"domain_id":999,"state":"restored","created_at":"2016-12-09T19:46:45Z","updated_at":"2016-12-12T19:46:45Z"}}

0 comments on commit e970867

Please sign in to comment.