github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/sdk/loaddata.go (about) 1 // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved. 2 // 3 // This software (Documize Community Edition) is licensed under 4 // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html 5 // 6 // You can operate outside the AGPL restrictions by purchasing 7 // Documize Enterprise Edition and obtaining a commercial license 8 // by contacting <sales@documize.com>. 9 // 10 // https://documize.com 11 12 package documize 13 14 import ( 15 "bytes" 16 "encoding/json" 17 "errors" 18 "strings" 19 20 "github.com/documize/community/wordsmith/api" 21 "github.com/documize/community/documize/api/entity" 22 ) 23 24 // LoadData uploads and converts the raw data comprising a Documize document into Documize, returning a fileID and error. 25 func (c *Client) LoadData(folderID, docName string, docData *api.DocumentConversionResponse) (*entity.Document, error) { 26 if len(docData.PagesHTML) == 0 && len(docData.Pages) == 0 { 27 return nil, errors.New("no data to load") // NOTE attachements must have a base document 28 } 29 for _, att := range docData.EmbeddedFiles { 30 if !strings.HasSuffix(strings.ToLower(att.Name), "."+strings.ToLower(att.Type)) { 31 return nil, errors.New("attachment " + att.Name + " does not have the extention " + att.Type) 32 } 33 } 34 buf, err := json.Marshal(*docData) 35 if err != nil { 36 return nil, err 37 } 38 cv, err := c.upload(folderID, docName+".documizeapi", bytes.NewReader(buf)) 39 if err != nil { 40 return nil, err 41 } 42 //cv, err := c.convert(folderID, job, nil) 43 //if err != nil { 44 // return nil, err 45 //} 46 return cv, nil 47 }