|
| 1 | +/** |
| 2 | + * Copyright 2015 Workfront |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * Logs in, then uploads an image and attaches it to a task |
| 19 | + */ |
| 20 | + |
| 21 | +var ApiFactory = require('./../../').ApiFactory; |
| 22 | +var util = require('util'); |
| 23 | +var fs = require('fs'); |
| 24 | + |
| 25 | +var stream = fs.createReadStream('./image.jpg'); |
| 26 | + |
| 27 | +var instance = ApiFactory.getInstance({ |
| 28 | + url: 'http://localhost:8080', |
| 29 | + version: '4.0' |
| 30 | +}); |
| 31 | + |
| 32 | +util.log('Logging in ...'); |
| 33 | +instance.login('admin@user.attask', 'user').then( |
| 34 | + function() { |
| 35 | + util.log('Uploading a sweet picture...'); |
| 36 | + instance.upload(stream, {filename: 'sweet.jpg', contentType: 'image/jpeg'}).then( |
| 37 | + function(data) { |
| 38 | + util.log('Upload success. Received data:'); |
| 39 | + console.log(util.inspect(data, {colors:true})); |
| 40 | + |
| 41 | + instance.create('DOCU', { |
| 42 | + name: 'sweet.jpg', |
| 43 | + handle: data.handle, |
| 44 | + docObjCode: 'TASK', |
| 45 | + |
| 46 | + //Obviously this will only work with a real TASK ID |
| 47 | + objID: '561ffe36000006ee9f8453a6c921d636' |
| 48 | + }).then( |
| 49 | + function(data) { |
| 50 | + util.log('Document creation success. Received data:'); |
| 51 | + console.log(util.inspect(data, {colors:true})); |
| 52 | + }, |
| 53 | + function(error) { |
| 54 | + util.log('Document creation failure. Received data:'); |
| 55 | + console.log(util.inspect(error, {colors:true})); |
| 56 | + } |
| 57 | + ); |
| 58 | + }, |
| 59 | + function(error) { |
| 60 | + util.log('Upload failure. Received data:'); |
| 61 | + console.log(util.inspect(error, {colors:true})); |
| 62 | + } |
| 63 | + ); |
| 64 | + }, |
| 65 | + function(error) { |
| 66 | + util.log('Login failure. Received data:'); |
| 67 | + console.log(util.inspect(error, {colors:true})); |
| 68 | + } |
| 69 | +); |
0 commit comments