Comparing version 2.0.0 to 2.1.0
(function() { | ||
var Attribute, AttributeBoolean, AttributeCollection, AttributeDateTime, AttributeNumber, AttributeString, | ||
var Attribute, AttributeBoolean, AttributeCollection, AttributeDateTime, AttributeNumber, AttributeString, AttributeStringList, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -89,2 +89,21 @@ hasProp = {}.hasOwnProperty; | ||
AttributeStringList = (function(superClass) { | ||
extend(AttributeStringList, superClass); | ||
function AttributeStringList() { | ||
return AttributeStringList.__super__.constructor.apply(this, arguments); | ||
} | ||
AttributeStringList.prototype.toJSON = function(val) { | ||
return val; | ||
}; | ||
AttributeStringList.prototype.fromJSON = function(val, parent) { | ||
return val || []; | ||
}; | ||
return AttributeStringList; | ||
})(Attribute); | ||
AttributeDateTime = (function(superClass) { | ||
@@ -179,2 +198,9 @@ extend(AttributeDateTime, superClass); | ||
}, | ||
StringList: function() { | ||
return (function(func, args, ctor) { | ||
ctor.prototype = func.prototype; | ||
var child = new ctor, result = func.apply(child, args); | ||
return Object(result) === result ? result : child; | ||
})(AttributeStringList, arguments, function(){}); | ||
}, | ||
DateTime: function() { | ||
@@ -210,2 +236,3 @@ return (function(func, args, ctor) { | ||
AttributeString: AttributeString, | ||
AttributeStringList: AttributeStringList, | ||
AttributeDateTime: AttributeDateTime, | ||
@@ -212,0 +239,0 @@ AttributeCollection: AttributeCollection, |
@@ -58,5 +58,2 @@ (function() { | ||
var reqOpts; | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
reqOpts = { | ||
@@ -63,0 +60,0 @@ method: 'POST', |
@@ -29,2 +29,9 @@ (function() { | ||
Draft.attributes = _.extend({}, Message.attributes, { | ||
'replyToMessageId': Attributes.String({ | ||
modelKey: 'replyToMessageId', | ||
jsonKey: 'reply_to_message_id' | ||
}) | ||
}); | ||
Draft.prototype.toJSON = function() { | ||
@@ -50,2 +57,6 @@ var json; | ||
Draft.prototype.saveRequestBody = function() { | ||
return Draft.__super__.saveRequestBody.apply(this, arguments); | ||
}; | ||
Draft.prototype.send = function(callback) { | ||
@@ -62,3 +73,3 @@ var body; | ||
} else { | ||
body = this.toJSON(); | ||
body = this.saveRequestBody(); | ||
} | ||
@@ -65,0 +76,0 @@ return this.connection.request({ |
(function() { | ||
var Attributes, File, RestfulModel, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -16,2 +17,3 @@ hasProp = {}.hasOwnProperty; | ||
function File() { | ||
this.upload = bind(this.upload, this); | ||
return File.__super__.constructor.apply(this, arguments); | ||
@@ -46,2 +48,48 @@ } | ||
File.prototype.upload = function(callback) { | ||
if (callback == null) { | ||
callback = null; | ||
} | ||
if (!this.filename) { | ||
throw new Error("Please define a filename"); | ||
} | ||
if (!this.data) { | ||
throw new Error("Please add some data to the file"); | ||
} | ||
if (!this.contentType) { | ||
throw new Error("Please define a content-type"); | ||
} | ||
return this.connection.request({ | ||
method: 'POST', | ||
json: false, | ||
path: "/" + this.constructor.collectionName, | ||
formData: { | ||
file: { | ||
value: this.data, | ||
options: { | ||
filename: this.filename, | ||
contentType: this.contentType | ||
} | ||
} | ||
} | ||
}).then((function(_this) { | ||
return function(json) { | ||
if (json.length > 0) { | ||
_this.fromJSON(json[0]); | ||
if (callback) { | ||
callback(null, _this); | ||
} | ||
return Promise.resolve(_this); | ||
} else { | ||
return Promise.reject(null); | ||
} | ||
}; | ||
})(this))["catch"](function(err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
return Promise.reject(err); | ||
}); | ||
}; | ||
return File; | ||
@@ -48,0 +96,0 @@ |
(function() { | ||
var Attributes, Contact, Folder, Label, RestfulModel, Tag, Thread, _, | ||
var Attributes, Contact, Folder, Label, Message, RestfulModel, Tag, Thread, _, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -11,2 +11,4 @@ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
Message = require('./message'); | ||
RestfulModel = require('./restful-model'); | ||
@@ -49,2 +51,6 @@ | ||
}), | ||
'messageIds': Attributes.StringList({ | ||
modelKey: 'messageIds', | ||
jsonKey: 'message_ids' | ||
}), | ||
'tags': Attributes.Collection({ | ||
@@ -51,0 +57,0 @@ queryable: true, |
@@ -21,13 +21,8 @@ (function() { | ||
Nylas.authServer = 'https://www.nylas.com'; | ||
Nylas.config = function(arg) { | ||
var apiServer, appId, appSecret, authServer, ref; | ||
ref = arg != null ? arg : {}, appId = ref.appId, appSecret = ref.appSecret, apiServer = ref.apiServer, authServer = ref.authServer; | ||
var apiServer, appId, appSecret, ref; | ||
ref = arg != null ? arg : {}, appId = ref.appId, appSecret = ref.appSecret, apiServer = ref.apiServer; | ||
if ((apiServer != null ? apiServer.indexOf('://') : void 0) === -1) { | ||
throw new Error("Please specify a fully qualified URL for the API Server."); | ||
} | ||
if ((authServer != null ? authServer.indexOf('://') : void 0) === -1) { | ||
throw new Error("Please specify a fully qualified URL for the Auth Server."); | ||
} | ||
if (appId) { | ||
@@ -42,5 +37,2 @@ this.appId = appId; | ||
} | ||
if (authServer) { | ||
this.authServer = authServer; | ||
} | ||
return this; | ||
@@ -74,3 +66,3 @@ }; | ||
json: true, | ||
url: _this.authServer + "/oauth/token", | ||
url: _this.apiServer + "/oauth/token", | ||
qs: { | ||
@@ -116,3 +108,3 @@ 'client_id': _this.appId, | ||
} | ||
return this.authServer + "/oauth/authorize?client_id=" + this.appId + "&trial=" + options.trial + "&response_type=code&scope=email&login_hint=" + options.loginHint + "&redirect_uri=" + options.redirectURI; | ||
return this.apiServer + "/oauth/authorize?client_id=" + this.appId + "&trial=" + options.trial + "&response_type=code&scope=email&login_hint=" + options.loginHint + "&redirect_uri=" + options.redirectURI; | ||
}; | ||
@@ -119,0 +111,0 @@ |
{ | ||
"name": "nylas", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A NodeJS wrapper for the Nylas REST API for Email, Contacts and Calendar", | ||
@@ -24,3 +24,3 @@ "main": "lib/nylas.js", | ||
"JSONStream": "1.0.4", | ||
"request": "^2.53.0", | ||
"request": "^2.63.0", | ||
"underscore": "^1.7.0" | ||
@@ -27,0 +27,0 @@ }, |
@@ -55,3 +55,3 @@ Nylas Node.js Bindings | ||
----- | ||
The Nylas REST API uses server-side (three-legged) OAuth, and the Node.js bindings provide convenience methods that simplifiy the OAuth process. For more information about authenticating users with Nylas, visit the [Developer Documentation](https://www.nylas.com/docs/knowledgebase#authentication) | ||
The Nylas REST API uses server-side (three-legged) OAuth, and the Node.js bindings provide convenience methods that simplifiy the OAuth process. For more information about authenticating users with Nylas, visit the [Developer Documentation](https://nylas.com/docs/#authentication) | ||
@@ -198,2 +198,36 @@ Step 1: Redirect the user to Nylas: | ||
Uploading files | ||
----- | ||
```javascript | ||
var nylas = Nylas.with(accessToken); | ||
var fs = require('fs'); | ||
// Because of a bug in the library we use to issue http requests, | ||
// we can't pass a stream to the file upload function, which is | ||
// why we read the file directly. | ||
fs.readFile(filePath, 'utf8', function (err, data) { | ||
f = nylas.files.build({ | ||
filename: filePath, | ||
data: data, | ||
contentType: 'text/plain' | ||
}); | ||
f.upload(function(err, file) { | ||
// Create a draft and attach the file to it. | ||
var draft = nylas.drafts.build({ | ||
subject: 'Ice-cream', | ||
to: [{email: 'helena@nylas.com'}], | ||
body: 'Hey, find the file attached.', | ||
}); | ||
draft.files = [file]; | ||
draft.send().then(function(draft) { | ||
console.log(draft.id + ' was sent'); | ||
}); | ||
}); | ||
}); | ||
``` | ||
Creating and Sending Drafts | ||
@@ -208,2 +242,5 @@ ------ | ||
to: [{email: 'ben@nylas.com'}] | ||
replyToMessageId: "8i4u7sid2ygvfso9gomu9rcw3" // id of the message we're replying to. When set, | ||
// the Nylas sending API will set specific email | ||
// headers to mark your message as a reply to `message_id`. | ||
}); | ||
@@ -210,0 +247,0 @@ |
@@ -5,2 +5,4 @@ /* | ||
*/ | ||
APP_ID = '' | ||
APP_SECRET = '' | ||
AUTH_TOKEN = "Your auth token" | ||
@@ -12,2 +14,4 @@ DEST_EMAIL = "An email address to sent email to." | ||
DEST_EMAIL: DEST_EMAIL, | ||
APP_ID: APP_ID, | ||
APP_SECRET: APP_SECRET, | ||
} |
@@ -14,3 +14,3 @@ console.log("") | ||
console.log("\n\n") | ||
console.log("Hiya! Welcome to the Ruby SDK test program. I need your help to make sure we didn't break the SDK.") | ||
console.log("Hiya! Welcome to the Node SDK test program. I need your help to make sure we didn't break the SDK.") | ||
console.log("") | ||
@@ -17,0 +17,0 @@ console.log("Could you confirm that the following API functions didn't break?") |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176998
83
2243
373
Updatedrequest@^2.63.0