refactor(OneSignal):

This commit is contained in:
Guille 2016-07-17 20:03:03 +02:00
parent 494d80e9de
commit 88e05d663a

View File

@ -1,4 +1,5 @@
import {Plugin, Cordova} from './plugin'; import { Cordova, Plugin } from './plugin';
/** /**
* @name OneSignal * @name OneSignal
@ -24,230 +25,231 @@ import {Plugin, Cordova} from './plugin';
* *
*/ */
@Plugin({ @Plugin({
plugin: 'onesignal-cordova-plugin', plugin: 'onesignal-cordova-plugin',
pluginRef: 'plugins.OneSignal', pluginRef: 'plugins.OneSignal',
repo: 'https://github.com/OneSignal/OneSignal-Cordova-SDK', repo: 'https://github.com/OneSignal/OneSignal-Cordova-SDK',
platforms: ['Android', 'iOS', 'Windows Phone 8'] platforms: ['Android', 'iOS', 'Windows Phone 8']
}) })
export class OneSignal { export class OneSignal {
/** /**
* Only required method you need to call to setup OneSignal to receive push notifications. Call this from the `deviceready` event. * Only required method you need to call to setup OneSignal to receive push notifications. Call this from the `deviceready` event.
* *
* @param {appId} Your AppId from your OneSignal app * @param {appId} Your AppId from your OneSignal app
* @param {options} The Google Project Number (which you can get from the Google Developer Potal) and the autoRegister option. * @param {options} The Google Project Number (which you can get from the Google Developer Potal) and the autoRegister option.
* @returns {Promise} Returns a Promise that resolves when remote notification was recieved. * @returns {Promise} Returns a Promise that resolves when remote notification was recieved.
*/ */
@Cordova() @Cordova()
static init(appId: string, static init(appId: string,
options: { options: {
googleProjectNumber: string, googleProjectNumber: string,
autoRegister: boolean autoRegister: boolean
}): Promise<any> { return; } }): Promise<any> { return; }
/** /**
* Call this when you would like to prompt an iOS user to accept push notifications with the default system prompt. * Call this when you would like to prompt an iOS user to accept push notifications with the default system prompt.
* Only use if you passed false to autoRegister when calling init. * Only use if you passed false to autoRegister when calling init.
*/ */
@Cordova({ sync: true }) @Cordova({ sync: true })
static registerForPushNotifications(): void { } static registerForPushNotifications(): void { }
/** /**
* Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users.
* Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
*
* @param {key} Key of your choosing to create or update.
* @param {value} Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call deleteTag.
*/
@Cordova({ sync: true })
static sendTag(key: string, value: string): void { }
/**
* Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users. * Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users.
* Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time. * Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
* *
* @param {json} Pass a json object with key/value pairs like: {key: "value", key2: "value2"} * @param {key} Key of your choosing to create or update.
* @param {value} Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call deleteTag.
*/ */
@Cordova({ sync: true }) @Cordova({ sync: true })
static sendTags(json: any): void { } static sendTag(key: string, value: string): void { }
/** /**
* Retrieve a list of tags that have been set on the user from the OneSignal server. * Tag a user based on an app event of your choosing so later you can create segments on [onesignal.com](https://onesignal.com/) to target these users.
* * Recommend using sendTags over sendTag if you need to set more than one tag on a user at a time.
* @returns {Promise} Returns a Promise that resolves when tags are recieved. *
*/ * @param {json} Pass a json object with key/value pairs like: {key: "value", key2: "value2"}
@Cordova() */
static getTags(): Promise<any> { return; } @Cordova({ sync: true })
static sendTags(json: any): void { }
/** /**
* Deletes a tag that was previously set on a user with `sendTag` or `sendTags`. Use `deleteTags` if you need to delete more than one. * Retrieve a list of tags that have been set on the user from the OneSignal server.
* *
* @param {key} Key to remove. * @returns {Promise} Returns a Promise that resolves when tags are recieved.
*/ */
@Cordova({ sync: true }) @Cordova()
static deleteTag(key: string): void { } static getTags(): Promise<any> { return; }
/** /**
* Deletes tags that were previously set on a user with `sendTag` or `sendTags`. * Deletes a tag that was previously set on a user with `sendTag` or `sendTags`. Use `deleteTags` if you need to delete more than one.
* *
* @param {keys} Keys to remove. * @param {key} Key to remove.
*/ */
@Cordova({ sync: true }) @Cordova({ sync: true })
static deleteTags(keys: string[]): void { } static deleteTag(key: string): void { }
/** /**
* Lets you retrieve the OneSignal user id and device token. * Deletes tags that were previously set on a user with `sendTag` or `sendTags`.
* Your handler is called after the device is successfully registered with OneSignal. *
* * @param {keys} Keys to remove.
* @returns {Promise} Returns a Promise that reolves if the device was successfully registered. */
* It returns a JSON with `userId`and `pushToken`. @Cordova({ sync: true })
*/ static deleteTags(keys: string[]): void { }
@Cordova()
static getIds(): Promise<any> { return; }
/** /**
* Warning: * Lets you retrieve the OneSignal user id and device token.
* Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications. * Your handler is called after the device is successfully registered with OneSignal.
* *
* By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode. * @returns {Promise} Returns a Promise that reolves if the device was successfully registered.
* Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode. * It returns a JSON with `userId`and `pushToken`.
* */
* @param {enable} false to disable vibrate, true to re-enable it. @Cordova()
*/ static getIds(): Promise<any> { return; }
@Cordova({ sync: true })
static enableVibrate(enable: boolean): void { }
/** /**
* Warning: * Warning:
* Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications. * Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications.
* *
* By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on. * By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode.
* Passing false means that the device will only vibrate unless the device is set to a total silent mode. * Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
* *
* @param {enable} false to disable sound, true to re-enable it. * @param {enable} false to disable vibrate, true to re-enable it.
*/ */
@Cordova({ sync: true }) @Cordova({ sync: true })
static enableSound(enable: boolean): void { } static enableVibrate(enable: boolean): void { }
/** /**
* Warning: * Warning:
* Only applies to Android and Amazon devices. * Only applies to Android and Amazon. You can call this from your UI from a button press for example to give your user's options for your notifications.
* *
* By default this is false and notifications will not be shown when the user is in your app, instead the notificationOpenedCallback is fired. * By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on.
* If set to true notifications will always show in the notification area and notificationOpenedCallback will not fire until the user taps on the notification. * Passing false means that the device will only vibrate unless the device is set to a total silent mode.
* *
* @param {enable} enable * @param {enable} false to disable sound, true to re-enable it.
*/ */
@Cordova({ sync: true }) @Cordova({ sync: true })
static enableNotificationsWhenActive(enable: boolean): void { } static enableSound(enable: boolean): void { }
/** /**
* By default this is false and notifications will not be shown when the user is in your app, instead the notificationOpenedCallback is fired. * Warning:
* If set to true notifications will be shown as native alert boxes if a notification is received when the user is in your app. * Only applies to Android and Amazon devices.
* The notificationOpenedCallback is then fired after the alert box is closed. *
* * By default this is false and notifications will not be shown when the user is in your app, instead the notificationOpenedCallback is fired.
* @param {enable} enable * If set to true notifications will always show in the notification area and notificationOpenedCallback will not fire until the user taps on the notification.
*/ *
@Cordova({ sync: true }) * @param {enable} enable
static enableInAppAlertNotification(enable: boolean): void { } */
@Cordova({ sync: true })
static enableNotificationsWhenActive(enable: boolean): void { }
/** /**
* You can call this method with false to opt users out of receiving all notifications through OneSignal. * By default this is false and notifications will not be shown when the user is in your app, instead the notificationOpenedCallback is fired.
* You can pass true later to opt users back into notifications. * If set to true notifications will be shown as native alert boxes if a notification is received when the user is in your app.
* * The notificationOpenedCallback is then fired after the alert box is closed.
* @param {enable} enable *
*/ * @param {enable} enable
@Cordova({ sync: true }) */
static setSubscription(enable: boolean): void { } @Cordova({ sync: true })
static enableInAppAlertNotification(enable: boolean): void { }
/** /**
* * You can call this method with false to opt users out of receiving all notifications through OneSignal.
* @param {notificationObj} Parameters see POST [documentation](https://documentation.onesignal.com/v2.0/docs/notifications-create-notification) * You can pass true later to opt users back into notifications.
* @returns {Promise} Returns a Promise that resolves if the notification was send successfully. *
*/ * @param {enable} enable
@Cordova() */
static postNotification(notificationObj: { @Cordova({ sync: true })
app_id: string, static setSubscription(enable: boolean): void { }
contents: any,
headings?: any,
isIos?: boolean,
isAndroid?: boolean,
isWP?: boolean,
isWP_WNS?: boolean,
isAdm?: boolean,
isChrome?: boolean,
isChromeWeb?: boolean,
isSafari?: boolean,
isAnyWeb?: boolean,
included_segments?: string[],
excluded_segments?: string[],
include_player_ids?: string[],
include_ios_tokens?: string[],
include_android_reg_ids?: string[],
include_wp_uris?: string[],
include_wp_wns_uris?: string[],
include_amazon_reg_ids?: string[],
include_chrome_reg_ids?: string[],
include_chrome_web_reg_ids?: string[],
app_ids?: string[];
tags?: any[],
ios_badgeType?: string,
ios_badgeCount?: number,
ios_sound?: string,
android_sound?: string,
adm_sound?: string,
wp_sound?: string,
wp_wns_sound?: string,
data?: any,
buttons?: any,
small_icon?: string,
large_icon?: string,
big_picture?: string,
adm_small_icon?: string,
adm_large_icon?: string,
adm_big_picture?: string,
chrome_icon?: string,
chrome_big_picture?: string,
chrome_web_icon?: string,
firefox_icon?: string,
url?: string,
send_after?: string,
delayed_option?: string,
delivery_time_of_day?: string,
android_led_color?: string,
android_accent_color?: string,
android_visibility?: number,
content_available?: boolean,
amazon_background_data?: boolean,
template_id?: string,
android_group?: string,
android_group_message?: any,
adm_group?: string,
adm_group_message?: any,
ttl?: number,
priority?: number,
ios_category?: string
}): Promise<any> { return; }
/** /**
* Prompts the user for location permission to allow geotagging based on the "Location radius" filter on the OneSignal dashboard. *
*/ * @param {notificationObj} Parameters see POST [documentation](https://documentation.onesignal.com/v2.0/docs/notifications-create-notification)
@Cordova({ sync: true }) * @returns {Promise} Returns a Promise that resolves if the notification was send successfully.
static promptLocation(): void { } */
@Cordova()
static postNotification(notificationObj: {
app_id: string,
contents: any,
headings?: any,
isIos?: boolean,
isAndroid?: boolean,
isWP?: boolean,
isWP_WNS?: boolean,
isAdm?: boolean,
isChrome?: boolean,
isChromeWeb?: boolean,
isSafari?: boolean,
isAnyWeb?: boolean,
included_segments?: string[],
excluded_segments?: string[],
include_player_ids?: string[],
include_ios_tokens?: string[],
include_android_reg_ids?: string[],
include_wp_uris?: string[],
include_wp_wns_uris?: string[],
include_amazon_reg_ids?: string[],
include_chrome_reg_ids?: string[],
include_chrome_web_reg_ids?: string[],
app_ids?: string[];
tags?: any[],
ios_badgeType?: string,
ios_badgeCount?: number,
ios_sound?: string,
android_sound?: string,
adm_sound?: string,
wp_sound?: string,
wp_wns_sound?: string,
data?: any,
buttons?: any,
small_icon?: string,
large_icon?: string,
big_picture?: string,
adm_small_icon?: string,
adm_large_icon?: string,
adm_big_picture?: string,
chrome_icon?: string,
chrome_big_picture?: string,
chrome_web_icon?: string,
firefox_icon?: string,
url?: string,
send_after?: string,
delayed_option?: string,
delivery_time_of_day?: string,
android_led_color?: string,
android_accent_color?: string,
android_visibility?: number,
content_available?: boolean,
amazon_background_data?: boolean,
template_id?: string,
android_group?: string,
android_group_message?: any,
adm_group?: string,
adm_group_message?: any,
ttl?: number,
priority?: number,
ios_category?: string
}): Promise<any> { return; }
/** /**
* Enable logging to help debug if you run into an issue setting up OneSignal. * Prompts the user for location permission to allow geotagging based on the "Location radius" filter on the OneSignal dashboard.
* The logging levels are as follows: 0 = None, 1= Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose */
@Cordova({ sync: true })
static promptLocation(): void { }
/**
* Enable logging to help debug if you run into an issue setting up OneSignal.
* The logging levels are as follows: 0 = None, 1= Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose
* The higher the value the more information is shown.
*
* @param {loglevel} contains two properties: logLevel (for console logging) and visualLevel (for dialog messages)
*/
@Cordova({ sync: true })
static setLogLevel(logLevel: {
logLevel: number,
visualLevel: number
}): void { }
* The higher the value the more information is shown.
*
* @param {loglevel} contains two properties: logLevel (for console logging) and visualLevel (for dialog messages)
*/
@Cordova({ sync: true })
static setLogLevel(logLevel: {
logLevel: number,
visualLevel: number
}): void { }
} }