-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added attachment Tests but these aren't currently working
It seems the original author of the OAuth libraries has decided to push the content through as application/x-www-form-urlencoded which means that raw data is not being processed correctly. I need to modify the library here to implement correct content-types.
- Loading branch information
Jordan Walsh
committed
Feb 27, 2017
1 parent
86c5733
commit 16fff71
Showing
11 changed files
with
278 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
/cert | ||
/coverage | ||
.nyc_output/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,53 @@ | ||
var _ = require('lodash') | ||
, Entity = require('./entity') | ||
, logger = require('../logger') | ||
, dateformat = require('dateformat') | ||
, fs = require('fs') | ||
var _ = require('lodash'), | ||
Entity = require('./entity'), | ||
logger = require('../logger'), | ||
dateformat = require('dateformat'), | ||
fs = require('fs') | ||
|
||
var AttachmentSchema = new Entity.SchemaObject({ | ||
AttachmentID: { type: String, toObject: 'never' }, | ||
FileName: {type: String, toObject: 'always'}, | ||
Url: {type: String, toObject:'always'}, | ||
MimeType: {type: String, toObject: 'always'}, | ||
ContentLength: {type: Number, toObject:'always'} | ||
FileName: { type: String, toObject: 'always' }, | ||
Url: { type: String, toObject: 'always' }, | ||
MimeType: { type: String, toObject: 'always' }, | ||
ContentLength: { type: Number, toObject: 'always' } | ||
}); | ||
|
||
|
||
var Attachment = Entity.extend(AttachmentSchema, { | ||
constructor: function (application, data, options) | ||
{ | ||
constructor: function(application, data, options) { | ||
logger.debug('Attachment::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function (data, options) | ||
{ | ||
}, | ||
getContent:function(ownerPath) | ||
{ | ||
initialize: function(data, options) {}, | ||
getContent: function(ownerPath) { | ||
return this.application.core.attachments.getContent(ownerPath, this.FileName); | ||
}, | ||
save:function(ownerPath, streamOrFilePath) | ||
{ | ||
save: function(ownerPath, streamOrFilePath) { | ||
var self = this; | ||
var path = ownerPath + '/Attachments/' + this.FileName; | ||
var stream; | ||
if (_.isString(streamOrFilePath)) | ||
stream = fs.createReadStream(streamOrFilePath); | ||
else | ||
stream = streamOrFilePath; | ||
return this.application.putEntity(path, stream) | ||
.then(function(ret) | ||
{ | ||
|
||
var base64string = base64_encode(streamOrFilePath); | ||
console.log(base64string); | ||
console.log(path); | ||
|
||
return this.application.postEntity(path, base64string, { type: this.MimeType }) | ||
.then(function(ret) { | ||
console.log(ret); | ||
return ret.response.Attachments.Attachment; | ||
}) | ||
.fail(function(err) { | ||
console.log(err); | ||
}) | ||
|
||
function base64_encode(file) { | ||
// read binary data | ||
var bitmap = fs.readFileSync(file); | ||
// convert binary data to base64 encoded string | ||
return new Buffer(bitmap).toString('base64'); | ||
} | ||
} | ||
}); | ||
|
||
|
||
module.exports = Attachment; | ||
module.exports.AttachmentSchema = AttachmentSchema; | ||
module.exports.AttachmentSchema = AttachmentSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, Attachment = require('../entities/attachment') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
Attachment = require('../entities/attachment'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var Attachments = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'Attachment', entityPlural:'Attachments'}, options)); | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'Attachment', entityPlural: 'Attachments' }, options)); | ||
}, | ||
newAttachment: function (data, options) | ||
{ | ||
newAttachment: function(data, options) { | ||
return new Attachment(this.application, data, options) | ||
}, | ||
getContent: function (ownerPath, fileName) | ||
{ | ||
getContent: function(ownerPath, fileName) { | ||
var path = ownerPath + '/Attachments/' + fileName; | ||
return this.application.getRaw({ id: id, modifiedAfter: modifiedAfter}) | ||
.then(function (attachments) | ||
{ | ||
return this.application.getRaw({ id: id, modifiedAfter: modifiedAfter }) | ||
.then(function(attachments) { | ||
return _.first(attachments); | ||
}) | ||
}, | ||
getAttachments: function (ownerPath, options) | ||
{ | ||
var clonedOptions = _.extend({},options, { path:ownerPath + '/Attachments'}) ; | ||
clonedOptions.entityConstructor = function(data) { return self.newAttachment(data)}; | ||
getAttachments: function(ownerPath, options) { | ||
var clonedOptions = _.extend({}, options, { path: ownerPath + '/Attachments' }); | ||
clonedOptions.entityConstructor = function(data) { return self.newAttachment(data) }; | ||
return this.getEntities(clonedOptions); | ||
} | ||
}) | ||
|
||
module.exports = Attachments; | ||
|
||
module.exports = Attachments; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, User = require('../entities/user') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
User = require('../entities/user'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var Users = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'User', entityPlural:'Users'}, options)); | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'User', entityPlural: 'Users' }, options)); | ||
}, | ||
newUser: function (data, options) | ||
{ | ||
newUser: function(data, options) { | ||
return new User(this.application, data, options) | ||
}, | ||
getUser: function (id, modifiedAfter) | ||
{ | ||
return this.getUsers({ id: id, modifiedAfter: modifiedAfter}) | ||
.then(function (users) | ||
{ | ||
getUser: function(id, modifiedAfter) { | ||
return this.getUsers({ id: id, modifiedAfter: modifiedAfter }) | ||
.then(function(users) { | ||
return _.first(users); | ||
}) | ||
}, | ||
saveUsers: function (users, options) | ||
{ | ||
return this.saveEntities(users, options) | ||
}, | ||
getUsers: function (options) | ||
{ | ||
// JWalsh 27 February 2017 - commented as user save is not supported by the v2.0 API. | ||
// saveUsers: function(users, options) { | ||
// return this.saveEntities(users, options) | ||
// }, | ||
getUsers: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newUser(data)}; | ||
clonedOptions.entityPath = 'Users.User'; | ||
clonedOptions.entityConstructor = function(data) { return self.newUser(data) }; | ||
return this.getEntities(clonedOptions) | ||
} | ||
}) | ||
|
||
module.exports = Users; | ||
module.exports = Users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.