Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Mar 19, 2024
1 parent 9d38fa3 commit 9984126
Show file tree
Hide file tree
Showing 31 changed files with 14,660 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 1235
configured_endpoints: 1288
176 changes: 176 additions & 0 deletions api.md

Large diffs are not rendered by default.

255 changes: 255 additions & 0 deletions dns/analyticsreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
package dns

import (
"context"
"fmt"
"net/http"
"net/url"
"time"

"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
)

Expand All @@ -25,3 +35,248 @@ func NewAnalyticsReportService(opts ...option.RequestOption) (r *AnalyticsReport
r.Bytimes = NewAnalyticsReportBytimeService(opts...)
return
}

// Retrieves a list of summarised aggregate metrics over a given time period.
//
// See
// [Analytics API properties](https://developers.cloudflare.com/dns/reference/analytics-api-properties/)
// for detailed information about the available query parameters.
func (r *AnalyticsReportService) Get(ctx context.Context, params AnalyticsReportGetParams, opts ...option.RequestOption) (res *DNSDNSAnalyticsAPIReport, err error) {
opts = append(r.Options[:], opts...)
var env AnalyticsReportGetResponseEnvelope
path := fmt.Sprintf("zones/%s/dns_analytics/report", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type DNSDNSAnalyticsAPIReport struct {
// Array with one row per combination of dimension values.
Data []DNSDNSAnalyticsAPIReportData `json:"data,required"`
// Number of seconds between current time and last processed event, in another
// words how many seconds of data could be missing.
DataLag float64 `json:"data_lag,required"`
// Maximum results for each metric (object mapping metric names to values).
// Currently always an empty object.
Max interface{} `json:"max,required"`
// Minimum results for each metric (object mapping metric names to values).
// Currently always an empty object.
Min interface{} `json:"min,required"`
Query DNSDNSAnalyticsAPIReportQuery `json:"query,required"`
// Total number of rows in the result.
Rows float64 `json:"rows,required"`
// Total results for metrics across all data (object mapping metric names to
// values).
Totals interface{} `json:"totals,required"`
JSON dnsdnsAnalyticsAPIReportJSON `json:"-"`
}

// dnsdnsAnalyticsAPIReportJSON contains the JSON metadata for the struct
// [DNSDNSAnalyticsAPIReport]
type dnsdnsAnalyticsAPIReportJSON struct {
Data apijson.Field
DataLag apijson.Field
Max apijson.Field
Min apijson.Field
Query apijson.Field
Rows apijson.Field
Totals apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DNSDNSAnalyticsAPIReport) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r dnsdnsAnalyticsAPIReportJSON) RawJSON() string {
return r.raw
}

type DNSDNSAnalyticsAPIReportData struct {
// Array of dimension values, representing the combination of dimension values
// corresponding to this row.
Dimensions []string `json:"dimensions,required"`
// Array with one item per requested metric. Each item is a single value.
Metrics []float64 `json:"metrics,required"`
JSON dnsdnsAnalyticsAPIReportDataJSON `json:"-"`
}

// dnsdnsAnalyticsAPIReportDataJSON contains the JSON metadata for the struct
// [DNSDNSAnalyticsAPIReportData]
type dnsdnsAnalyticsAPIReportDataJSON struct {
Dimensions apijson.Field
Metrics apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DNSDNSAnalyticsAPIReportData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r dnsdnsAnalyticsAPIReportDataJSON) RawJSON() string {
return r.raw
}

type DNSDNSAnalyticsAPIReportQuery struct {
// Array of dimension names.
Dimensions []string `json:"dimensions,required"`
// Limit number of returned metrics.
Limit int64 `json:"limit,required"`
// Array of metric names.
Metrics []string `json:"metrics,required"`
// Start date and time of requesting data period in ISO 8601 format.
Since time.Time `json:"since,required" format:"date-time"`
// 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.
Filters string `json:"filters"`
// Array of dimensions to sort by, where each dimension may be prefixed by -
// (descending) or + (ascending).
Sort []string `json:"sort"`
JSON dnsdnsAnalyticsAPIReportQueryJSON `json:"-"`
}

// dnsdnsAnalyticsAPIReportQueryJSON contains the JSON metadata for the struct
// [DNSDNSAnalyticsAPIReportQuery]
type dnsdnsAnalyticsAPIReportQueryJSON struct {
Dimensions apijson.Field
Limit apijson.Field
Metrics apijson.Field
Since apijson.Field
Until apijson.Field
Filters apijson.Field
Sort apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *DNSDNSAnalyticsAPIReportQuery) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r dnsdnsAnalyticsAPIReportQueryJSON) RawJSON() string {
return r.raw
}

type AnalyticsReportGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
// A comma-separated list of dimensions to group results by.
Dimensions param.Field[string] `query:"dimensions"`
// Segmentation filter in 'attribute operator value' format.
Filters param.Field[string] `query:"filters"`
// Limit number of returned metrics.
Limit param.Field[int64] `query:"limit"`
// A comma-separated list of metrics to query.
Metrics param.Field[string] `query:"metrics"`
// Start date and time of requesting data period in ISO 8601 format.
Since param.Field[time.Time] `query:"since" format:"date-time"`
// A comma-separated list of dimensions to sort by, where each dimension may be
// prefixed by - (descending) or + (ascending).
Sort param.Field[string] `query:"sort"`
// End date and time of requesting data period in ISO 8601 format.
Until param.Field[time.Time] `query:"until" format:"date-time"`
}

// URLQuery serializes [AnalyticsReportGetParams]'s query parameters as
// `url.Values`.
func (r AnalyticsReportGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}

type AnalyticsReportGetResponseEnvelope struct {
Errors []AnalyticsReportGetResponseEnvelopeErrors `json:"errors,required"`
Messages []AnalyticsReportGetResponseEnvelopeMessages `json:"messages,required"`
Result DNSDNSAnalyticsAPIReport `json:"result,required"`
// Whether the API call was successful
Success AnalyticsReportGetResponseEnvelopeSuccess `json:"success,required"`
JSON analyticsReportGetResponseEnvelopeJSON `json:"-"`
}

// analyticsReportGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [AnalyticsReportGetResponseEnvelope]
type analyticsReportGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AnalyticsReportGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r analyticsReportGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}

type AnalyticsReportGetResponseEnvelopeErrors struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON analyticsReportGetResponseEnvelopeErrorsJSON `json:"-"`
}

// analyticsReportGetResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [AnalyticsReportGetResponseEnvelopeErrors]
type analyticsReportGetResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AnalyticsReportGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r analyticsReportGetResponseEnvelopeErrorsJSON) RawJSON() string {
return r.raw
}

type AnalyticsReportGetResponseEnvelopeMessages struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON analyticsReportGetResponseEnvelopeMessagesJSON `json:"-"`
}

// analyticsReportGetResponseEnvelopeMessagesJSON contains the JSON metadata for
// the struct [AnalyticsReportGetResponseEnvelopeMessages]
type analyticsReportGetResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AnalyticsReportGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r analyticsReportGetResponseEnvelopeMessagesJSON) RawJSON() string {
return r.raw
}

// Whether the API call was successful
type AnalyticsReportGetResponseEnvelopeSuccess bool

const (
AnalyticsReportGetResponseEnvelopeSuccessTrue AnalyticsReportGetResponseEnvelopeSuccess = true
)

func (r AnalyticsReportGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case AnalyticsReportGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
49 changes: 49 additions & 0 deletions dns/analyticsreport_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package dns_test

import (
"context"
"errors"
"os"
"testing"
"time"

"github.com/cloudflare/cloudflare-go/v2"
"github.com/cloudflare/cloudflare-go/v2/dns"
"github.com/cloudflare/cloudflare-go/v2/internal/testutil"
"github.com/cloudflare/cloudflare-go/v2/option"
)

func TestAnalyticsReportGetWithOptionalParams(t *testing.T) {
t.Skip("skipped: tests are disabled for the time being")
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := cloudflare.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
option.WithAPIEmail("user@example.com"),
)
_, err := client.DNS.Analytics.Reports.Get(context.TODO(), dns.AnalyticsReportGetParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Dimensions: cloudflare.F("queryType"),
Filters: cloudflare.F("responseCode==NOERROR,queryType==A"),
Limit: cloudflare.F(int64(100)),
Metrics: cloudflare.F("queryCount,uncachedCount"),
Since: cloudflare.F(time.Now()),
Sort: cloudflare.F("+responseCode,-queryName"),
Until: cloudflare.F(time.Now()),
})
if err != nil {
var apierr *cloudflare.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

0 comments on commit 9984126

Please sign in to comment.