This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added birdsend api, needed to change the interface entity, delete and…
… reload when upgrading
- Loading branch information
Showing
3 changed files
with
109 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
This software is in the public domain under CC0 1.0 Universal plus a | ||
Grant of Patent License. | ||
To the extent possible under law, the author(s) have dedicated all | ||
copyright and related and neighboring rights to this software to the | ||
public domain worldwide. This software is distributed without any | ||
warranty. | ||
You should have received a copy of the CC0 Public Domaicrn Dedication | ||
along with this software (see the LICENSE.md file). If not, see | ||
<http://creativecommons.org/publicdomain/zero/1.0/>. | ||
--> | ||
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-2.1.xsd"> | ||
|
||
<service verb="registerAdd" noun="UserToGroup"> | ||
<in-parameters> | ||
<parameter name="email" required="true"/> | ||
<parameter name="firstName"/> | ||
<parameter name="lastName"/> | ||
</in-parameters> | ||
<out-parameters> | ||
<parameter name="resultMessage"/> | ||
</out-parameters> | ||
<actions> | ||
<entity-find-one entity-name="growerp.general.Interface" value-field="interfaceValue"> | ||
<field-map field-name="interfaceId" value="birdSend"/> | ||
</entity-find-one> | ||
<set field="apiKey" from="interfaceValue?.apiKey"/> | ||
<set field="baseUrl" from="interfaceValue?.baseUrl"/> | ||
<set field="groupName" from="interfaceValue?.value1"/> | ||
<if condition="!interfaceValue || !baseUrl || !apiKey || !groupName"> | ||
<return error="false" message="mailerLight not configured: missing parameters in table interfaceValue"/> | ||
</if> | ||
<!-- add user --> | ||
<script><![CDATA[ | ||
import org.moqui.util.RestClient | ||
import org.moqui.util.RestClient.Method | ||
// get sequence id | ||
Map result = restGet("v1/sequences") | ||
String sequenceId; | ||
for(sequence in result.data) { | ||
if (sequence.name == groupName) sequenceId = sequence.sequence_id | ||
} | ||
if (sequenceId) { | ||
// add user and sequence | ||
result = restPost("v1/contacts", [email: email, sequenceId: sequenceId]) | ||
} else { | ||
logger.warn("Sequence group $groupName not found!") | ||
} | ||
//============ closures ============= | ||
def Map restPost(String path, Map parameters) { | ||
RestClient restClient = ec.service.rest().method(RestClient.POST) | ||
.uri("$baseUrl/$path").addHeader("Content-Type", "application/json") | ||
.addHeader("Authorization","Bearer ${apiKey}").addBodyParameters(parameters) | ||
RestClient.RestResponse restResponse = restClient.call() | ||
Map respMap = (Map) restResponse.jsonObject() | ||
if (restResponse.statusCode < 200 || restResponse.statusCode >= 300) { | ||
ec.logger.warn("Unsuccessful register ${restResponse.statusCode}: ${respMap}") | ||
return | ||
} | ||
ec.logger.info("Successful : ${respMap}") | ||
return respMap | ||
} | ||
// cannot use other post closure because of strange parameter passing..... | ||
def Map restAssignToGroup(String subscriberId, String groupId) { | ||
RestClient restClient = ec.service.rest().method(RestClient.POST) | ||
.uri("$baseUrl/api/subscribers/$subscriberId/groups/$groupId") | ||
.addHeader("Content-Type", "application/json") | ||
.addHeader("Authorization","Bearer ${apiKey}") | ||
RestClient.RestResponse restResponse = restClient.call() | ||
Map respMap = (Map) restResponse.jsonObject() | ||
if (restResponse.statusCode < 200 || restResponse.statusCode >= 300) { | ||
ec.logger.warn("Unsuccessful register ${restResponse.statusCode}: ${respMap}") | ||
return | ||
} | ||
ec.logger.info("Successful : ${respMap}") | ||
return respMap | ||
} | ||
def Map restGet(String path) { | ||
// List pList = new ArrayList(parameters.entrySet()); | ||
RestClient restClient = ec.service.rest().method(RestClient.GET) | ||
restClient.addHeader("Authorization","Bearer ${apiKey}") | ||
.addHeader("Content-Type", "application/json") | ||
restClient.uri().protocol("https") | ||
.host(baseUrl.substring(baseUrl.indexOf('/')+2)).port(443) | ||
.path(path) | ||
// .parameter(pList[0]?.getKey(), pList[0]?.getValue()).parameter(pList[1]?.getKey(), pList[1]?.getValue()) | ||
.build() | ||
RestClient.RestResponse restResponse = restClient.call() | ||
Map respMap = (Map) restResponse.jsonObject() | ||
if (restResponse.statusCode < 200 || restResponse.statusCode >= 300) { | ||
ec.logger.warn("Unsuccessful register ${restResponse.statusCode}: ${respMap}") | ||
return | ||
} | ||
ec.logger.info("Successful : ${respMap}") | ||
return respMap | ||
} | ||
]]></script> | ||
</actions> | ||
</service> | ||
</services> |
File renamed without changes.