Skip to content

Commit

Permalink
SDK regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Feb 1, 2024
1 parent d86e996 commit 49cc9ef
Show file tree
Hide file tree
Showing 31 changed files with 1,035 additions and 1,574 deletions.
102 changes: 23 additions & 79 deletions audiences/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
fmt "fmt"
v3 "github.com/trycourier/courier-go/v3"
core "github.com/trycourier/courier-go/v3/core"
option "github.com/trycourier/courier-go/v3/option"
io "io"
http "net/http"
url "net/url"
Expand All @@ -22,8 +21,11 @@ type Client struct {
header http.Header
}

func NewClient(opts ...option.RequestOption) *Client {
options := core.NewRequestOptions(opts...)
func NewClient(opts ...core.ClientOption) *Client {
options := core.NewClientOptions()
for _, opt := range opts {
opt(options)
}
return &Client{
baseURL: options.BaseURL,
caller: core.NewCaller(options.HTTPClient),
Expand All @@ -32,33 +34,22 @@ func NewClient(opts ...option.RequestOption) *Client {
}

// Returns the specified audience by id.
func (c *Client) Get(
ctx context.Context,
// A unique identifier representing the audience_id
audienceId string,
opts ...option.RequestOption,
) (*v3.Audience, error) {
options := core.NewRequestOptions(opts...)

//
// A unique identifier representing the audience_id
func (c *Client) Get(ctx context.Context, audienceId string) (*v3.Audience, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"audiences/%v", audienceId)

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

var response *v3.Audience
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Response: &response,
},
); err != nil {
Expand All @@ -68,34 +59,22 @@ func (c *Client) Get(
}

// Creates or updates audience.
func (c *Client) Update(
ctx context.Context,
// A unique identifier representing the audience id
audienceId string,
request *v3.AudienceUpdateParams,
opts ...option.RequestOption,
) (*v3.AudienceUpdateResponse, error) {
options := core.NewRequestOptions(opts...)

//
// A unique identifier representing the audience id
func (c *Client) Update(ctx context.Context, audienceId string, request *v3.AudienceUpdateParams) (*v3.AudienceUpdateResponse, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"audiences/%v", audienceId)

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

var response *v3.AudienceUpdateResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPut,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Request: request,
Response: &response,
},
Expand All @@ -106,32 +85,21 @@ func (c *Client) Update(
}

// Deletes the specified audience.
func (c *Client) Delete(
ctx context.Context,
// A unique identifier representing the audience id
audienceId string,
opts ...option.RequestOption,
) error {
options := core.NewRequestOptions(opts...)

//
// A unique identifier representing the audience id
func (c *Client) Delete(ctx context.Context, audienceId string) error {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"audiences/%v", audienceId)

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodDelete,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
},
); err != nil {
return err
Expand All @@ -140,22 +108,13 @@ func (c *Client) Delete(
}

// Get list of members of an audience.
func (c *Client) ListMembers(
ctx context.Context,
// A unique identifier representing the audience id
audienceId string,
request *v3.AudienceMembersListParams,
opts ...option.RequestOption,
) (*v3.AudienceMemberListResponse, error) {
options := core.NewRequestOptions(opts...)

//
// A unique identifier representing the audience id
func (c *Client) ListMembers(ctx context.Context, audienceId string, request *v3.AudienceMembersListParams) (*v3.AudienceMemberListResponse, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"audiences/%v/members", audienceId)

queryParams := make(url.Values)
Expand All @@ -166,8 +125,6 @@ func (c *Client) ListMembers(
endpointURL += "?" + queryParams.Encode()
}

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

errorDecoder := func(statusCode int, body io.Reader) error {
raw, err := io.ReadAll(body)
if err != nil {
Expand All @@ -193,8 +150,7 @@ func (c *Client) ListMembers(
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Response: &response,
ErrorDecoder: errorDecoder,
},
Expand All @@ -205,20 +161,11 @@ func (c *Client) ListMembers(
}

// Get the audiences associated with the authorization token.
func (c *Client) ListAudiences(
ctx context.Context,
request *v3.AudiencesListParams,
opts ...option.RequestOption,
) (*v3.AudienceListResponse, error) {
options := core.NewRequestOptions(opts...)

func (c *Client) ListAudiences(ctx context.Context, request *v3.AudiencesListParams) (*v3.AudienceListResponse, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := baseURL + "/" + "audiences"

queryParams := make(url.Values)
Expand All @@ -229,8 +176,6 @@ func (c *Client) ListAudiences(
endpointURL += "?" + queryParams.Encode()
}

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

errorDecoder := func(statusCode int, body io.Reader) error {
raw, err := io.ReadAll(body)
if err != nil {
Expand All @@ -256,8 +201,7 @@ func (c *Client) ListAudiences(
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Response: &response,
ErrorDecoder: errorDecoder,
},
Expand Down
43 changes: 11 additions & 32 deletions auditevents/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
fmt "fmt"
v3 "github.com/trycourier/courier-go/v3"
core "github.com/trycourier/courier-go/v3/core"
option "github.com/trycourier/courier-go/v3/option"
http "net/http"
url "net/url"
)
Expand All @@ -18,8 +17,11 @@ type Client struct {
header http.Header
}

func NewClient(opts ...option.RequestOption) *Client {
options := core.NewRequestOptions(opts...)
func NewClient(opts ...core.ClientOption) *Client {
options := core.NewClientOptions()
for _, opt := range opts {
opt(options)
}
return &Client{
baseURL: options.BaseURL,
caller: core.NewCaller(options.HTTPClient),
Expand All @@ -28,20 +30,11 @@ func NewClient(opts ...option.RequestOption) *Client {
}

// Fetch the list of audit events
func (c *Client) List(
ctx context.Context,
request *v3.ListAuditEventsRequest,
opts ...option.RequestOption,
) (*v3.ListAuditEventsResponse, error) {
options := core.NewRequestOptions(opts...)

func (c *Client) List(ctx context.Context, request *v3.ListAuditEventsRequest) (*v3.ListAuditEventsResponse, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := baseURL + "/" + "audit-events"

queryParams := make(url.Values)
Expand All @@ -52,16 +45,13 @@ func (c *Client) List(
endpointURL += "?" + queryParams.Encode()
}

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

var response *v3.ListAuditEventsResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Response: &response,
},
); err != nil {
Expand All @@ -71,33 +61,22 @@ func (c *Client) List(
}

// Fetch a specific audit event by ID.
func (c *Client) Get(
ctx context.Context,
// A unique identifier associated with the audit event you wish to retrieve
auditEventId string,
opts ...option.RequestOption,
) (*v3.AuditEvent, error) {
options := core.NewRequestOptions(opts...)

//
// A unique identifier associated with the audit event you wish to retrieve
func (c *Client) Get(ctx context.Context, auditEventId string) (*v3.AuditEvent, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"audit-events/%v", auditEventId)

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

var response *v3.AuditEvent
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Response: &response,
},
); err != nil {
Expand Down
24 changes: 7 additions & 17 deletions authtokens/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
context "context"
v3 "github.com/trycourier/courier-go/v3"
core "github.com/trycourier/courier-go/v3/core"
option "github.com/trycourier/courier-go/v3/option"
http "net/http"
)

Expand All @@ -16,8 +15,11 @@ type Client struct {
header http.Header
}

func NewClient(opts ...option.RequestOption) *Client {
options := core.NewRequestOptions(opts...)
func NewClient(opts ...core.ClientOption) *Client {
options := core.NewClientOptions()
for _, opt := range opts {
opt(options)
}
return &Client{
baseURL: options.BaseURL,
caller: core.NewCaller(options.HTTPClient),
Expand All @@ -26,32 +28,20 @@ func NewClient(opts ...option.RequestOption) *Client {
}

// Returns a new access token.
func (c *Client) IssueToken(
ctx context.Context,
request *v3.IssueTokenParams,
opts ...option.IdempotentRequestOption,
) (*v3.IssueTokenResponse, error) {
options := core.NewIdempotentRequestOptions(opts...)

func (c *Client) IssueToken(ctx context.Context, request *v3.IssueTokenParams) (*v3.IssueTokenResponse, error) {
baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := baseURL + "/" + "auth/issue-token"

headers := core.MergeHeaders(c.header.Clone(), options.ToHeader())

var response *v3.IssueTokenResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPost,
Headers: headers,
Client: options.HTTPClient,
Headers: c.header,
Request: request,
Response: &response,
},
Expand Down
Loading

0 comments on commit 49cc9ef

Please sign in to comment.