}
}
-var MessageServiceTag = ['messaging.sms', 'messaging.mms', 'messaging.email'];
+var MessageServiceTag = {
+ SMS: "messaging.sms",
+ MMS: "messaging.mms",
+ EMAIL: "messaging.email"
+};
function Message(type, data) {
- if (!(this instanceof Message)) {
- throw new TypeError('Constructor called like a function');
- }
- if (MessageServiceTag.indexOf(type) === -1) {
+ validator_.isConstructorCall(this, Message);
+
+ if (Object.values(MessageServiceTag).indexOf(type) == -1) {
throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR);
}
+
if (!data || typeof data !== 'object') {
- // 'data' is optional
data = {};
}
- // set initial data from internal MessageInit_ object or to default values
var internal = data instanceof MessageInit_,
id = internal ? data.id : null,
conversationId = internal ? data.conversationId : null,
hasAttachment = internal ? data.hasAttachment : false,
isRead = internal ? data.isRead : false,
inResponseTo = internal ? data.inResponseTo : null;
- // create MessageBody object
+
var body = new MessageBody({
messageId: id,
plainBody: data.plainBody,
htmlBody: data.htmlBody
});
- // check 'to', 'cc' and 'bcc' fields
+
var to = data.to;
if (!(to instanceof Array)) {
to = [];
}
+
var cc = data.cc;
if (!(cc instanceof Array)) {
cc = [];
}
+
var bcc = data.bcc;
if (!(bcc instanceof Array)) {
bcc = [];
}
- // 'attachments' private variable, getter and setter
+
var attachments = (internal ? data.attachments : []) || [];
var _internal = {
});
}
-function MessageInit(data) {
- if (!(this instanceof MessageInit)) {
- return new MessageInit(data);
- }
- if (data === null || typeof data !== 'object') {
- data = {};
- }
- propertyFactory_(this, 'subject', data.subject || '', Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(this, 'to', data.to || [], Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(this, 'cc', data.cc || [], Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(this, 'bcc', data.bcc || [], Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(this, 'plainBody', data.plainBody || '', Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(this, 'htmlBody', data.htmlBody || '', Property.ENUMERABLE | Property.WRITEABLE);
- propertyFactory_(
- this,
- 'isHighPriority',
- data.isHighPriority || false,
- Property.ENUMERABLE | Property.WRITEABLE
- );
-}
-
function MessageInit_(data) {
if (!(this instanceof MessageInit_)) {
return new MessageInit_(data);
Messaging.prototype.getMessageServices = function() {
var args = validator_.validateArgs(arguments, [
- { name: 'messageServiceType', type: types_.ENUM, values: MessageServiceTag },
+ { name: 'messageServiceType', type: types_.ENUM, values: Object.values(MessageServiceTag) },
{ name: 'successCallback', type: types_.FUNCTION },
{ name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
]);