mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 15:47:52 -05:00
feat(GODT-2181): Implement GetDomains
This commit is contained in:
15
manager_domains.go
Normal file
15
manager_domains.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package proton
|
||||
|
||||
import "context"
|
||||
|
||||
func (m *Manager) GetDomains(ctx context.Context) ([]string, error) {
|
||||
var res struct {
|
||||
Domains []string
|
||||
}
|
||||
|
||||
if _, err := m.r(ctx).SetResult(&res).Get("/core/v4/domains/available"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Domains, nil
|
||||
}
|
||||
15
server/domains.go
Normal file
15
server/domains.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (s *Server) handleGetDomainsAvailable() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"Domains": []string{s.domain},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ func initRouter(s *Server) {
|
||||
auth.POST("/refresh", s.handlePostAuthRefresh())
|
||||
}
|
||||
|
||||
// Domains routes don't need authentication.
|
||||
if domains := core.Group("/domains"); domains != nil {
|
||||
domains.GET("/available", s.handleGetDomainsAvailable())
|
||||
}
|
||||
|
||||
// Reporting a bug is also possible without authentication.
|
||||
if reports := core.Group("/reports"); reports != nil {
|
||||
reports.POST("/bug", s.handlePostReportBug())
|
||||
|
||||
@@ -1662,6 +1662,14 @@ func TestServer_AddressOrder(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestServer_Domains(t *testing.T) {
|
||||
withServer(t, func(ctx context.Context, s *Server, m *proton.Manager) {
|
||||
domains, err := m.GetDomains(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{s.GetDomain()}, domains)
|
||||
})
|
||||
}
|
||||
|
||||
func withServer(t *testing.T, fn func(ctx context.Context, s *Server, m *proton.Manager), opts ...Option) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user