Repository: cloudflare/cloudflare-go
Pull request #3697 (2024-12-04 04:29:39)

feat(dns): remove `delta` model


Patch:
diff --git a/api.md b/api.md
index 983772042..9c75a1986 100644
--- a/api.md
+++ b/api.md
@@ -957,14 +957,6 @@ Methods:
 
 ## Analytics
 
-Params Types:
-
-- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/dns_firewall">dns_firewall</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/dns_firewall#Delta">Delta</a>
-
-Response Types:
-
-- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/dns_firewall">dns_firewall</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v3/dns_firewall#Delta">Delta</a>
-
 ### Reports
 
 Methods:
diff --git a/dns/analyticsreportbytime.go b/dns/analyticsreportbytime.go
index 03e6992df..24b2a9d2a 100644
--- a/dns/analyticsreportbytime.go
+++ b/dns/analyticsreportbytime.go
@@ -10,7 +10,6 @@ import (
 	"net/url"
 	"time"
 
-	"github.com/cloudflare/cloudflare-go/v3/dns_firewall"
 	"github.com/cloudflare/cloudflare-go/v3/internal/apijson"
 	"github.com/cloudflare/cloudflare-go/v3/internal/apiquery"
 	"github.com/cloudflare/cloudflare-go/v3/internal/param"
@@ -148,7 +147,7 @@ type AnalyticsReportBytimeGetParams struct {
 	// prefixed by - (descending) or + (ascending).
 	Sort param.Field[string] `query:"sort"`
 	// Unit of time to group data by.
-	TimeDelta param.Field[dns_firewall.Delta] `query:"time_delta"`
+	TimeDelta param.Field[AnalyticsReportBytimeGetParamsTimeDelta] `query:"time_delta"`
 	// End date and time of requesting data period in ISO 8601 format.
 	Until param.Field[time.Time] `query:"until" format:"date-time"`
 }
@@ -162,6 +161,30 @@ func (r AnalyticsReportBytimeGetParams) URLQuery() (v url.Values) {
 	})
 }
 
+// Unit of time to group data by.
+type AnalyticsReportBytimeGetParamsTimeDelta string
+
+const (
+	AnalyticsReportBytimeGetParamsTimeDeltaAll        AnalyticsReportBytimeGetParamsTimeDelta = "all"
+	AnalyticsReportBytimeGetParamsTimeDeltaAuto       AnalyticsReportBytimeGetParamsTimeDelta = "auto"
+	AnalyticsReportBytimeGetParamsTimeDeltaYear       AnalyticsReportBytimeGetParamsTimeDelta = "year"
+	AnalyticsReportBytimeGetParamsTimeDeltaQuarter    AnalyticsReportBytimeGetParamsTimeDelta = "quarter"
+	AnalyticsReportBytimeGetParamsTimeDeltaMonth      AnalyticsReportBytimeGetParamsTimeDelta = "month"
+	AnalyticsReportBytimeGetParamsTimeDeltaWeek       AnalyticsReportBytimeGetParamsTimeDelta = "week"
+	AnalyticsReportBytimeGetParamsTimeDeltaDay        AnalyticsReportBytimeGetParamsTimeDelta = "day"
+	AnalyticsReportBytimeGetParamsTimeDeltaHour       AnalyticsReportBytimeGetParamsTimeDelta = "hour"
+	AnalyticsReportBytimeGetParamsTimeDeltaDekaminute AnalyticsReportBytimeGetParamsTimeDelta = "dekaminute"
+	AnalyticsReportBytimeGetParamsTimeDeltaMinute     AnalyticsReportBytimeGetParamsTimeDelta = "minute"
+)
+
+func (r AnalyticsReportBytimeGetParamsTimeDelta) IsKnown() bool {
+	switch r {
+	case AnalyticsReportBytimeGetParamsTimeDeltaAll, AnalyticsReportBytimeGetParamsTimeDeltaAuto, AnalyticsReportBytimeGetParamsTimeDeltaYear, AnalyticsReportBytimeGetParamsTimeDeltaQuarter, AnalyticsReportBytimeGetParamsTimeDeltaMonth, AnalyticsReportBytimeGetParamsTimeDeltaWeek, AnalyticsReportBytimeGetParamsTimeDeltaDay, AnalyticsReportBytimeGetParamsTimeDeltaHour, AnalyticsReportBytimeGetParamsTimeDeltaDekaminute, AnalyticsReportBytimeGetParamsTimeDeltaMinute:
+		return true
+	}
+	return false
+}
+
 type AnalyticsReportBytimeGetResponseEnvelope struct {
 	Errors   []shared.ResponseInfo `json:"errors,required"`
 	Messages []shared.ResponseInfo `json:"messages,required"`
diff --git a/dns/dns.go b/dns/dns.go
index d703cef47..391e60414 100644
--- a/dns/dns.go
+++ b/dns/dns.go
@@ -5,7 +5,6 @@ package dns
 import (
 	"time"
 
-	"github.com/cloudflare/cloudflare-go/v3/dns_firewall"
 	"github.com/cloudflare/cloudflare-go/v3/internal/apijson"
 	"github.com/cloudflare/cloudflare-go/v3/option"
 )
@@ -51,7 +50,7 @@ type DNSAnalyticsQuery struct {
 	// Start date and time of requesting data period in ISO 8601 format.
 	Since time.Time `json:"since,required" format:"date-time"`
 	// Unit of time to group data by.
-	TimeDelta dns_firewall.Delta `json:"time_delta,required"`
+	TimeDelta DNSAnalyticsQueryTimeDelta `json:"time_delta,required"`
 	// End date and time of requesting data period in ISO 8601 format.
 	Until time.Time `json:"until,required" format:"date-time"`
 	// Segmentation filter in 'attribute operator value' format.
@@ -84,3 +83,27 @@ func (r *DNSAnalyticsQuery) UnmarshalJSON(data []byte) (err error) {
 func (r dnsAnalyticsQueryJSON) RawJSON() string {
 	return r.raw
 }
+
+// Unit of time to group data by.
+type DNSAnalyticsQueryTimeDelta string
+
+const (
+	DNSAnalyticsQueryTimeDeltaAll        DNSAnalyticsQueryTimeDelta = "all"
+	DNSAnalyticsQueryTimeDeltaAuto       DNSAnalyticsQueryTimeDelta = "auto"
+	DNSAnalyticsQueryTimeDeltaYear       DNSAnalyticsQueryTimeDelta = "year"
+	DNSAnalyticsQueryTimeDeltaQuarter    DNSAnalyticsQueryTimeDelta = "quarter"
+	DNSAnalyticsQueryTimeDeltaMonth      DNSAnalyticsQueryTimeDelta = "month"
+	DNSAnalyticsQueryTimeDeltaWeek       DNSAnalyticsQueryTimeDelta = "week"
+	DNSAnalyticsQueryTimeDeltaDay        DNSAnalyticsQueryTimeDelta = "day"
+	DNSAnalyticsQueryTimeDeltaHour       DNSAnalyticsQueryTimeDelta = "hour"
+	DNSAnalyticsQueryTimeDeltaDekaminute DNSAnalyticsQueryTimeDelta = "dekaminute"
+	DNSAnalyticsQueryTimeDeltaMinute     DNSAnalyticsQueryTimeDelta = "minute"
+)
+
+func (r DNSAnalyticsQueryTimeDelta) IsKnown() bool {
+	switch r {
+	case DNSAnalyticsQueryTimeDeltaAll, DNSAnalyticsQueryTimeDeltaAuto, DNSAnalyticsQueryTimeDeltaYear, DNSAnalyticsQueryTimeDeltaQuarter, DNSAnalyticsQueryTimeDeltaMonth, DNSAnalyticsQueryTimeDeltaWeek, DNSAnalyticsQueryTimeDeltaDay, DNSAnalyticsQueryTimeDeltaHour, DNSAnalyticsQueryTimeDeltaDekaminute, DNSAnalyticsQueryTimeDeltaMinute:
+		return true
+	}
+	return false
+}
diff --git a/dns_firewall/analytics.go b/dns_firewall/analytics.go
index aa8fb6113..827e57000 100644
--- a/dns_firewall/analytics.go
+++ b/dns_firewall/analytics.go
@@ -26,27 +26,3 @@ func NewAnalyticsService(opts ...option.RequestOption) (r *AnalyticsService) {
 	r.Reports = NewAnalyticsReportService(opts...)
 	return
 }
-
-// Unit of time to group data by.
-type Delta string
-
-const (
-	DeltaAll        Delta = "all"
-	DeltaAuto       Delta = "auto"
-	DeltaYear       Delta = "year"
-	DeltaQuarter    Delta = "quarter"
-	DeltaMonth      Delta = "month"
-	DeltaWeek       Delta = "week"
-	DeltaDay        Delta = "day"
-	DeltaHour       Delta = "hour"
-	DeltaDekaminute Delta = "dekaminute"
-	DeltaMinute     Delta = "minute"
-)
-
-func (r Delta) IsKnown() bool {
-	switch r {
-	case DeltaAll, DeltaAuto, DeltaYear, DeltaQuarter, DeltaMonth, DeltaWeek, DeltaDay, DeltaHour, DeltaDekaminute, DeltaMinute:
-		return true
-	}
-	return false
-}
diff --git a/dns_firewall/analyticsreportbytime.go b/dns_firewall/analyticsreportbytime.go
index 43b859260..3b54636e2 100644
--- a/dns_firewall/analyticsreportbytime.go
+++ b/dns_firewall/analyticsreportbytime.go
@@ -80,7 +80,7 @@ type AnalyticsReportBytimeGetParams struct {
 	// prefixed by - (descending) or + (ascending).
 	Sort param.Field[string] `query:"sort"`
 	// Unit of time to group data by.
-	TimeDelta param.Field[Delta] `query:"time_delta"`
+	TimeDelta param.Field[AnalyticsReportBytimeGetParamsTimeDelta] `query:"time_delta"`
 	// End date and time of requesting data period in ISO 8601 format.
 	Until param.Field[time.Time] `query:"until" format:"date-time"`
 }
@@ -94,6 +94,30 @@ func (r AnalyticsReportBytimeGetParams) URLQuery() (v url.Values) {
 	})
 }
 
+// Unit of time to group data by.
+type AnalyticsReportBytimeGetParamsTimeDelta string
+
+const (
+	AnalyticsReportBytimeGetParamsTimeDeltaAll        AnalyticsReportBytimeGetParamsTimeDelta = "all"
+	AnalyticsReportBytimeGetParamsTimeDeltaAuto       AnalyticsReportBytimeGetParamsTimeDelta = "auto"
+	AnalyticsReportBytimeGetParamsTimeDeltaYear       AnalyticsReportBytimeGetParamsTimeDelta = "year"
+	AnalyticsReportBytimeGetParamsTimeDeltaQuarter    AnalyticsReportBytimeGetParamsTimeDelta = "quarter"
+	AnalyticsReportBytimeGetParamsTimeDeltaMonth      AnalyticsReportBytimeGetParamsTimeDelta = "month"
+	AnalyticsReportBytimeGetParamsTimeDeltaWeek       AnalyticsReportBytimeGetParamsTimeDelta = "week"
+	AnalyticsReportBytimeGetParamsTimeDeltaDay        AnalyticsReportBytimeGetParamsTimeDelta = "day"
+	AnalyticsReportBytimeGetParamsTimeDeltaHour       AnalyticsReportBytimeGetParamsTimeDelta = "hour"
+	AnalyticsReportBytimeGetParamsTimeDeltaDekaminute AnalyticsReportBytimeGetParamsTimeDelta = "dekaminute"
+	AnalyticsReportBytimeGetParamsTimeDeltaMinute     AnalyticsReportBytimeGetParamsTimeDelta = "minute"
+)
+
+func (r AnalyticsReportBytimeGetParamsTimeDelta) IsKnown() bool {
+	switch r {
+	case AnalyticsReportBytimeGetParamsTimeDeltaAll, AnalyticsReportBytimeGetParamsTimeDeltaAuto, AnalyticsReportBytimeGetParamsTimeDeltaYear, AnalyticsReportBytimeGetParamsTimeDeltaQuarter, AnalyticsReportBytimeGetParamsTimeDeltaMonth, AnalyticsReportBytimeGetParamsTimeDeltaWeek, AnalyticsReportBytimeGetParamsTimeDeltaDay, AnalyticsReportBytimeGetParamsTimeDeltaHour, AnalyticsReportBytimeGetParamsTimeDeltaDekaminute, AnalyticsReportBytimeGetParamsTimeDeltaMinute:
+		return true
+	}
+	return false
+}
+
 type AnalyticsReportBytimeGetResponseEnvelope struct {
 	Errors   []shared.ResponseInfo `json:"errors,required"`
 	Messages []shared.ResponseInfo `json:"messages,required"`


Test patch:
diff --git a/dns/analyticsreportbytime_test.go b/dns/analyticsreportbytime_test.go
index 57db2d3c1..4ca63fab2 100644
--- a/dns/analyticsreportbytime_test.go
+++ b/dns/analyticsreportbytime_test.go
@@ -11,7 +11,6 @@ import (
 
 	"github.com/cloudflare/cloudflare-go/v3"
 	"github.com/cloudflare/cloudflare-go/v3/dns"
-	"github.com/cloudflare/cloudflare-go/v3/dns_firewall"
 	"github.com/cloudflare/cloudflare-go/v3/internal/testutil"
 	"github.com/cloudflare/cloudflare-go/v3/option"
 )
@@ -37,7 +36,7 @@ func TestAnalyticsReportBytimeGetWithOptionalParams(t *testing.T) {
 		Metrics:    cloudflare.F("queryCount,uncachedCount"),
 		Since:      cloudflare.F(time.Now()),
 		Sort:       cloudflare.F("+responseCode,-queryName"),
-		TimeDelta:  cloudflare.F(dns_firewall.DeltaAll),
+		TimeDelta:  cloudflare.F(dns.AnalyticsReportBytimeGetParamsTimeDeltaAll),
 		Until:      cloudflare.F(time.Now()),
 	})
 	if err != nil {
diff --git a/dns_firewall/analyticsreportbytime_test.go b/dns_firewall/analyticsreportbytime_test.go
index a5534f440..10d3f823d 100644
--- a/dns_firewall/analyticsreportbytime_test.go
+++ b/dns_firewall/analyticsreportbytime_test.go
@@ -39,7 +39,7 @@ func TestAnalyticsReportBytimeGetWithOptionalParams(t *testing.T) {
 			Metrics:    cloudflare.F("queryCount,uncachedCount"),
 			Since:      cloudflare.F(time.Now()),
 			Sort:       cloudflare.F("+responseCode,-queryName"),
-			TimeDelta:  cloudflare.F(dns_firewall.DeltaAll),
+			TimeDelta:  cloudflare.F(dns_firewall.AnalyticsReportBytimeGetParamsTimeDeltaAll),
 			Until:      cloudflare.F(time.Now()),
 		},
 	)