Skip to content

Latest commit

 

History

History
333 lines (257 loc) · 15 KB

README.md

File metadata and controls

333 lines (257 loc) · 15 KB

Files

(Files)

Overview

Available Operations

List

List files.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Files.List(ctx, nil, nil, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceFileRead != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
organizationID *string N/A
ids []string List of file IDs to get.
page *int64 Page number, defaults to 1.
limit *int64 Size of a page, defaults to 10. Maximum is 100.
opts []operations.Option The options for this request.

Response

*operations.FilesListResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Create a file.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Files.Create(ctx, components.CreateFileCreateProductMediaFileCreate(
        components.ProductMediaFileCreate{
            Name: "<value>",
            MimeType: "<value>",
            Size: 951062,
            Upload: components.S3FileCreateMultipart{
                Parts: []components.S3FileCreatePart{
                    components.S3FileCreatePart{
                        Number: 86,
                        ChunkStart: 169727,
                        ChunkEnd: 89964,
                    },
                },
            },
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.FileUpload != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.FileCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.FilesCreateResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Uploaded

Complete a file upload.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Files.Uploaded(ctx, "<value>", components.FileUploadCompleted{
        ID: "<id>",
        Path: "/sys",
        Parts: []components.S3FileUploadCompletedPart{
            components.S3FileUploadCompletedPart{
                Number: 173116,
                ChecksumEtag: "<value>",
                ChecksumSha256Base64: polargo.String("<value>"),
            },
            components.S3FileUploadCompletedPart{
                Number: 894030,
                ChecksumEtag: "<value>",
                ChecksumSha256Base64: polargo.String("<value>"),
            },
            components.S3FileUploadCompletedPart{
                Number: 673715,
                ChecksumEtag: "<value>",
                ChecksumSha256Base64: polargo.String("<value>"),
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ResponseFilesUploaded != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The file ID.
fileUploadCompleted components.FileUploadCompleted ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.FilesUploadedResponse, error

Errors

Error Type Status Code Content Type
apierrors.NotPermitted 403 application/json
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update a file.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Files.Update(ctx, "<value>", components.FilePatch{})
    if err != nil {
        log.Fatal(err)
    }
    if res.ResponseFilesUpdate != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The file ID.
filePatch components.FilePatch ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.FilesUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.NotPermitted 403 application/json
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a file.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Files.Delete(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.FilesDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.NotPermitted 403 application/json
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*