webflow

package
v0.0.0-...-801cc09 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

Types

type Client

type Client struct {

	// Base URL for API requests. Defaults to the public Webflow API, but can be
	// set to a domain endpoint to use with Webflow Enterprise. BaseURL should
	// always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the Webflow API.
	UserAgent string

	// Services used for talking to different parts of the Webflow API.
	//TODO: Add services
	Meta        *MetaService
	Sites       *SitesService
	Domains     *DomainsService
	Collections *CollectionsService
	Items       *ItemsService
	Ecommerce   *EcommerceService
	Webhooks    *WebhooksService
	// contains filtered or unexported fields
}

A Client manages communication with the Webflow API.

func NewClient

func NewClient(token string) *Client

func (*Client) BareDo

func (c *Client) BareDo(ctx context.Context, req *http.Request) (*Response, error)

BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body. If rate limit is exceeded and reset time is in the future, BareDo returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns the http.Client used by this Webflow client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error happens, the response is returned as is. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type Collection

type Collection struct {
	Id           string        `json:"_id"`
	LastUpdated  time.Time     `json:"lastUpdated"`
	CreatedOn    time.Time     `json:"createdOn"`
	Name         string        `json:"name"`
	Slug         string        `json:"slug"`
	SingularName string        `json:"singularName"`
	Fields       []interface{} `json:"fields"`
}

Collection models a Webflow API collection ref: https://developers.webflow.com/#model16

type CollectionsService

type CollectionsService service

CollectionsService handles communication with the collections related methods of the Webflow API.

ref: https://developers.webflow.com/#collections

func (*CollectionsService) GetCollection

func (s *CollectionsService) GetCollection(ctx context.Context, collectionId string) (*Collection, error)

GetCollection retrieves the specified collection ref: https://developers.webflow.com/#get-collection-with-full-schema

func (*CollectionsService) ListCollections

func (s *CollectionsService) ListCollections(ctx context.Context, site string, opts *ListCollectionsOptions) ([]*Collection, error)

ListCollections lists all the collections for the given site ref: https://developers.webflow.com/#list-collections

type DeleteItemResponse

type DeleteItemResponse struct {
	Deleted int `json:"deleted"`
}

type Domain

type Domain struct {
	Id   string `json:"_id"`
	Name string `json:"name"`
}

type DomainsService

type DomainsService service

DomainsService handles communication with the meta related methods of the Webflow API.

ref: https://developers.webflow.com/#domains

func (*DomainsService) ListDomains

func (s *DomainsService) ListDomains(ctx context.Context, site string, opts *ListDomainsOptions) ([]*Domain, error)

ListDomains lists of all domains for the provided site. ref: https://developers.webflow.com/#list-domains

type EcommerceService

type EcommerceService service

EcommerceService handles communication with the ecommerce related methods of the Webflow API.

ref: https://developers.webflow.com/#ecommerce

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Msg      string         `json:"msg"`
	Code     int            `json:"code"`
	Name     string         `json:"name"`
	Path     string         `json:"path"`
	Err      string         `json:"err"`
}

An ErrorResponse reports one or more errors caused by an API request. Webflow API docs: https://developers.webflow.com/?shell#errors

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Field

type Field struct {
	Validations struct {
		SingleLine    bool          `json:"singleLine,omitempty"`
		MaxLength     int           `json:"maxLength,omitempty"`
		MinLength     int           `json:"minLength,omitempty"`
		Minimum       int           `json:"minimum,omitempty"`
		Maximum       int           `json:"maximum,omitempty"`
		MaxSize       int           `json:"maxSize,omitempty"`
		DecimalPlaces int           `json:"decimalPlaces,omitempty"`
		Options       []interface{} `json:"options,omitempty"`
		Format        string        `json:"format,omitempty"`
		Precision     int           `json:"precision,omitempty"`
		AllowNegative bool          `json:"allowNegative,omitempty"`
		CollectionId  string        `json:"collectionId,omitempty"`
	} `json:"validations"`
	Id       string `json:"id"`
	Editable bool   `json:"editable"`
	Required bool   `json:"required"`
	Type     string `json:"type"`
	Slug     string `json:"slug"`
	Name     string `json:"name"`
}

Field models a Webflow API field ref: https://developers.webflow.com/#fields

type Item

type Item map[string]interface{}

Item is a dynamic object. Its fields depend on the fields a user creates for a collection ref: https://developers.webflow.com/#item-model

type ItemResponse

type ItemResponse struct {
	Items []Item
	PageInfo
}

ItemResponse models a response returned by the Items Webflow API

type ItemsService

type ItemsService service

ItemsService handles communication with the items related methods of the Webflow API.

ref: https://developers.webflow.com/#items

func (*ItemsService) CreateItem

func (s *ItemsService) CreateItem(ctx context.Context, collectionId string, item Item) (Item, error)

CreateItem creates a new item inside the given collection ref: https://developers.webflow.com/#create-new-collection-item

func (*ItemsService) CreateItemLive

func (s *ItemsService) CreateItemLive(ctx context.Context, collectionId string, item Item) (Item, error)

CreateItemLive creates a new item inside the given collection and publish it ref: https://developers.webflow.com/#create-new-live-collection-item

func (*ItemsService) DeleteItem

func (s *ItemsService) DeleteItem(ctx context.Context, collectionId string, itemId string) (*DeleteItemResponse, error)

func (*ItemsService) GetItem

func (s *ItemsService) GetItem(ctx context.Context, collectionId string, itemId string) (*ItemResponse, error)

GetItem retrieves the specified item ref: https://developers.webflow.com/#get-single-item

func (*ItemsService) ListItems

func (s *ItemsService) ListItems(ctx context.Context, collectionId string, opts *ListItemsOptions) (*ItemResponse, error)

ListItems lists all the items of the given collection ref: https://developers.webflow.com/#get-all-items-for-a-collection

func (*ItemsService) PatchItem

func (s *ItemsService) PatchItem(ctx context.Context, collectionId string, itemId string, item Item) (Item, error)

PatchItem updates the selected fields of the given item ref: https://developers.webflow.com/#patch-collection-item

func (*ItemsService) PatchItemLive

func (s *ItemsService) PatchItemLive(ctx context.Context, collectionId string, itemId string, item Item) (Item, error)

PatchItemLive updates the selected fields of the given item and publishes the changes ref: https://developers.webflow.com/#patch-live-collection-item

func (*ItemsService) UpdateItem

func (s *ItemsService) UpdateItem(ctx context.Context, collectionId string, itemId string, item Item) (Item, error)

UpdateItem updates (replaces) the collection item with the given fields ref: https://developers.webflow.com/#update-collection-item

func (*ItemsService) UpdateItemLive

func (s *ItemsService) UpdateItemLive(ctx context.Context, collectionId string, itemId string, item Item) (Item, error)

UpdateItemLive updates (replaces) the collection item with the given fields and publishes the changes ref: https://developers.webflow.com/#update-live-collection-item

type ListCollectionsOptions

type ListCollectionsOptions struct {
	ListOptions
}

type ListDomainsOptions

type ListDomainsOptions struct {
	ListOptions
}

type ListItemsOptions

type ListItemsOptions struct {
	ListOptions
}

ListItemsOptions defines the available list options

type ListOptions

type ListOptions struct {
	// Maximum number of Items to be returned (max limit: 100)
	Limit int `url:"limit,omitempty"`

	// 	Offset used for pagination if collection has more than limit items
	Offset int `url:"offset,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support offset pagination.

type ListSitesOptions

type ListSitesOptions struct {
	ListOptions
}

type MetaService

type MetaService service

MetaService handles communication with the meta related methods of the Webflow API.

Webflow API docs: https://developers.webflow.com/#meta

func (*MetaService) GetCurrentAuthorizationInfo

func (s *MetaService) GetCurrentAuthorizationInfo(ctx context.Context) (interface{}, error)

func (*MetaService) GetCurrentAuthorizedUser

func (s *MetaService) GetCurrentAuthorizedUser(ctx context.Context) (interface{}, error)

type PageInfo

type PageInfo struct {
	Count  int `json:"count,omitempty"`
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`
	Total  int `json:"total,omitempty"`
}

PageInfo holds the pagination information for a Webflow API request

type PublishSiteResponse

type PublishSiteResponse struct {
	Queued bool `json:"queued"`
}

type Rate

type Rate struct {
	// The number of requests per hour the client is currently limited to.
	Limit int `json:"limit"`

	// The number of remaining requests the client can make this hour.
	Remaining int `json:"remaining"`

	// The time at which the current rate limit will reset.
	Reset time.Time `json:"reset"`
}

Rate represents the rate limit for the current client.

type RateLimitError

type RateLimitError struct {
	Rate     Rate           // Rate specifies last known rate limit for the client
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"message"` // error message
}

RateLimitError occurs when Webflow returns 403 Forbidden response with a rate limit remaining value of 0.

func (*RateLimitError) Error

func (r *RateLimitError) Error() string

func (*RateLimitError) Is

func (r *RateLimitError) Is(target error) bool

Is returns whether the provided error equals this error.

type Response

type Response struct {
	*http.Response

	// These fields provide the page values for paginating through a set of
	// results. Any or all of these may be set to the zero value for
	// responses that are not part of a paginated set, or for which there
	// are no additional pages.
	//
	// These fields support what is called "offset pagination" and should
	// be used with the ListOptions struct.
	NextPage  int
	PrevPage  int
	FirstPage int
	LastPage  int

	// Explicitly specify the Rate type so Rate's String() receiver doesn't
	// propagate to Response.
	Rate Rate

	// token's expiration date
	TokenExpiration time.Time
}

Response is a Webflow API response. This wraps the standard http.Response returned from Webflow and provides convenient access to things like pagination links.

type Site

type Site struct {
	Id            string    `json:"_id"`
	CreatedOn     time.Time `json:"createdOn"`
	Name          string    `json:"name"`
	ShortName     string    `json:"shortName"`
	LastPublished time.Time `json:"lastPublished"`
	PreviewUrl    string    `json:"previewUrl"`
	Timezone      string    `json:"timezone"`
	Database      string    `json:"database"`
}

Site models a Webflow API site ref: https://developers.webflow.com/#model

type SitesService

type SitesService service

SitesService handles communication with the meta related methods of the Webflow API.

ref: https://developers.webflow.com/#sites

func (*SitesService) GetSite

func (s *SitesService) GetSite(ctx context.Context, siteId string) (*Site, error)

GetSite retrieves the specified site ref: https://developers.webflow.com/#get-specific-site

func (*SitesService) ListSites

func (s *SitesService) ListSites(ctx context.Context, opts *ListSitesOptions) ([]*Site, error)

ListSites lists of all sites the provided access token is able to access. ref: https://developers.webflow.com/#list-sites

func (*SitesService) PublishSite

func (s *SitesService) PublishSite(ctx context.Context, siteId string, domains []string) (*PublishSiteResponse, error)

PublishSite publishes a new site ref: https://developers.webflow.com/#publish-site

type WebhooksService

type WebhooksService service

WebhooksService handles communication with the webhooks related methods of the Webflow API.

ref: https://developers.webflow.com/#webhooks

Jump to

Keyboard shortcuts

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