transloadit

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2014 License: MIT Imports: 19 Imported by: 0

README

Build Status Coverage Status

go-sdk

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

Example

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

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

file, err := os.Open("../../fixtures/lol_cat.jpg")
if err != nil {
	panic(err)
}

// Add an io.Reader to upload
assembly.AddReader("image", "lol_cat.jpg", file)

// 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 more example, 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.

Command line interface

As a bonus we ship a commonad line tool: transloadify which provides the functionality of Client.Watch for simple watching and automated uploading and processing of files. This way you don't have to write a single line of code to get an existing folder converted, even when new files get added to it

# Use -h for more help
transloadify -h

# Upload all files from ./input and process them using the steps defined in the template with the id 'tpl123id'.
# Download the results and put them into ./output.
# Watch the input directory to automatically upload all new files.
TRANSLOADIT_KEY=abc123 \
TRANSLOADIT_SECRET=abc123efg \
./transloadify \
  -input="./input" \
  -output="./output" \
  -template="tpl123id" \
  -watch

Installation

There are multiple way to obtain the transloadify binary:

Gobuild

Use gobuild.io to select your OS and download a zipped version of the ready-to-use binary.

go get

go get github.com/transloadit/go-sdk/transloadify

# Use the binary
$GOPATH/bin/transloadify -h

Github

git clone https://github.com/transloadit/go-sdk.git
cd go-sdk
make build
./transloadify -h

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",
}

Functions

This section is empty.

Types

type Assembly

type Assembly struct {
	NotifyUrl  string
	TemplateId string
	Blocking   bool
	// contains filtered or unexported fields
}

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.

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 {
	NotifyUrl string
	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

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"`
	Auth       struct {
		Key     string `json:"key"`
		Expires string `json:"expires"`
	} `json:"auth"`
}

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:"template_name"`
	Steps map[string]map[string]interface{} `json:"template_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]map[string]interface{} `json:"json"`
}

type WatchOptions

type WatchOptions struct {
	Input      string
	Output     string
	Watch      bool
	TemplateId string
	NotifyUrl  string
	Steps      map[string]map[string]interface{}
	Preserve   bool
}

type Watcher

type Watcher struct {
	Error  chan error
	Done   chan *AssemblyInfo
	Change chan string
	// contains filtered or unexported fields
}

func (*Watcher) Stop

func (watcher *Watcher) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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