Skip to content

Commit

Permalink
Release v0.5.8-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Sep 9, 2024
1 parent f13de14 commit ef463dc
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/request_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *RequestOptions) cloneHeader() http.Header {
headers := r.HTTPHeader.Clone()
headers.Set("X-Fern-Language", "Go")
headers.Set("X-Fern-SDK-Name", "github.com/mercoa-finance/go")
headers.Set("X-Fern-SDK-Version", "v0.5.7")
headers.Set("X-Fern-SDK-Version", "v0.5.8-rc1")
return headers
}

Expand Down
115 changes: 115 additions & 0 deletions entity/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,3 +1277,118 @@ func (c *Client) SendOnboardingLink(
}
return nil
}

// Get all events for an entity
func (c *Client) Events(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
request *entity.EntityEntityGetEventsRequest,
opts ...option.RequestOption,
) (*mercoafinancego.EntityEventsResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.mercoa.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := core.EncodeURL(baseURL+"/entity/%v/events", entityID)

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 {
return err
}
apiError := core.NewAPIError(statusCode, errors.New(string(raw)))
decoder := json.NewDecoder(bytes.NewReader(raw))
var discriminant struct {
ErrorName string `json:"errorName"`
Content json.RawMessage `json:"content"`
}
if err := decoder.Decode(&discriminant); err != nil {
return apiError
}
switch discriminant.ErrorName {
case "BadRequest":
value := new(mercoafinancego.BadRequest)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Unauthorized":
value := new(mercoafinancego.Unauthorized)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Forbidden":
value := new(mercoafinancego.Forbidden)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "NotFound":
value := new(mercoafinancego.NotFound)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Conflict":
value := new(mercoafinancego.Conflict)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "InternalServerError":
value := new(mercoafinancego.InternalServerError)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Unimplemented":
value := new(mercoafinancego.Unimplemented)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
}
return apiError
}

var response *mercoafinancego.EntityEventsResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
}
return response, nil
}
4 changes: 4 additions & 0 deletions entity/counterparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type FindPayeeCounterpartiesRequest struct {
InvoiceMetrics *bool `json:"-" url:"invoiceMetrics,omitempty"`
// Filter by counterparty ids (Foreign ID is supported)
CounterpartyID []*mercoafinancego.EntityID `json:"-" url:"counterpartyId,omitempty"`
// If true, will return simple key/value metadata for the counterparties.
ReturnMetadata *bool `json:"-" url:"returnMetadata,omitempty"`
// Number of counterparties to return. Limit can range between 1 and 100, and the default is 10.
Limit *int `json:"-" url:"limit,omitempty"`
// The ID of the counterparties to start after. If not provided, the first page of counterparties will be returned.
Expand All @@ -34,6 +36,8 @@ type FindPayorCounterpartiesRequest struct {
InvoiceMetrics *bool `json:"-" url:"invoiceMetrics,omitempty"`
// Filter by counterparty ids (Foreign ID is supported)
CounterpartyID []*mercoafinancego.EntityID `json:"-" url:"counterpartyId,omitempty"`
// If true, will return simple key/value metadata for the counterparties.
ReturnMetadata *bool `json:"-" url:"returnMetadata,omitempty"`
// Number of counterparties to return. Limit can range between 1 and 100, and the default is 10.
Limit *int `json:"-" url:"limit,omitempty"`
// The ID of the counterparties to start after. If not provided, the first page of counterparties will be returned.
Expand Down
12 changes: 11 additions & 1 deletion entity/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ import (
fmt "fmt"
mercoafinancego "github.com/mercoa-finance/go"
core "github.com/mercoa-finance/go/core"
time "time"
)

type EntityEntityGetEventsRequest struct {
// Start date filter. If not provided, events from the start of time will be returned.
StartDate *time.Time `json:"-" url:"startDate,omitempty"`
// End date filter. If not provided, events to the end of time will be returned.
EndDate *time.Time `json:"-" url:"endDate,omitempty"`
}

type FindEntities struct {
// If true, will include entity payment methods as part of the response
PaymentMethods *bool `json:"-" url:"paymentMethods,omitempty"`
Expand All @@ -25,6 +33,8 @@ type FindEntities struct {
IsPayor *bool `json:"-" url:"isPayor,omitempty"`
// Filter entities by name. Partial matches are supported.
Name *string `json:"-" url:"name,omitempty"`
// If true, will return simple key/value metadata for the entity. For more complex metadata, use the Metadata API.
ReturnMetadata *bool `json:"-" url:"returnMetadata,omitempty"`
// Number of entities to return. Limit can range between 1 and 100, and the default is 10.
Limit *int `json:"-" url:"limit,omitempty"`
// The ID of the entity to start after. If not provided, the first page of entities will be returned.
Expand All @@ -33,7 +43,7 @@ type FindEntities struct {

type EntityGetRequest struct {
// If true, will return simple key/value metadata for the entity. For more complex metadata, use the Metadata API.
Metadata *bool `json:"-" url:"metadata,omitempty"`
ReturnMetadata *bool `json:"-" url:"returnMetadata,omitempty"`
}

type GenerateOnboardingLink struct {
Expand Down
4 changes: 4 additions & 0 deletions entity/user/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (c *Client) Get(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
opts ...option.RequestOption,
) (*mercoafinancego.EntityUserResponse, error) {
Expand Down Expand Up @@ -486,6 +487,7 @@ func (c *Client) Update(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
request *mercoafinancego.EntityUserRequest,
opts ...option.RequestOption,
Expand Down Expand Up @@ -599,6 +601,7 @@ func (c *Client) Delete(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
opts ...option.RequestOption,
) error {
Expand Down Expand Up @@ -708,6 +711,7 @@ func (c *Client) GetToken(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
request *mercoafinancego.TokenGenerationOptions,
opts ...option.RequestOption,
Expand Down
3 changes: 3 additions & 0 deletions entity/user/notificationpolicy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (c *Client) GetAll(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
opts ...option.RequestOption,
) ([]*mercoafinancego.UserNotificationPolicyResponse, error) {
Expand Down Expand Up @@ -150,6 +151,7 @@ func (c *Client) Get(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
notificationType mercoafinancego.NotificationType,
opts ...option.RequestOption,
Expand Down Expand Up @@ -263,6 +265,7 @@ func (c *Client) Update(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
notificationType mercoafinancego.NotificationType,
request *mercoafinancego.UserNotificationPolicyRequest,
Expand Down
3 changes: 3 additions & 0 deletions entity/user/notifications/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (c *Client) Find(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
request *user.EntityGetNotificationsRequest,
opts ...option.RequestOption,
Expand Down Expand Up @@ -158,6 +159,7 @@ func (c *Client) Get(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
notificationID mercoafinancego.NotificationID,
opts ...option.RequestOption,
Expand Down Expand Up @@ -271,6 +273,7 @@ func (c *Client) Update(
ctx context.Context,
// Entity ID or Entity ForeignID
entityID mercoafinancego.EntityID,
// User ID or User ForeignID
userID mercoafinancego.EntityUserID,
notificationID mercoafinancego.NotificationID,
request *mercoafinancego.NotificationUpdateRequest,
Expand Down
2 changes: 1 addition & 1 deletion entitygroup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type EntityGroupGetRequest struct {
// If true, will return simple key/value metadata for entities in the group. For more complex metadata, use the Metadata API.
EntityMetadata *bool `json:"-" url:"entityMetadata,omitempty"`
ReturnEntityMetadata *bool `json:"-" url:"returnEntityMetadata,omitempty"`
}

type EntityGroupFindRequest struct {
Expand Down
115 changes: 115 additions & 0 deletions invoice/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,118 @@ func (c *Client) Delete(
}
return nil
}

// Get all events for an invoice
func (c *Client) Events(
ctx context.Context,
// Invoice ID or Invoice ForeignID
invoiceID mercoafinancego.InvoiceID,
request *invoice.InvoiceInvoiceGetEventsRequest,
opts ...option.RequestOption,
) (*mercoafinancego.InvoiceEventsResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.mercoa.com"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := core.EncodeURL(baseURL+"/invoice/%v/events", invoiceID)

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 {
return err
}
apiError := core.NewAPIError(statusCode, errors.New(string(raw)))
decoder := json.NewDecoder(bytes.NewReader(raw))
var discriminant struct {
ErrorName string `json:"errorName"`
Content json.RawMessage `json:"content"`
}
if err := decoder.Decode(&discriminant); err != nil {
return apiError
}
switch discriminant.ErrorName {
case "BadRequest":
value := new(mercoafinancego.BadRequest)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Unauthorized":
value := new(mercoafinancego.Unauthorized)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Forbidden":
value := new(mercoafinancego.Forbidden)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "NotFound":
value := new(mercoafinancego.NotFound)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Conflict":
value := new(mercoafinancego.Conflict)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "InternalServerError":
value := new(mercoafinancego.InternalServerError)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
case "Unimplemented":
value := new(mercoafinancego.Unimplemented)
value.APIError = apiError
if err := json.Unmarshal(discriminant.Content, value); err != nil {
return apiError
}
return value
}
return apiError
}

var response *mercoafinancego.InvoiceEventsResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodGet,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
}
return response, nil
}
Loading

0 comments on commit ef463dc

Please sign in to comment.