Skip to content

Commit

Permalink
Release v0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed May 24, 2024
1 parent f7278c2 commit 0d7f27a
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 23 deletions.
29 changes: 29 additions & 0 deletions apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,32 @@ func (a *AppsResponse) String() string {
}
return fmt.Sprintf("%#v", a)
}

type SuccessResponse struct {
Success bool `json:"success" url:"success"`

_rawJSON json.RawMessage
}

func (s *SuccessResponse) UnmarshalJSON(data []byte) error {
type unmarshaler SuccessResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*s = SuccessResponse(value)
s._rawJSON = json.RawMessage(data)
return nil
}

func (s *SuccessResponse) String() string {
if len(s._rawJSON) > 0 {
if value, err := core.StringifyJSON(s._rawJSON); err == nil {
return value
}
}
if value, err := core.StringifyJSON(s); err == nil {
return value
}
return fmt.Sprintf("%#v", s)
}
37 changes: 37 additions & 0 deletions apps/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,40 @@ func (c *Client) Create(
}
return response, nil
}

// Deletes an app
func (c *Client) Delete(
ctx context.Context,
// ID of app to delete
appId flatfilego.AppId,
opts ...option.RequestOption,
) (*flatfilego.SuccessResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.x.flatfile.com/v1"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"apps/%v", appId)

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

var response *flatfilego.SuccessResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodDelete,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Response: &response,
},
); err != nil {
return nil, err
}
return response, nil
}
2 changes: 1 addition & 1 deletion core/request_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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/FlatFilers/flatfile-go")
headers.Set("X-Fern-SDK-Version", "v0.0.12")
headers.Set("X-Fern-SDK-Version", "v0.0.13")
return headers
}

Expand Down
2 changes: 1 addition & 1 deletion documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *DocumentResponse) String() string {
}

type ListDocumentsResponse struct {
Data []*DocumentResponse `json:"data,omitempty" url:"data,omitempty"`
Data []*Document `json:"data,omitempty" url:"data,omitempty"`

_rawJSON json.RawMessage
}
Expand Down
2 changes: 2 additions & 0 deletions jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ type JobConfig struct {
PartExecution *JobPartExecution `json:"partExecution,omitempty" url:"partExecution,omitempty"`
// The id of the parent job
ParentId *JobId `json:"parentId,omitempty" url:"parentId,omitempty"`
// The ids of the jobs that must complete before this job can start
PredecessorIds []JobId `json:"predecessorIds,omitempty" url:"predecessorIds,omitempty"`

_rawJSON json.RawMessage
}
Expand Down
5 changes: 5 additions & 0 deletions mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type DeleteAllHistoryForUserRequest struct {
EnvironmentId *EnvironmentId `json:"environmentId,omitempty" url:"environmentId,omitempty"`
}

type DeleteMultipleRulesRequest struct {
// Array of rule IDs to be deleted
RuleIds []MappingId `json:"ruleIds,omitempty" url:"ruleIds,omitempty"`
}

type ListProgramsRequest struct {
// Number of programs to return in a page (default 10)
PageSize *int `json:"-" url:"pageSize,omitempty"`
Expand Down
66 changes: 66 additions & 0 deletions mapping/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,72 @@ func (c *Client) CreateRules(
return response, nil
}

// Deletes multiple mapping rules from a program
func (c *Client) DeleteMultipleRules(
ctx context.Context,
// ID of the program
programId flatfilego.ProgramId,
request *flatfilego.DeleteMultipleRulesRequest,
opts ...option.RequestOption,
) (*flatfilego.Success, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.x.flatfile.com/v1"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"mapping/%v/rules", programId)

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))
switch statusCode {
case 400:
value := new(flatfilego.BadRequestError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
case 404:
value := new(flatfilego.NotFoundError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
}
return apiError
}

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

// List all mapping rules in a program
func (c *Client) ListRules(
ctx context.Context,
Expand Down
35 changes: 35 additions & 0 deletions sheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,38 @@ func (s *SheetResponse) String() string {
}
return fmt.Sprintf("%#v", s)
}

// Changes to make to an existing sheet
type SheetUpdateRequest struct {
// The name of the Sheet.
Name *string `json:"name,omitempty" url:"name,omitempty"`
// The slug of the Sheet.
Slug *string `json:"slug,omitempty" url:"slug,omitempty"`
// Useful for any contextual metadata regarding the sheet. Store any valid json
Metadata interface{} `json:"metadata,omitempty" url:"metadata,omitempty"`

_rawJSON json.RawMessage
}

func (s *SheetUpdateRequest) UnmarshalJSON(data []byte) error {
type unmarshaler SheetUpdateRequest
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*s = SheetUpdateRequest(value)
s._rawJSON = json.RawMessage(data)
return nil
}

func (s *SheetUpdateRequest) String() string {
if len(s._rawJSON) > 0 {
if value, err := core.StringifyJSON(s._rawJSON); err == nil {
return value
}
}
if value, err := core.StringifyJSON(s); err == nil {
return value
}
return fmt.Sprintf("%#v", s)
}
66 changes: 66 additions & 0 deletions sheets/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,69 @@ func (c *Client) GetCellValues(
}
return response, nil
}

// Updates Sheet
func (c *Client) UpdateSheet(
ctx context.Context,
// ID of sheet
sheetId flatfilego.SheetId,
request *flatfilego.SheetUpdateRequest,
opts ...option.RequestOption,
) (*flatfilego.SheetResponse, error) {
options := core.NewRequestOptions(opts...)

baseURL := "https://api.x.flatfile.com/v1"
if c.baseURL != "" {
baseURL = c.baseURL
}
if options.BaseURL != "" {
baseURL = options.BaseURL
}
endpointURL := fmt.Sprintf(baseURL+"/"+"sheets/%v", sheetId)

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))
switch statusCode {
case 400:
value := new(flatfilego.BadRequestError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
case 404:
value := new(flatfilego.NotFoundError)
value.APIError = apiError
if err := decoder.Decode(value); err != nil {
return apiError
}
return value
}
return apiError
}

var response *flatfilego.SheetResponse
if err := c.caller.Call(
ctx,
&core.CallParams{
URL: endpointURL,
Method: http.MethodPatch,
MaxAttempts: options.MaxAttempts,
Headers: headers,
Client: options.HTTPClient,
Request: request,
Response: &response,
ErrorDecoder: errorDecoder,
},
); err != nil {
return nil, err
}
return response, nil
}
16 changes: 13 additions & 3 deletions spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const (
EventTopicCronHourly EventTopic = "cron:hourly"
EventTopicCronDaily EventTopic = "cron:daily"
EventTopicCronWeekly EventTopic = "cron:weekly"
EventTopicEnvironmentCreated EventTopic = "environment:created"
EventTopicEnvironmentUpdated EventTopic = "environment:updated"
EventTopicEnvironmentDeleted EventTopic = "environment:deleted"
)

func NewEventTopicFromString(s string) (EventTopic, error) {
Expand Down Expand Up @@ -196,6 +199,12 @@ func NewEventTopicFromString(s string) (EventTopic, error) {
return EventTopicCronDaily, nil
case "cron:weekly":
return EventTopicCronWeekly, nil
case "environment:created":
return EventTopicEnvironmentCreated, nil
case "environment:updated":
return EventTopicEnvironmentUpdated, nil
case "environment:deleted":
return EventTopicEnvironmentDeleted, nil
}
var t EventTopic
return "", fmt.Errorf("%s is not a valid %T", s, t)
Expand Down Expand Up @@ -272,9 +281,10 @@ func (l *ListSpacesResponse) String() string {

// Properties used to create a new Space
type SpaceConfig struct {
SpaceConfigId *SpaceConfigId `json:"spaceConfigId,omitempty" url:"spaceConfigId,omitempty"`
EnvironmentId *EnvironmentId `json:"environmentId,omitempty" url:"environmentId,omitempty"`
PrimaryWorkbookId *WorkbookId `json:"primaryWorkbookId,omitempty" url:"primaryWorkbookId,omitempty"`
SpaceConfigId *SpaceConfigId `json:"spaceConfigId,omitempty" url:"spaceConfigId,omitempty"`
EnvironmentId *EnvironmentId `json:"environmentId,omitempty" url:"environmentId,omitempty"`
// The ID of the primary workbook for the space. This should not be included in create space requests.
PrimaryWorkbookId *WorkbookId `json:"primaryWorkbookId,omitempty" url:"primaryWorkbookId,omitempty"`
// Metadata for the space
Metadata interface{} `json:"metadata,omitempty" url:"metadata,omitempty"`
// The Space settings.
Expand Down
Loading

0 comments on commit 0d7f27a

Please sign in to comment.