diff --git a/assembly.go b/assembly.go index 2681f1d..5f6b5d6 100644 --- a/assembly.go +++ b/assembly.go @@ -14,12 +14,16 @@ import ( type Assembly struct { // NotifiyURL specifies a URL to which a request will be sent once the // assembly finishes. - // See https://transloadit.com/docs#notifications. + // See https://transloadit.com/docs#notifications NotifyURL string // TemplateID specifies a optional template from which the encoding // instructions will be fetched. // See https://transloadit.com/docs/#15-templates TemplateID string + // Fields specifies additional key-value pairs that can be accessed by + // Assembly Instructions to allow customizing steps on a per-assembly basis. + // See https://transloadit.com/docs/#assembly-variables + Fields map[string]interface{} steps map[string]map[string]interface{} readers []*upload @@ -139,6 +143,7 @@ type FileInfo struct { // an assembly using Client.StartAssembly. func NewAssembly() Assembly { return Assembly{ + Fields: make(map[string]interface{}), steps: make(map[string]map[string]interface{}), readers: make([]*upload, 0), } @@ -220,6 +225,10 @@ func (assembly *Assembly) makeRequest(ctx context.Context, client *Client) (*htt options["steps"] = assembly.steps } + if len(assembly.Fields) != 0 { + options["fields"] = assembly.Fields + } + if assembly.TemplateID != "" { options["template_id"] = assembly.TemplateID } diff --git a/assembly_test.go b/assembly_test.go index 3328b8c..2cc9e40 100644 --- a/assembly_test.go +++ b/assembly_test.go @@ -31,6 +31,8 @@ func TestStartAssembly_Success(t *testing.T) { }) assembly.NotifyURL = "https://example.com/" + assembly.Fields["string_test"] = "foo" + assembly.Fields["number_test"] = 100 info, err := client.StartAssembly(ctx, assembly) if err != nil { @@ -45,6 +47,15 @@ func TestStartAssembly_Success(t *testing.T) { t.Fatal("wrong notify url") } + if info.Fields["string_test"] != "foo" { + t.Fatal("wrong field string_test") + } + + fmt.Printf("%#v\n", info.Fields) + if info.Fields["number_test"] != float64(100) { + t.Fatal("wrong field number_test") + } + if len(info.Uploads) != 2 { t.Fatal("wrong number of uploads") }