Skip to content

Commit

Permalink
feat(api): update internal path (#3910)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Feb 9, 2025
1 parent a5527d2 commit 3359bd6
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1524
configured_endpoints: 1525
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-201a9d77b2e238cb2f8c2c952b00b976608e2a53fe4230369e801971fda29edc.yml
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@ Methods:

## Recommendations

Response Types:

- <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl">ssl</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationGetResponse">RecommendationGetResponse</a>

Methods:

- <code title="get /zones/{zone_id}/ssl/recommendation">client.SSL.Recommendations.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl">ssl</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationGetParams">RecommendationGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl">ssl</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/ssl#RecommendationGetResponse">RecommendationGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

## Universal

### Settings
Expand Down
117 changes: 117 additions & 0 deletions ssl/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
package ssl

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

"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
"github.com/cloudflare/cloudflare-go/v4/internal/param"
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/cloudflare/cloudflare-go/v4/shared"
)

// RecommendationService contains methods and other services that help with
Expand All @@ -24,3 +34,110 @@ func NewRecommendationService(opts ...option.RequestOption) (r *RecommendationSe
r.Options = opts
return
}

// Retrieve the SSL/TLS Recommender's recommendation for a zone.
func (r *RecommendationService) Get(ctx context.Context, query RecommendationGetParams, opts ...option.RequestOption) (res *RecommendationGetResponse, err error) {
var env RecommendationGetResponseEnvelope
opts = append(r.Options[:], opts...)
if query.ZoneID.Value == "" {
err = errors.New("missing required zone_id parameter")
return
}
path := fmt.Sprintf("zones/%s/ssl/recommendation", query.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}

type RecommendationGetResponse struct {
// Identifier of a recommendation result.
ID string `json:"id"`
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
Value RecommendationGetResponseValue `json:"value"`
JSON recommendationGetResponseJSON `json:"-"`
}

// recommendationGetResponseJSON contains the JSON metadata for the struct
// [RecommendationGetResponse]
type recommendationGetResponseJSON struct {
ID apijson.Field
ModifiedOn apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type RecommendationGetResponseValue string

const (
RecommendationGetResponseValueFlexible RecommendationGetResponseValue = "flexible"
RecommendationGetResponseValueFull RecommendationGetResponseValue = "full"
RecommendationGetResponseValueStrict RecommendationGetResponseValue = "strict"
)

func (r RecommendationGetResponseValue) IsKnown() bool {
switch r {
case RecommendationGetResponseValueFlexible, RecommendationGetResponseValueFull, RecommendationGetResponseValueStrict:
return true
}
return false
}

type RecommendationGetParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
}

type RecommendationGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success RecommendationGetResponseEnvelopeSuccess `json:"success,required"`
Result RecommendationGetResponse `json:"result"`
JSON recommendationGetResponseEnvelopeJSON `json:"-"`
}

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

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

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

// Whether the API call was successful
type RecommendationGetResponseEnvelopeSuccess bool

const (
RecommendationGetResponseEnvelopeSuccessTrue RecommendationGetResponseEnvelopeSuccess = true
)

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

package ssl_test

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

"github.com/cloudflare/cloudflare-go/v4"
"github.com/cloudflare/cloudflare-go/v4/internal/testutil"
"github.com/cloudflare/cloudflare-go/v4/option"
"github.com/cloudflare/cloudflare-go/v4/ssl"
)

func TestRecommendationGet(t *testing.T) {
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.SSL.Recommendations.Get(context.TODO(), ssl.RecommendationGetParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
})
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 3359bd6

Please sign in to comment.