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 19, 2024
1 parent bf10c1d commit 39b74aa
Show file tree
Hide file tree
Showing 51 changed files with 3,571 additions and 1,558 deletions.
32 changes: 16 additions & 16 deletions audiences.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (

type AudiencesListParams struct {
// A unique identifier that allows for fetching the next set of audiences
Cursor *string `json:"-"`
Cursor *string `json:"-" url:"cursor,omitempty"`
}

type AudienceMembersListParams struct {
// A unique identifier that allows for fetching the next set of members
Cursor *string `json:"-"`
Cursor *string `json:"-" url:"cursor,omitempty"`
}

type Audience struct {
// A unique identifier representing the audience_id
Id string `json:"id"`
Id string `json:"id" url:"id"`
// The name of the audience
Name string `json:"name"`
Name string `json:"name" url:"name"`
// A description of the audience
Description string `json:"description"`
Filter *Filter `json:"filter,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Description string `json:"description" url:"description"`
Filter *Filter `json:"filter,omitempty" url:"filter,omitempty"`
CreatedAt string `json:"created_at" url:"created_at"`
UpdatedAt string `json:"updated_at" url:"updated_at"`

_rawJSON json.RawMessage
}
Expand Down Expand Up @@ -56,8 +56,8 @@ func (a *Audience) String() string {
}

type AudienceListResponse struct {
Items []*Audience `json:"items,omitempty"`
Paging *Paging `json:"paging,omitempty"`
Items []*Audience `json:"items,omitempty" url:"items,omitempty"`
Paging *Paging `json:"paging,omitempty" url:"paging,omitempty"`

_rawJSON json.RawMessage
}
Expand Down Expand Up @@ -86,8 +86,8 @@ func (a *AudienceListResponse) String() string {
}

type AudienceMemberListResponse struct {
Items []*AudienceMember `json:"items,omitempty"`
Paging *Paging `json:"paging,omitempty"`
Items []*AudienceMember `json:"items,omitempty" url:"items,omitempty"`
Paging *Paging `json:"paging,omitempty" url:"paging,omitempty"`

_rawJSON json.RawMessage
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (a *AudienceMemberListResponse) String() string {
}

type AudienceUpdateResponse struct {
Audience *Audience `json:"audience,omitempty"`
Audience *Audience `json:"audience,omitempty" url:"audience,omitempty"`

_rawJSON json.RawMessage
}
Expand Down Expand Up @@ -203,8 +203,8 @@ func (f *Filter) Accept(visitor FilterVisitor) error {

type AudienceUpdateParams struct {
// The name of the audience
Name *string `json:"name,omitempty"`
Name *string `json:"name,omitempty" url:"name,omitempty"`
// A description of the audience
Description *string `json:"description,omitempty"`
Filter *Filter `json:"filter,omitempty"`
Description *string `json:"description,omitempty" url:"description,omitempty"`
Filter *Filter `json:"filter,omitempty" url:"filter,omitempty"`
}
147 changes: 106 additions & 41 deletions audiences/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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"
)

type Client struct {
Expand All @@ -21,36 +21,50 @@ type Client struct {
header http.Header
}

func NewClient(opts ...core.ClientOption) *Client {
options := core.NewClientOptions()
for _, opt := range opts {
opt(options)
}
func NewClient(opts ...option.RequestOption) *Client {
options := core.NewRequestOptions(opts...)
return &Client{
baseURL: options.BaseURL,
caller: core.NewCaller(options.HTTPClient),
header: options.ToHeader(),
caller: core.NewCaller(
&core.CallerParams{
Client: options.HTTPClient,
MaxAttempts: options.MaxAttempts,
},
),
header: options.ToHeader(),
}
}

// Returns the specified audience by id.
//
// A unique identifier representing the audience_id
func (c *Client) Get(ctx context.Context, audienceId string) (*v3.Audience, error) {
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...)

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: c.header,
Response: &response,
URL: endpointURL,
Method: http.MethodGet,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
},
); err != nil {
return nil, err
Expand All @@ -59,24 +73,37 @@ func (c *Client) Get(ctx context.Context, audienceId string) (*v3.Audience, erro
}

// Creates or updates audience.
//
// A unique identifier representing the audience id
func (c *Client) Update(ctx context.Context, audienceId string, request *v3.AudienceUpdateParams) (*v3.AudienceUpdateResponse, error) {
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...)

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: c.header,
Request: request,
Response: &response,
URL: endpointURL,
Method: http.MethodPut,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
},
); err != nil {
return nil, err
Expand All @@ -85,21 +112,33 @@ func (c *Client) Update(ctx context.Context, audienceId string, request *v3.Audi
}

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

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: c.header,
URL: endpointURL,
Method: http.MethodDelete,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
},
); err != nil {
return err
Expand All @@ -108,23 +147,34 @@ func (c *Client) Delete(ctx context.Context, audienceId string) error {
}

// Get list of members of an audience.
//
// A unique identifier representing the audience id
func (c *Client) ListMembers(ctx context.Context, audienceId string, request *v3.AudienceMembersListParams) (*v3.AudienceMemberListResponse, error) {
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...)

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)
if request.Cursor != nil {
queryParams.Add("cursor", fmt.Sprintf("%v", *request.Cursor))
queryParams, err := core.QueryValues(request)
if err != nil {
return nil, err
}
if len(queryParams) > 0 {
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 @@ -150,7 +200,9 @@ func (c *Client) ListMembers(ctx context.Context, audienceId string, request *v3
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: c.header,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
Expand All @@ -161,21 +213,32 @@ func (c *Client) ListMembers(ctx context.Context, audienceId string, request *v3
}

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

baseURL := "https://api.courier.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := baseURL + "/" + "audiences"

queryParams := make(url.Values)
if request.Cursor != nil {
queryParams.Add("cursor", fmt.Sprintf("%v", *request.Cursor))
queryParams, err := core.QueryValues(request)
if err != nil {
return nil, err
}
if len(queryParams) > 0 {
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 @@ -201,7 +264,9 @@ func (c *Client) ListAudiences(ctx context.Context, request *v3.AudiencesListPar
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
Headers: c.header,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
Expand Down
18 changes: 9 additions & 9 deletions audit_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (

type ListAuditEventsRequest struct {
// A unique identifier that allows for fetching the next set of audit events.
Cursor *string `json:"-"`
Cursor *string `json:"-" url:"cursor,omitempty"`
}

type AuditEvent struct {
Actor *Actor `json:"actor,omitempty"`
Target *Target `json:"target,omitempty"`
AuditEventId string `json:"auditEventId"`
Source string `json:"source"`
Timestamp string `json:"timestamp"`
Type string `json:"type"`
Actor *Actor `json:"actor,omitempty" url:"actor,omitempty"`
Target *Target `json:"target,omitempty" url:"target,omitempty"`
AuditEventId string `json:"auditEventId" url:"auditEventId"`
Source string `json:"source" url:"source"`
Timestamp string `json:"timestamp" url:"timestamp"`
Type string `json:"type" url:"type"`

_rawJSON json.RawMessage
}
Expand Down Expand Up @@ -48,8 +48,8 @@ func (a *AuditEvent) String() string {
}

type ListAuditEventsResponse struct {
Paging *Paging `json:"paging,omitempty"`
Results []*AuditEvent `json:"results,omitempty"`
Paging *Paging `json:"paging,omitempty" url:"paging,omitempty"`
Results []*AuditEvent `json:"results,omitempty" url:"results,omitempty"`

_rawJSON json.RawMessage
}
Expand Down
Loading

0 comments on commit 39b74aa

Please sign in to comment.