You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2018/02/08 18:24:18 UTC
[incubator-openwhisk-package-pushnotifications] branch master
updated: Do not hard code API host of push notification service (#86)
This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-pushnotifications.git
The following commit(s) were added to refs/heads/master by this push:
new 97b99da Do not hard code API host of push notification service (#86)
97b99da is described below
commit 97b99da2b7c596dd348cb965b432fda08c25490c
Author: Jason Peterson <ja...@us.ibm.com>
AuthorDate: Thu Feb 8 13:24:16 2018 -0500
Do not hard code API host of push notification service (#86)
---
README.md | 5 ++--
packages/actions/sendMessage.js | 16 +++++++++++-
packages/installCatalog.sh | 8 +++---
.../scala/packages/PushNotificationsTests.scala | 30 ++++++++++++++++++++++
4 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 43a4dc6..b96f1c3 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@ The package includes the following action and feed:
| Entity | Type | Parameters | Description |
| --- | --- | --- | --- |
-| `/whisk.system/pushnotifications` | package | appId, appSecret | Work with the Push Service |
-| `/whisk.system/pushnotifications/sendMessage` | action | text, url, deviceIds, platforms, userIds, tagNames, gcmCollapseKey, gcmCategory, gcmIcon, gcmDelayWhileIdle, gcmSync, gcmVisibility, gcmPayload, gcmPriority, gcmSound, gcmTimeToLive, gcmStyleType, gcmStyleTitle, gcmStyleUrl, gcmStyleText, gcmStyleLines, gcmLightsLedArgb, gcmLightsLedOnMs, gcmLightsLedOffMs, apnsBadge, apnsCategory, apnsIosActionKey, apnsPayload, apnsType, apnsSound, apnsTitleLocKey, apnsLocKey, apnsLaunchImage, a [...]
+| `/whisk.system/pushnotifications` | package | appId, appSecret, admin_url | Work with the Push Service |
+| `/whisk.system/pushnotifications/sendMessage` | action | text, url, apiHost, deviceIds, platforms, userIds, tagNames, gcmCollapseKey, gcmCategory, gcmIcon, gcmDelayWhileIdle, gcmSync, gcmVisibility, gcmPayload, gcmPriority, gcmSound, gcmTimeToLive, gcmStyleType, gcmStyleTitle, gcmStyleUrl, gcmStyleText, gcmStyleLines, gcmLightsLedArgb, gcmLightsLedOnMs, gcmLightsLedOffMs, apnsBadge, apnsCategory, apnsIosActionKey, apnsPayload, apnsType, apnsSound, apnsTitleLocKey, apnsLocKey, apnsLaunc [...]
| `/whisk.system/pushnotifications/webhook` | feed | events | Fire trigger events on device activities (device registration, unregistration, subscription, or unsubscription) on the Push service |
Creating a package binding with the `appId` and `appSecret` values is suggested. This way, you don't need to specify these credentials every time you invoke the actions in the package.
@@ -54,6 +54,7 @@ The `/whisk.system/pushnotifications/sendMessage` action sends push notification
- `text`: The notification message to be shown to the user. For example: `-p text "Hi ,OpenWhisk send a notification"`.
- `url`: An optional URL that can be sent along with the alert. For example: `-p url "https:\\www.w3.ibm.com"`.
+- `apiHost`: An optional string that specifies the API host. The default is 'mobile.ng.bluemix.net'. For example: `-p apiHost "mobile.eu-gb.bluemix.net"`.
- `deviceIds` The list of specified devices. For example: `-p deviceIds "[\"deviceID1\"]"`.
- `platforms` Send notification to the devices of the specified platforms. 'A' for apple (iOS) devices and 'G' for google (Android) devices. For example `-p platforms ["A"]`.
- `userIds` - Send notification to the devices of the specified users. For example: `-p userIds "[\"testUser\"]"`
diff --git a/packages/actions/sendMessage.js b/packages/actions/sendMessage.js
index c3c39ab..4ee1584 100644
--- a/packages/actions/sendMessage.js
+++ b/packages/actions/sendMessage.js
@@ -21,6 +21,7 @@
* @param {string} appGuid - appGuid to create webhook
* @param {string} appSecret - appSecret of the application
* @param {string} url - An optional URL that can be sent along with the alert. Eg : -p url "https:\\www.mycompany.com".
+* @param {string} apiHost - An optional string that specifies the API host. The default is 'mobile.ng.bluemix.net'. Eg : -p apiHost "mobile.eu-gb.bluemix.net".
* @param {object} text - The notification message to be shown to the user. Eg: -p text "Hi ,OpenWhisk send a notification"
* @param {string} deviceIds - Send notification to the list of specified devices. Eg: -p deviceIds "["deviceID1"]"
* @param {object} platforms - Send notification to the devices of the specified platforms. 'A' for apple (iOS) devices and 'G' for google (Android) devices. Eg: -p platforms ["A"]
@@ -85,6 +86,7 @@
*/
module.paths.push('/usr/lib/node_modules');
var https = require('https');
+var url = require('url');
function main(params) {
@@ -426,10 +428,22 @@ function main(params) {
var bodyData = JSON.stringify(sendMessage);
var request = require('request');
+ var apiHost;
+ if (params.apiHost) {
+ apiHost = params.apiHost;
+ }
+ else if (params.admin_url) {
+ var adminURL = url.parse(params.admin_url).protocol === null ? `https:${params.admin_url}` : params.admin_url;
+ apiHost = url.parse(adminURL).host;
+ }
+ else {
+ apiHost = 'mobile.ng.bluemix.net';
+ }
+
var promise = new Promise(function (resolve, reject) {
request({
method: 'post',
- uri: 'https://mobile.ng.bluemix.net/imfpush/v1/apps/' + appId + '/messages',
+ uri: `https://${apiHost}/imfpush/v1/apps/${appId}/messages`,
headers: {
'appSecret': appSecret,
'Accept': 'application/json',
diff --git a/packages/installCatalog.sh b/packages/installCatalog.sh
index 06ce2fe..0dffbff 100755
--- a/packages/installCatalog.sh
+++ b/packages/installCatalog.sh
@@ -36,11 +36,11 @@ echo Installing pushnotifications package.
$WSK_CLI -i --apihost "$APIHOST" package update --auth "$AUTH" --shared yes "pushnotifications" \
-a description "This package supports sending push notifications to your mobile device, using the IBM Bluemix Push Notifications service." \
--a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}]' \
+-a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"admin_url", "required":false, "bindTime":true}]' \
-a prettyName "Push Notifications" \
-p bluemixServiceName 'imfpush'
-$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "pushnotifications/webhook" "$PACKAGE_HOME/feeds/webhook.js" \
+$WSK_CLI -i --apihost "$APIHOST" action update --kind nodejs:6 --auth "$AUTH" "pushnotifications/webhook" "$PACKAGE_HOME/feeds/webhook.js" \
-a feed true \
-a description 'pushnotifications feed' \
-a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"},{"name":"events", "required":true, "description":"Name of the event user want to subscribe"} ]' \
@@ -48,8 +48,8 @@ $WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "pushnotifications
-a sampleOutput '{"tagName": "tagName","eventType": "onDeviceRegister","applicationId": "xxx-xxx-xx"}'
-$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "pushnotifications/sendMessage" "$PACKAGE_HOME/actions/sendMessage.js" \
+$WSK_CLI -i --apihost "$APIHOST" action update --kind nodejs:6 --auth "$AUTH" "pushnotifications/sendMessage" "$PACKAGE_HOME/actions/sendMessage.js" \
-a description 'Send push notification to all application users or to a specific set of devices' \
--a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"text", "required":true, "description":"The notification message to be shown to the user"}, {"name":"url", "required":false, "description":"An optional URL that can be sent along with the alert"}, {"name":"deviceIds", "required":false, "description":" [...]
+-a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"text", "required":true, "description":"The notification message to be shown to the user"}, {"name":"url", "required":false, "description":"An optional URL that can be sent along with the alert"}, {"name":"apiHost", "required":false, "description":"AP [...]
-a sampleInput '{"appGuid":"xxx-xxx-xx", "appSecret":"yyy-yyy-yyy", "text":"hi there"}' \
-a sampleOutput '{"pushResponse": {"messageId":"11111s","message":{"message":{"alert":"register for tag"}}}}'
diff --git a/tests/src/test/scala/packages/PushNotificationsTests.scala b/tests/src/test/scala/packages/PushNotificationsTests.scala
index cb6afc5..8da096e 100644
--- a/tests/src/test/scala/packages/PushNotificationsTests.scala
+++ b/tests/src/test/scala/packages/PushNotificationsTests.scala
@@ -31,6 +31,8 @@ class PushNotificationsTests
val credentials = TestUtils.getVCAPcredentials("imfpush")
val appSecret = credentials.get("appSecret").toJson;
val credentialsUrl = credentials.get("url");
+ val adminURL = credentials.get("admin_url");
+ val apiHost = adminURL.split("/")(2);
val appGuid = credentialsUrl.split("/").last.toJson;
val url = "www.google.com".toJson;
@@ -67,4 +69,32 @@ class PushNotificationsTests
_.response.result.get.toString should include ("message")
}
}
+
+ it should "Send Notification action using admin_url" in {
+ val name = "/whisk.system/pushnotifications/sendMessage"
+ withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "admin_url"-> adminURL.toJson))){
+ _.response.result.get.toString should include ("message")
+ }
+ }
+
+ it should "Send Notification action using bad admin_url" in {
+ val name = "/whisk.system/pushnotifications/sendMessage"
+ withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "admin_url"-> "//mobile.bad.host/pathname".toJson))){
+ _.response.success shouldBe false
+ }
+ }
+
+ it should "Send Notification action using apiHost" in {
+ val name = "/whisk.system/pushnotifications/sendMessage"
+ withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "apiHost"-> apiHost.toJson))){
+ _.response.result.get.toString should include ("message")
+ }
+ }
+
+ it should "Send Notification action using bad apiHost" in {
+ val name = "/whisk.system/pushnotifications/sendMessage"
+ withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "apiHost"-> "mobile.bad.host".toJson))){
+ _.response.success shouldBe false
+ }
+ }
}
--
To stop receiving notification emails like this one, please contact
csantanapr@apache.org.