transloadit

package
v0.0.0-...-bd14a5d Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2016 License: MIT, MIT Imports: 23 Imported by: 0

README

Build Status Coverage Status

go-sdk

A Go SDK to make it easy to talk to the Transloadit REST API.

We also offer transloadify that bundles much of the technology inside this SDK as a commandline utility.

Example

// Create client
options := transloadit.DefaultConfig
options.AuthKey = "TRANSLOADIT_KEY"
options.AuthSecret = "TRANSLOADIT_SECRET"
client, err := transloadit.NewClient(options)
if err != nil {
    panic(err)
}

// Initialize new assembly
assembly := client.CreateAssembly()

// Add input file to upload
assembly.AddFile("myimage", "./lol_cat.jpg")

// Add instructions, e.g. resize image to 75x75px
assembly.AddStep("resize", map[string]interface{}{
    "robot":           "/image/resize",
    "width":           75,
    "height":          75,
    "resize_strategy": "pad",
    "background":      "#000000",
})

// Wait until transloadit is done processing all uploads
// and is ready to download the results
assembly.Blocking = true

// Start the upload
info, err := assembly.Upload()
if err != nil {
    panic(err)
}

fmt.Printf("You can view the result at: %s\n", info.Results["resize"][0].Url)

For examples on how to use templates, non-blocking processing and more, take a look at examples/.

Installation

go get github.com/transloadit/go-sdk

The Go SDK requires Go 1.1 or higher.

Documentation

See Godoc.

License

MIT Licensed

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Region:   "us-east-1",
	Endpoint: "http://api2.transloadit.com",
}
View Source
var Version = "v0.1.9"

Go SDK's version

Functions

This section is empty.

Types

type Assembly

type Assembly struct {

	// Notify url to send a request to once the assembly finishes.
	// See https://transloadit.com/docs#notifications.
	NotifyUrl string
	// Optional template id to use instead of adding steps.
	TemplateId string
	// Wait until the assembly completes (or is canceled).
	Blocking bool
	// contains filtered or unexported fields
}

func (*Assembly) AddFile

func (assembly *Assembly) AddFile(field, name string) error

Add another file to upload later.

func (*Assembly) AddReader

func (assembly *Assembly) AddReader(field, name string, reader io.ReadCloser)

Add another reader to upload later.

func (*Assembly) AddStep

func (assembly *Assembly) AddStep(name string, details map[string]interface{})

Add a step to the assembly.

func (*Assembly) Upload

func (assembly *Assembly) Upload() (*AssemblyInfo, error)

Start the assembly and upload all files. When an error is returned you should also check AssemblyInfo.Error for more information about the error. This happens when there is an error returned by the Transloadit API:

info, err := assembly.Upload()
if err != nil {
	if info != nil && info.Error != "" {
		// See info.Error
	}
	panic(err)
}

type AssemblyInfo

type AssemblyInfo struct {
	AssemblyId             string                 `json:"assembly_id"`
	ParentId               string                 `json:"parent_id"`
	AssemblyUrl            string                 `json:"assembly_url"`
	AssemblySslUrl         string                 `json:"assembly_ssl_url"`
	BytesReceived          int                    `json:"bytes_received"`
	BytesExpected          int                    `json:"bytes_expected"`
	ClientAgent            string                 `json:"client_agent"`
	ClientIp               string                 `json:"client_ip"`
	ClientReferer          string                 `json:"client_referer"`
	StartDate              string                 `json:"start_date"`
	IsInfinite             bool                   `json:"is_infinite"`
	HasDupeJobs            bool                   `json:"has_dupe_jobs"`
	UploadDuration         float32                `json:"upload_duration"`
	NotifyUrl              string                 `json:"notify_url"`
	NotifyStart            string                 `json:"notify_start"`
	NotifyStatus           string                 `json:"notify_status"`
	NotifyDuation          float32                `json:"notify_duration"`
	LastJobCompleted       string                 `json:"last_job_completed"`
	ExecutionDuration      float32                `json:"execution_duration"`
	ExecutionStart         string                 `json:"execution_start"`
	Created                string                 `json:"created"`
	Ok                     string                 `json:"ok"`
	Message                string                 `json:"message"`
	Files                  string                 `json:"files"`
	Fields                 map[string]interface{} `json:"fields"`
	BytesUsage             int                    `json:"bytes_usage"`
	FilesToStoreOnS3       int                    `json:"files_to_store_on_s3"`
	QueuedFilesToStoreOnS3 int                    `json:"queued_files_to_store_on_s3"`
	ExecutingJobs          []interface{}          `json:"executing_jobs"`
	StartedJobs            []interface{}          `json:"started_jobs"`
	ParentAssemblyStatus   *AssemblyInfo          `json:"parent_assembly_status"`
	Uploads                []*FileInfo            `json:"uploads"`
	Results                map[string][]*FileInfo `json:"results"`
	Params                 string                 `json:"params"`
	Error                  string                 `json:"error"`
}

type AssemblyList

type AssemblyList struct {
	Assemblies []*AssemblyListItem `json:"items"`
	Count      int                 `json:"count"`
}

type AssemblyListItem

type AssemblyListItem struct {
	AssemblyId        string    `json:"id"`
	AccountId         string    `json:"account_id"`
	TemplateId        string    `json:"template_id"`
	Instance          string    `json:"instance"`
	NotifyUrl         string    `json:"notify_url"`
	RedirectUrl       string    `json:"redirect_url"`
	ExecutionDuration float32   `json:"execution_duration"`
	ExecutionStart    time.Time `json:"execution_start"`
	Created           time.Time `json:"created"`
	Ok                string    `json:"ok"`
	Error             string    `json:"error"`
	Files             string    `json:"files"`
}

type AssemblyReplay

type AssemblyReplay struct {

	// Notify url to send a request to once the assembly finishes.
	// See https://transloadit.com/docs#notifications.
	NotifyUrl string
	// Wait until the assembly completes (or is canceled).
	Blocking bool
	// contains filtered or unexported fields
}

func (*AssemblyReplay) AddStep

func (assembly *AssemblyReplay) AddStep(name string, details map[string]interface{})

Add a step to override the original ones.

func (*AssemblyReplay) ReparseTemplate

func (assembly *AssemblyReplay) ReparseTemplate()

Reparse the template when replaying. Useful if the template has changed since the orignal assembly was created.

func (*AssemblyReplay) Start

func (assembly *AssemblyReplay) Start() (*AssemblyInfo, error)

Start the assembly replay.

type AssemblyWatcher

type AssemblyWatcher struct {
	Response chan *AssemblyInfo
	Error    chan error
	// contains filtered or unexported fields
}

func (*AssemblyWatcher) Stop

func (watcher *AssemblyWatcher) Stop()

Stop the watcher and close all channels.

type Client

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

func NewClient

func NewClient(config Config) (*Client, error)

Create a new client using the provided configuration object. An error will be returned if no AuthKey or AuthSecret is found in config.

func (*Client) CancelAssembly

func (client *Client) CancelAssembly(assemblyUrl string) (Response, error)

Cancel an assembly using its url.

func (*Client) CreateAssembly

func (client *Client) CreateAssembly() *Assembly

Create a new assembly instance which can be executed later.

func (*Client) CreateTemplate

func (client *Client) CreateTemplate(template *Template) (string, error)

Save the template.

func (*Client) DeleteTemplate

func (client *Client) DeleteTemplate(templateId string) error

Delete a template from the list.

func (*Client) EditTemplate

func (client *Client) EditTemplate(templateId string, newTemplate *Template) error

Update the name and content of the template defined using the id.

func (*Client) GetAssembly

func (client *Client) GetAssembly(assemblyUrl string) (*AssemblyInfo, error)

Get information about an assembly using its url.

func (*Client) GetTemplate

func (client *Client) GetTemplate(templateId string) (*Template, error)

Get information about a template using its id.

func (*Client) ListAssemblies

func (client *Client) ListAssemblies(options *ListOptions) (*AssemblyList, error)

List all assemblies matching the criterias.

func (*Client) ListNotifications

func (client *Client) ListNotifications(options *ListOptions) (*NotificationList, error)

List all notificaions matching the criterias.

func (*Client) ListTemplates

func (client *Client) ListTemplates(options *ListOptions) (*TemplateList, error)

List all templates matching the criterias.

func (*Client) ReplayAssembly

func (client *Client) ReplayAssembly(assemblyId string) *AssemblyReplay

Create a new AssemblyReplay instance.

func (*Client) ReplayNotification

func (client *Client) ReplayNotification(assemblyId string, notifyUrl string) (Response, error)

Replay a notification which was trigger by assembly defined using the assemblyId. If notifyUrl is not empty it will override the original notify url.

func (*Client) WaitForAssembly

func (client *Client) WaitForAssembly(assemblyUrl string) *AssemblyWatcher

Wait until the status of an assembly is either completed, canceled or aborted.

func (*Client) Watch

func (client *Client) Watch(options *WatchOptions) *Watcher

Watch a directory for changes and convert all changes files and download the result. It will create a new assembly for each file. If the directory already contains some they are all converted. See WatchOptions for possible configuration.

type Config

type Config struct {
	AuthKey    string
	AuthSecret string
	Region     string
	Endpoint   string
}

type FileInfo

type FileInfo struct {
	Id               string                 `json:"id"`
	Name             string                 `json:"name"`
	Basename         string                 `json:"basename"`
	Ext              string                 `json:"ext"`
	Size             int                    `json:"size"`
	Mime             string                 `json:"mime"`
	Type             string                 `json:"type"`
	Field            string                 `json:"field"`
	Md5Hash          string                 `json:"md5hash"`
	OriginalMd5Hash  string                 `json:"original_md5hash"`
	OriginalId       string                 `json:"original_id"`
	OriginalBasename string                 `json:"original_basename"`
	Url              string                 `json:"url"`
	SslUrl           string                 `json:"ssl_url"`
	Meta             map[string]interface{} `json:"meta"`
}

type ListOptions

type ListOptions struct {
	Page       int        `json:"page,omitempty"`
	PageSize   int        `json:"pagesize,omitempty"`
	Sort       string     `json:"sort,omitempty"`
	Order      string     `json:"order,omitempty"`
	Fields     []string   `json:"fields,omitempty"`
	Type       string     `json:"type,omitempty"`
	Keywords   []string   `json:"keyword,omitempty"`
	AssemblyId string     `json:"assembly_id,omitempty"`
	FromDate   *time.Time `json:"fromdate,omitempty"`
	ToDate     *time.Time `json:"todate,omitempty"`
	// For internal use only!
	Auth struct {
		Key     string `json:"key"`
		Expires string `json:"expires"`
	} `json:"auth"`
}

Options when retrieving a list. Look at the documentation which properties are accepted and to see their meaining, e.g. https://transloadit.com/docs/api-docs#retrieve-assembly-list for listing assemblies.

type NotificationList

type NotificationList struct {
	Notifications []*NotificationListItem `json:"items"`
	Count         int                     `json:"count"`
}

type NotificationListItem

type NotificationListItem struct {
	Id           string    `json:"id"`
	AssemblyId   string    `json:"assembly_id"`
	AccountId    string    `json:"account_id"`
	Url          string    `json:"url"`
	ResponseCode int       `json:"response_code"`
	RespandeData string    `json:"response_data"`
	Duration     float32   `json:"duration"`
	Created      time.Time `json:"created"`
	Error        string    `json:"error"`
}

type Response

type Response map[string]interface{}

type Template

type Template struct {
	Name string `json:"name"`
	// See AddStep for simple usage.
	Steps map[string]map[string]interface{} `json:"content"`
}

func NewTemplate

func NewTemplate(name string) *Template

Creates a new template instance which can be saved to transloadit.

func (*Template) AddStep

func (template *Template) AddStep(name string, step map[string]interface{})

Add another step to the template.

type TemplateList

type TemplateList struct {
	Templates []TemplateListItem `json:"items"`
	Count     int                `json:"count"`
}

type TemplateListItem

type TemplateListItem struct {
	Id    string                 `json:"id"`
	Name  string                 `json:"name"`
	Steps map[string]interface{} `json:"json"`
}

type WatchOptions

type WatchOptions struct {
	// Directory to watch files in (only if Watch is true)
	Input string
	// Directoy to put result files in
	Output string
	// Watch the input directory or just compile files in input directory
	Watch bool
	// Template id to convert files with
	TemplateId string
	// Optional notify url for each assembly.
	NotifyUrl string
	// Instead of using templates you can define steps
	Steps map[string]map[string]interface{}
	// If true the original files will be copied in the output directoy with `-original_0_` prefix.
	// If false input files will be deleted.
	Preserve bool
	// Read template from JSON file. See exmaples for information about the format.
	TemplateFile string
	// If true file which are already in the directory won't be compiled.
	DontProcessDir bool
}

type Watcher

type Watcher struct {

	// Original options passed to Client.Watch.
	// If Input or Output are relative to the home directory
	// they will be extended (~/input -> /home/user/input)
	Options *WatchOptions

	// Listen for errors
	Error chan error
	// Listen for completed assemblies
	Done chan *AssemblyInfo
	// Listen for file changes (only if Watch == true)
	Change chan string
	// contains filtered or unexported fields
}

func (*Watcher) Stop

func (watcher *Watcher) Stop()

Stop the watcher.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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