cms

package module
v0.0.0-...-80539dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 17 Imported by: 18

README

reearth-cms-api

Supported Go version: >=1.18

go get github.com/reearth/reearth-cms-api/go

Documentation

Index

Constants

View Source
const (
	AssetArchiveExtractionStatusDone = "done"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func Marshal

func Marshal(src any, item *Item)

Types

type Asset

type Asset struct {
	ArchiveExtractionStatus string    `json:"archiveExtractionStatus,omitempty"`
	ContentType             string    `json:"contentType,omitempty"`
	CreatedAt               time.Time `json:"createdAt"`
	File                    *File     `json:"file,omitempty"`
	ID                      string    `json:"id"`
	Name                    string    `json:"name,omitempty"`
	PreviewType             string    `json:"previewType,omitempty"`
	ProjectID               string    `json:"projectId"`
	TotalSize               uint64    `json:"totalSize,omitempty"`
	UpdatedAt               time.Time `json:"updatedAt"`
	URL                     string    `json:"url"`
}

func (*Asset) Clone

func (a *Asset) Clone() *Asset

func (*Asset) ToPublic

func (a *Asset) ToPublic() *PublicAsset

type AssetUpload

type AssetUpload struct {
	URL         string `json:"url"`
	Token       string `json:"token"`
	ContentType string `json:"contentType"`
}

type CMS

type CMS struct {
	// contains filtered or unexported fields
}

func New

func New(base, token string) (*CMS, error)

func (*CMS) Asset

func (c *CMS) Asset(ctx context.Context, assetID string) (*Asset, error)

func (*CMS) CommentToAsset

func (c *CMS) CommentToAsset(ctx context.Context, assetID, content string) error

func (*CMS) CommentToItem

func (c *CMS) CommentToItem(ctx context.Context, itemID, content string) error

func (*CMS) CreateAssetByToken

func (c *CMS) CreateAssetByToken(ctx context.Context, projectID, token string) (*Asset, error)

func (*CMS) CreateAssetUpload

func (c *CMS) CreateAssetUpload(ctx context.Context, projectID, name string) (*AssetUpload, error)

func (*CMS) CreateItem

func (c *CMS) CreateItem(ctx context.Context, modelID string, fields []*Field, metadataFields []*Field) (*Item, error)

func (*CMS) CreateItemByKey

func (c *CMS) CreateItemByKey(ctx context.Context, projectID, modelID string, fields []*Field, metadataFields []*Field) (*Item, error)

func (*CMS) DeleteItem

func (c *CMS) DeleteItem(ctx context.Context, itemID string) error

func (*CMS) GetItem

func (c *CMS) GetItem(ctx context.Context, itemID string, asset bool) (*Item, error)

func (*CMS) GetItems

func (c *CMS) GetItems(ctx context.Context, modelID string, asset bool) (items *Items, _ error)

func (*CMS) GetItemsByKey

func (c *CMS) GetItemsByKey(ctx context.Context, projectIDOrAlias, modelIDOrAlias string, asset bool) (*Items, error)

func (*CMS) GetItemsByKeyInParallel

func (c *CMS) GetItemsByKeyInParallel(ctx context.Context, projectIDOrAlias, modelIDOrAlias string, asset bool, limit int) (*Items, error)

func (*CMS) GetItemsInParallel

func (c *CMS) GetItemsInParallel(ctx context.Context, modelID string, asset bool, limit int) (*Items, error)

func (*CMS) GetItemsPartially

func (c *CMS) GetItemsPartially(ctx context.Context, modelID string, page, perPage int, asset bool) (*Items, error)

func (*CMS) GetItemsPartiallyByKey

func (c *CMS) GetItemsPartiallyByKey(ctx context.Context, projectIDOrAlias, modelIDOrAlias string, page, perPage int, asset bool) (*Items, error)

func (*CMS) GetModel

func (c *CMS) GetModel(ctx context.Context, modelID string) (*Model, error)

func (*CMS) GetModelByKey

func (c *CMS) GetModelByKey(ctx context.Context, projectKey, modelKey string) (*Model, error)

func (*CMS) GetModels

func (c *CMS) GetModels(ctx context.Context, projectIDOrAlias string) (models *Models, _ error)

func (*CMS) GetModelsInParallel

func (c *CMS) GetModelsInParallel(ctx context.Context, modelID string, limit int) (*Models, error)

func (*CMS) GetModelsPartially

func (c *CMS) GetModelsPartially(ctx context.Context, projectIDOrAlias string, page, perPage int) (*Models, error)

func (*CMS) UpdateItem

func (c *CMS) UpdateItem(ctx context.Context, itemID string, fields []*Field, metadataFields []*Field) (*Item, error)

func (*CMS) UploadAsset

func (c *CMS) UploadAsset(ctx context.Context, projectID, url string) (string, error)

func (*CMS) UploadAssetDirectly

func (c *CMS) UploadAssetDirectly(ctx context.Context, projectID, name string, data io.Reader) (string, error)

func (*CMS) UploadToAssetUpload

func (c *CMS) UploadToAssetUpload(ctx context.Context, upload *AssetUpload, data io.Reader) error

func (*CMS) WithHTTPClient

func (c *CMS) WithHTTPClient(hc *http.Client) *CMS

func (*CMS) WithTimeout

func (c *CMS) WithTimeout(t time.Duration) *CMS

type Field

type Field struct {
	ID    string `json:"id,omitempty"`
	Key   string `json:"key,omitempty"`
	Group string `json:"group,omitempty"`
	Type  string `json:"type"`
	Value any    `json:"value"`
}

func (*Field) Clone

func (f *Field) Clone() *Field

func (*Field) GetValue

func (f *Field) GetValue() *Value

type FieldChange

type FieldChange struct {
	ID            string          `json:"id,omitempty"`
	Type          FieldChangeType `json:"type"`
	PreviousValue any             `json:"previousValue"`
	CurrentValue  any             `json:"currentValue"`
}

func (*FieldChange) GetCurrentValue

func (f *FieldChange) GetCurrentValue() *Value

func (*FieldChange) GetPreviousValue

func (f *FieldChange) GetPreviousValue() *Value

type FieldChangeType

type FieldChangeType string
const (
	FieldChangeTypeCreate FieldChangeType = "add"
	FieldChangeTypeUpdate FieldChangeType = "update"
	FieldChangeTypeDelete FieldChangeType = "delete"
)

type File

type File struct {
	Name        string `json:"name"`
	Size        int    `json:"size"`
	ContentType string `json:"contentType"`
	Path        string `json:"path"`
	Children    []File `json:"children"`
}

func (File) Paths

func (f File) Paths() []string

type Interface

type Interface interface {
	GetModel(ctx context.Context, modelID string) (*Model, error)
	GetModelByKey(ctx context.Context, proejctID, modelID string) (*Model, error)
	GetModelsPartially(ctx context.Context, projectIDOrAlias string, page, perPage int) (*Models, error)
	GetModelsInParallel(ctx context.Context, modelID string, limit int) (*Models, error)
	GetModels(ctx context.Context, projectIDOrAlias string) (*Models, error)
	GetItem(ctx context.Context, itemID string, asset bool) (*Item, error)
	GetItemsPartially(ctx context.Context, modelID string, page, perPage int, asset bool) (*Items, error)
	GetItems(ctx context.Context, modelID string, asset bool) (*Items, error)
	GetItemsInParallel(ctx context.Context, modelID string, asset bool, limit int) (*Items, error)
	GetItemsPartiallyByKey(ctx context.Context, projectIDOrAlias, modelIDOrKey string, page, perPage int, asset bool) (*Items, error)
	GetItemsByKey(ctx context.Context, projectIDOrAlias, modelIDOrKey string, asset bool) (*Items, error)
	GetItemsByKeyInParallel(ctx context.Context, projectIDOrAlias, modelIDOrKey string, asset bool, limit int) (*Items, error)
	CreateItem(ctx context.Context, modelID string, fields []*Field, metadataFields []*Field) (*Item, error)
	CreateItemByKey(ctx context.Context, projectID, modelID string, fields []*Field, metadataFields []*Field) (*Item, error)
	UpdateItem(ctx context.Context, itemID string, fields []*Field, metadataFields []*Field) (*Item, error)
	DeleteItem(ctx context.Context, itemID string) error
	Asset(ctx context.Context, id string) (*Asset, error)
	UploadAsset(ctx context.Context, projectID, url string) (string, error)
	UploadAssetDirectly(ctx context.Context, projectID, name string, data io.Reader) (string, error)
	UploadToAssetUpload(ctx context.Context, upload *AssetUpload, data io.Reader) error
	CreateAssetByToken(ctx context.Context, projectID, token string) (*Asset, error)
	CreateAssetUpload(ctx context.Context, projectID, name string) (*AssetUpload, error)
	CommentToItem(ctx context.Context, assetID, content string) error
	CommentToAsset(ctx context.Context, assetID, content string) error
}

type Item

type Item struct {
	ID              string   `json:"id"`
	ModelID         string   `json:"modelId"`
	Fields          []*Field `json:"fields"`
	MetadataFields  []*Field `json:"metadataFields,omitempty"`
	ReferencedItems []*Item  `json:"referencedItems,omitempty"`
	OriginalItemID  *string  `json:"originalItemId,omitempty"`
	MetadataItemID  *string  `json:"metadataItemId,omitempty"`
	IsMetadata      bool     `json:"isMetadata,omitempty"`
}

func (*Item) Clone

func (i *Item) Clone() *Item

func (*Item) Field

func (i *Item) Field(id string) *Field

func (*Item) FieldByGroup

func (i *Item) FieldByGroup(id, group string) *Field

func (*Item) FieldByKey

func (i *Item) FieldByKey(key string) *Field

func (*Item) FieldByKeyAndGroup

func (i *Item) FieldByKeyAndGroup(key, group string) *Field

func (*Item) Group

func (i *Item) Group(g string) *Item

func (*Item) MetadataField

func (i *Item) MetadataField(id string) *Field

func (*Item) MetadataFieldByGroup

func (i *Item) MetadataFieldByGroup(id, group string) *Field

func (*Item) MetadataFieldByKey

func (i *Item) MetadataFieldByKey(key string) *Field

func (*Item) MetadataFieldByKeyAndGroup

func (i *Item) MetadataFieldByKeyAndGroup(key, group string) *Field

func (*Item) Unmarshal

func (d *Item) Unmarshal(i any)

type Items

type Items struct {
	Items      []Item `json:"items"`
	Page       int    `json:"page"`
	PerPage    int    `json:"perPage"`
	TotalCount int    `json:"totalCount"`
}

func (Items) HasNext

func (r Items) HasNext() bool

type MarshalCMS

type MarshalCMS interface {
	MarshalCMS() any
}

type Model

type Model struct {
	ID               string    `json:"id,omitempty"`
	Name             string    `json:"name,omitempty"`
	Key              string    `json:"key,omitempty"`
	Public           bool      `json:"public,omitempty"`
	ProjectID        string    `json:"projectId,omitempty"`
	SchemaID         string    `json:"schemaId,omitempty"`
	MetadataSchemaID string    `json:"metadataSchemaId,omitempty"`
	CreatedAt        time.Time `json:"createdAt,omitempty"`
	UpdatedAt        time.Time `json:"updatedAt,omitempty"`
	LastModified     time.Time `json:"lastModified,omitempty"`
}

type Models

type Models struct {
	Models     []Model `json:"models"`
	Page       int     `json:"page"`
	PerPage    int     `json:"perPage"`
	TotalCount int     `json:"totalCount"`
}

func (Models) HasNext

func (r Models) HasNext() bool

type PublicAPIClient

type PublicAPIClient[T any] struct {
	// contains filtered or unexported fields
}

func ChangePublicAPIClientType

func ChangePublicAPIClientType[T, K any](c *PublicAPIClient[T]) *PublicAPIClient[K]

func NewPublicAPIClient

func NewPublicAPIClient[T any](c *http.Client, base string) (*PublicAPIClient[T], error)

func (*PublicAPIClient[T]) Clone

func (c *PublicAPIClient[T]) Clone() *PublicAPIClient[T]

func (*PublicAPIClient[T]) GetAllItems

func (c *PublicAPIClient[T]) GetAllItems(ctx context.Context, project, model string) (res []T, err error)

func (*PublicAPIClient[T]) GetAllItemsInParallel

func (c *PublicAPIClient[T]) GetAllItemsInParallel(ctx context.Context, project, model string, limit int) ([]T, error)

func (*PublicAPIClient[T]) GetAsset

func (c *PublicAPIClient[T]) GetAsset(ctx context.Context, project, id string) (*PublicAsset, error)

func (*PublicAPIClient[T]) GetItem

func (c *PublicAPIClient[T]) GetItem(ctx context.Context, project, model string, id string) (T, error)

func (*PublicAPIClient[T]) GetItems

func (c *PublicAPIClient[T]) GetItems(ctx context.Context, project, model string, page, perPage int) (_ *PublicAPIListResponse[T], err error)

func (*PublicAPIClient[T]) WithTimeout

func (c *PublicAPIClient[T]) WithTimeout(t time.Duration) *PublicAPIClient[T]

type PublicAPIListResponse

type PublicAPIListResponse[T any] struct {
	Results    []T `json:"results"`
	PerPage    int `json:"perPage"`
	Page       int `json:"page"`
	TotalCount int `json:"totalCount"`
}

func (PublicAPIListResponse[T]) HasNext

func (r PublicAPIListResponse[T]) HasNext() bool

type PublicAsset

type PublicAsset struct {
	Type  string   `json:"type,omitempty"`
	Files []string `json:"files,omitempty"`
	Asset
}

func PublicAssetFrom

func PublicAssetFrom(a any) *PublicAsset

func (PublicAsset) IsExtractionDone

func (a PublicAsset) IsExtractionDone() bool

type Schema

type Schema struct {
	ID        string        `json:"id"`
	Fields    []SchemaField `json:"fields"`
	ProjectID string        `json:"projectId"`
	Meta      *Schema       `json:"meta"`
}

func (Schema) FieldIDByKey

func (d Schema) FieldIDByKey(k string) string

type SchemaField

type SchemaField struct {
	ID   string `json:"id"`
	Type string `json:"type"`
	Key  string `json:"key"`
}

type Tag

type Tag struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

func TagFrom

func TagFrom(j any) *Tag

func TagsFrom

func TagsFrom(j any) []Tag

func (*Tag) MarshalCMS

func (t *Tag) MarshalCMS() any

type Value

type Value struct {
	// contains filtered or unexported fields
}

func NewValue

func NewValue(value any) *Value

func (*Value) Asset

func (v *Value) Asset() *PublicAsset

func (*Value) AssetID

func (v *Value) AssetID() string

func (*Value) AssetURL

func (v *Value) AssetURL() string

func (*Value) Bool

func (v *Value) Bool() *bool

func (*Value) Bools

func (v *Value) Bools() []bool

func (*Value) Float

func (v *Value) Float() *float64

func (*Value) Floats

func (v *Value) Floats() []float64

func (*Value) Int

func (v *Value) Int() *int

func (*Value) Interface

func (v *Value) Interface() any

func (*Value) Ints

func (v *Value) Ints() []int

func (*Value) JSON

func (f *Value) JSON(j any) error

func (*Value) JSONs

func (f *Value) JSONs(j any) error

func (*Value) MarshalCMS

func (v *Value) MarshalCMS() any

func (*Value) MarshalJSON

func (v *Value) MarshalJSON() ([]byte, error)

func (*Value) String

func (v *Value) String() *string

func (*Value) Strings

func (v *Value) Strings() []string

func (*Value) Tag

func (v *Value) Tag() *Tag

func (*Value) Tags

func (v *Value) Tags() []Tag

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(b []byte) error

Directories

Path Synopsis
cmd
Package cmaoapi provides primitives to interact with the openapi HTTP API.
Package cmaoapi provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL