Skip to content

Commit

Permalink
#789: add support to update mobileMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 7, 2023
1 parent fc26e59 commit b4c7f1b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 66 deletions.
14 changes: 7 additions & 7 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3178,7 +3178,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.createOrUpdate(metadata, metadataKey, hasError, metadataToUpdate, metadataToCreate)](#MetadataType.createOrUpdate) ⇒ <code>void</code>
* [.createREST(metadataEntry, uri)](#MetadataType.createREST) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [.createSOAP(metadataEntry, [overrideType], [handleOutside])](#MetadataType.createSOAP) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [.updateREST(metadataEntry, uri, [usePut])](#MetadataType.updateREST) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [.updateREST(metadataEntry, uri, [httpMethod])](#MetadataType.updateREST) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [.updateSOAP(metadataEntry, [overrideType], [handleOutside])](#MetadataType.updateSOAP) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
* [._handleSOAPErrors(ex, msg, [metadataEntry], [handleOutside])](#MetadataType._handleSOAPErrors)
* [.getSOAPErrorMsg(ex)](#MetadataType.getSOAPErrorMsg) ⇒ <code>string</code>
Expand Down Expand Up @@ -3510,17 +3510,17 @@ Creates a single metadata entry via fuel-soap (generic lib not wrapper)

<a name="MetadataType.updateREST"></a>

### MetadataType.updateREST(metadataEntry, uri, [usePut]) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
### MetadataType.updateREST(metadataEntry, uri, [httpMethod]) ⇒ <code>Promise.&lt;object&gt;</code> \| <code>null</code>
Updates a single metadata entry via REST

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
**Returns**: <code>Promise.&lt;object&gt;</code> \| <code>null</code> - Promise of API response or null in case of an error

| Param | Type | Description |
| --- | --- | --- |
| metadataEntry | <code>TYPE.MetadataTypeItem</code> | a single metadata Entry |
| uri | <code>string</code> | rest endpoint for PATCH |
| [usePut] | <code>boolean</code> | some update requests require PUT instead of PATCH |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| metadataEntry | <code>TYPE.MetadataTypeItem</code> | | a single metadata Entry |
| uri | <code>string</code> | | rest endpoint for PATCH |
| [httpMethod] | <code>&#x27;patch&#x27;</code> \| <code>&#x27;post&#x27;</code> \| <code>&#x27;put&#x27;</code> | <code>&#x27;patch&#x27;</code> | defaults to 'patch'; some update requests require PUT instead of PATCH |

<a name="MetadataType.updateSOAP"></a>

Expand Down
2 changes: 1 addition & 1 deletion lib/metadataTypes/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Interaction extends MetadataType {
* @returns {Promise} Promise
*/
static update(metadata) {
return super.updateREST(metadata, '/interaction/v1/interactions/', true);
return super.updateREST(metadata, '/interaction/v1/interactions/', 'put');
}

/**
Expand Down
9 changes: 4 additions & 5 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,14 @@ class MetadataType {
*
* @param {TYPE.MetadataTypeItem} metadataEntry a single metadata Entry
* @param {string} uri rest endpoint for PATCH
* @param {boolean} [usePut] some update requests require PUT instead of PATCH
* @param {'patch'|'post'|'put'} [httpMethod='patch'] defaults to 'patch'; some update requests require PUT instead of PATCH
* @returns {Promise.<object> | null} Promise of API response or null in case of an error
*/
static async updateREST(metadataEntry, uri, usePut) {
static async updateREST(metadataEntry, uri, httpMethod = 'patch') {
Util.logger.info('uri: ' + uri);
this.removeNotUpdateableFields(metadataEntry);
try {
const response = usePut
? await this.client.rest.put(uri, metadataEntry)
: await this.client.rest.patch(uri, metadataEntry);
const response = await this.client.rest[httpMethod](uri, metadataEntry);
this.checkForErrors(response);
// some times, e.g. automation dont return a key in their update response and hence we need to fall back to name
Util.logger.info(
Expand Down
4 changes: 3 additions & 1 deletion lib/metadataTypes/MobileMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ class MobileMessage extends MetadataType {
static update(metadata) {
return super.updateREST(
metadata,
'/legacy/v1/beta/mobile/message/' + metadata[this.definition.keyField]
'/legacy/v1/beta/mobile/message/' + metadata[this.definition.keyField],
'post'
);
}

/**
* Creates a single Event Definition
*
Expand Down
104 changes: 52 additions & 52 deletions lib/metadataTypes/definitions/MobileMessage.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,163 +64,163 @@ module.exports = {
},
lastUpdated: {
isCreateable: false,
isUpdateable: false,
isUpdateable: true,
retrieving: true,
template: false,
},
'code.code': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'code.id': {
isCreateable: true,
isUpdateable: false,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.createdDate': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.lastUpdated': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.startDate': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.endDate': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.keywordLimit': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.keywordsUsed': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.codeType': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isShortCode': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.keywordsUsedOther': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isGsmCharacterSetOnly': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isMms': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isStackIndependant': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.supportsConcatenation': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isClientOwned': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.isOwner': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.dipSwitches': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.sendableCountries': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.countryCode': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'code.moEngineVersion': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'keyword.id': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'keyword.keyword': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'keyword.restriction': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'keyword.keywordType': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
'keyword.isInherited': {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
Expand Down

0 comments on commit b4c7f1b

Please sign in to comment.