cloudinary

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: MIT Imports: 18 Imported by: 0

README

go-cloudinary

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type AdminResponse

type AdminResponse struct {
	Deleted interface{} `json:"deleted"`
	Partial bool        `json:"partial"`
}

func (*AdminResponse) ToJSON

func (ar *AdminResponse) ToJSON() string

type AdminService

type AdminService service

func (*AdminService) DeleteAllResources

func (as *AdminService) DeleteAllResources(opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

func (*AdminService) DeleteDerivedResources

func (as *AdminService) DeleteDerivedResources(derivedResourceIds string, opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

func (*AdminService) DeleteDerivedResourcesByTransformation

func (as *AdminService) DeleteDerivedResourcesByTransformation(publicId, transformation []string, opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

func (*AdminService) DeleteResources

func (as *AdminService) DeleteResources(ctx context.Context, publicIds []string, opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

DeleteResource deletes all resources with the given publicIds publicIds is a array that store up to 100 ids

Documentation: https://cloudinary.com/documentation/admin_api#delete_all_or_selected_resources

func (*AdminService) DeleteResourcesByPrefix

func (as *AdminService) DeleteResourcesByPrefix(ctx context.Context, prefix string, opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

DeleteResource deletes all resources, including derived resources, where the publicId starts with the given prefix (up to maximum of 1000 original resources)

func (*AdminService) DeleteResourcesByTag

func (as *AdminService) DeleteResourcesByTag(ctx context.Context, tag string, opts ...SetOpts) (ar *AdminResponse, resp *Response, err error)

DeleteResourcesByTag deletes all resources and their derivatives with the given tag name, up to a maximum of 1000 original resources

type Client

type Client struct {

	// BaseURL for the API request. It should always be specified with a trailing slash
	BaseURL *url.URL

	// Services used for talking to different parts of the Cloudinary API
	Upload *UploadService
	Admin  *AdminService
	// contains filtered or unexported fields
}

A Client manages communication with the Cloudinary API

func NewClient

func NewClient(httpClient *http.Client, uri string) (*Client, error)

The uri parameter must be a valid URI with the cloudinary:// scheme, e.g. cloudinary://api_key:api_secret@cloud_name

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.

The provided ctx must be non-nil. 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 create 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.

func (*Client) NewUploadRequest

func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, writer *multipart.Writer) (*http.Request, error)

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	ErrorData struct {
		Message string `json:"message"`
	} `json:"error"`

	// Errors can also include a documentation_url field
	// pointing to some content that might help you resolve the error
	DocumentationURL string `json:"documentation_url,omitempty"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Options

type Options struct {
	//AccessControl           interface{} `json:"access_control,omitempty"`
	AccessMode     *string  `json:"access_mode,omitempty"`
	AllowedFormats *string  `json:"allowed_formats,omitempty"`
	Async          *bool    `json:"async,omitempty"`
	AutoTagging    *float64 `json:"auto_tagging,omitempty"`

	BackgroundRemoval *string `json:"background_removal,omitempty"`
	Backup            *bool   `json:"backup,omitempty"`

	Callback          *string `json:"callback,omitempty"`
	Categorization    *string `json:"categorization,omitempty"`
	Colors            *bool   `json:"colors,omitempty"`
	Context           *string `json:"context,omitempty"`
	CustomCoordinates *string `json:"custom_coordinates,omitempty"`

	Detection               *string `json:"detection,omitempty"`
	DiscardOriginalFilename *bool   `json:"discard_original_filename,omitempty"`

	Eager                *string `json:"eager,omitempty"`
	EagerAsync           *bool   `json:"eager_async,omitempty"`
	EagerNotificationURL *string `json:"eager_notification_url,omitempty"`
	Exif                 *bool   `json:"exif,omitempty"`

	FaceCoordinates *string `json:"face_coordinates,omitempty"`
	Faces           *bool   `json:"faces,omitempty"`
	Folder          *string `json:"folder,omitempty"`
	Format          *string `json:"format,omitempty"`

	Headers *string `json:"headers,omitempty"`

	ImageMetadata *bool `json:"image_metadata,omitempty"`
	Invalidate    *bool `json:"invalidate,omitempty"`

	KeepOriginal *bool `json:"keep_original,omitempty"`

	Moderation *string `json:"moderation,omitempty"`

	NextCursor      *string `json:"next_cursor,omitempty"`
	NotificationURL *string `json:"notification_url,omitempty"`

	OCR       *string `json:"ocr,omitempty"`
	Overwrite *bool   `json:"overwrite,omitempty"`

	Phash    *bool   `json:"phash,omitempty"`
	Proxy    *string `json:"proxy,omitempty"`
	PublicId *string `json:"public_id,omitempty"`

	QualityAnalysis *bool `json:"quality_analysis,omitempty"`

	RawConvert        *string `json:"raw_convert,omitempty"`
	ReturnDeleteToken *bool   `json:"return_delete_token,omitempty"`
	ResourceType      *string `json:"resource_type,omitempty"`

	Tags            *string `json:"tags,omitempty"`
	Timestamp       *string `json:"timestamp,omitempty"`
	Transformations *string `json:"transformation,omitempty"`
	Type            *string `json:"type,omitempty"`

	UniqueFilename *bool `json:"unique_filename,omitempty"`
	// Upload Preset is required for unsigned uploading and
	// optional for signed uploading
	UploadPreset *string `json:"upload_preset,omitempty"`
	UseFilename  *bool   `json:"use_filename,omitempty"`
	// contains filtered or unexported fields
}

func (*Options) GetInvalidate

func (o *Options) GetInvalidate() bool

func (*Options) GetKeepOriginal

func (o *Options) GetKeepOriginal() bool

func (*Options) GetNextCursor

func (o *Options) GetNextCursor() string

func (*Options) GetPublicId

func (o *Options) GetPublicId() string

func (*Options) GetResourceType

func (o *Options) GetResourceType() string

func (*Options) GetTimestamp

func (o *Options) GetTimestamp() string

func (*Options) GetType

func (o *Options) GetType() string

func (*Options) GetUploadPreset

func (o *Options) GetUploadPreset() string

type ResourceType

type ResourceType string

type Response

type Response struct {
	*http.Response
}

Response is a Cloudinary API response.

type SetOpts

type SetOpts func(opts *Options)

func WithAccessMode

func WithAccessMode(accessMode string) SetOpts

func WithAutoTagging

func WithAutoTagging(autoTagging float64) SetOpts

func WithCategorization

func WithCategorization(c string) SetOpts

func WithColors

func WithColors(hasColor bool) SetOpts

func WithContext

func WithContext(ctx string) SetOpts

func WithDetection

func WithDetection(d string) SetOpts

func WithDiscardOriginalFilename

func WithDiscardOriginalFilename(dof bool) SetOpts

func WithExif

func WithExif(e bool) SetOpts

func WithFaces

func WithFaces(returnFaces bool) SetOpts

func WithFolder

func WithFolder(folder string) SetOpts

func WithImageMetadata

func WithImageMetadata(returnImageMetadata bool) SetOpts

func WithKeepOriginal

func WithKeepOriginal(ko bool) SetOpts

func WithOCR

func WithOCR(ocr string) SetOpts

func WithOverwrite

func WithOverwrite(isOverwrite bool) SetOpts

func WithPhash

func WithPhash(returnPhash bool) SetOpts

func WithPublicId

func WithPublicId(id string) SetOpts

func WithQualityAnalysis

func WithQualityAnalysis(returnQualityAnalysis bool) SetOpts

func WithResourceType

func WithResourceType(resourceType string) SetOpts

func WithTags

func WithTags(tags string) SetOpts

func WithType

func WithType(typeStr string) SetOpts

func WithUniqueFilename

func WithUniqueFilename(isUniqueFilename bool) SetOpts

func WithUploadPreset

func WithUploadPreset(uploadPreset string) SetOpts

func WithUseFilename

func WithUseFilename(isUseFilename bool) SetOpts

type UploadRequest

type UploadRequest struct {
	// Required fields to call upload request
	File string `json:"file"`
}

type UploadResponse

type UploadResponse struct {
	PublicId         string          `json:"public_id"`
	Version          int64           `json:"version"`
	Signature        string          `json:"signature"`
	Width            int64           `json:"width"`
	Height           int64           `json:"height"`
	Format           string          `json:"format"`
	ResourceType     string          `json:"resource_type"`
	CreatedAt        string          `json:"created_at"`
	Tags             []string        `json:"tags"`
	Bytes            int64           `json:"bytes"`
	Type             string          `json:"type"`
	Etag             string          `json:"etag"`
	Placeholder      bool            `json:"placeholder"`
	URL              string          `json:"url"`
	SecureURL        string          `json:"secure_url"`
	AccessMode       string          `json:"access_mode"`
	OriginalFilename string          `json:"original_filename"`
	Colors           [][]interface{} `json:"colors"`
}

type UploadService

type UploadService service

func (*UploadService) UnsignedUploadImage

func (us *UploadService) UnsignedUploadImage(ctx context.Context, filePath string, uploadPreset string, opts ...SetOpts) (ur *UploadResponse, r *Response, err error)

UnsignedUploadImage handle unsigned uploading image to Cloudinary. Unsigned request are restricted to the following allowed parameters: `public_id`, `folder`, `callback`, `tags`, `context`, `face_coordinates` (image-only), `custom_coordinates` (image-only) and `upload_preset`. Most of the other upload parameters can be defined in your `upload_preset`.

Additionally, although the `public_id` parameter can be specified, the `overwrite` parameter is always set to `false` for unsigned uploads to prevent overwriting existing file.

func (*UploadService) UploadImage

func (us *UploadService) UploadImage(ctx context.Context, filePath string, opts ...SetOpts) (ur *UploadResponse, r *Response, err error)

UploadImage handle signed uploading image to Cloudinary Signed request are required `signature` parameters

Jump to

Keyboard shortcuts

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