diff --git a/src/index.ts b/src/index.ts index 38781d5b7e..1c1a5756f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { AdMob } from './plugins/admob'; import { Alipay } from './plugins/alipay'; import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth'; import { AppAvailability } from './plugins/appavailability'; +import { Appodeal } from './plugins/appodeal'; import { AppRate } from './plugins/apprate'; import { AppUpdate } from './plugins/app-update'; import { AppVersion } from './plugins/appversion'; @@ -134,6 +135,7 @@ export * from './plugins/admob'; export * from './plugins/alipay'; export * from './plugins/android-fingerprint-auth'; export * from './plugins/appavailability'; +export * from './plugins/appodeal'; export * from './plugins/apprate'; export * from './plugins/app-update'; export * from './plugins/appversion'; @@ -262,6 +264,7 @@ window['IonicNative'] = { Alipay, AndroidFingerprintAuth, AppAvailability, + Appodeal, AppRate, AppUpdate, AppVersion, diff --git a/src/plugins/appodeal.ts b/src/plugins/appodeal.ts new file mode 100644 index 0000000000..2d3933f538 --- /dev/null +++ b/src/plugins/appodeal.ts @@ -0,0 +1,443 @@ +import { Plugin, Cordova } from './plugin'; +import { Observable } from 'rxjs'; + +/** + * @name Appodeal + * @description + * Plugin to serve ads through native Appodeal SDKs + * + * @usage + * ``` + * import { Appodeal } from 'ionic-native'; + * + * let appKey = ''; + * Appodeal.initialize(appKey, Appodeal.AD_TYPES.REWARDED_VIDEO); + * Appodeal.show(Appodeal.AD_TYPES.REWARDED_VIDEO); + * + * ``` + */ +@Plugin({ + pluginName: 'Appodeal', + plugin: 'https://github.com/appodeal/appodeal-cordova-plugin', + pluginRef: 'Appodeal', + repo: 'https://github.com/appodeal/appodeal-cordova-plugin.git', + platforms: [ 'ios', 'android' ] +}) +export class Appodeal { + // available types of advertisements + static readonly AD_TYPES = { + INTERSTITIAL: 1, + SKIPPABLE_VIDEO: 2, + BANNER: 4, + BANNER_BOTTOM: 8, + BANNER_TOP: 16, + REWARDED_VIDEO: 128, + NON_SKIPPABLE_VIDEO: 256 + }; + + /** + * initialize Appodeal SDK + * @param {string} appKey + * @param {number} adType + */ + @Cordova() + static initialize(appKey: string, adType: number): void {}; + + /** + * check if SDK has been initialized + * @returns {Promise} + */ + @Cordova() + static isInitialized(): Promise { return; }; + + /** + * show ad of specified type + * @param {number} adType + * @returns {Promise} + */ + @Cordova() + static show(adType: number): Promise { return; }; + + /** + * show ad of specified type with placement options + * @param {number} adType + * @param {any} placement + * @returns {Promise} + */ + @Cordova() + static showWithPlacement( + adType: number, + placement: any + ): Promise { return; }; + + /** + * hide ad of specified type + * @param {number} adType + */ + @Cordova() + static hide(adType: number): void {}; + + /** + * confirm use of ads of specified type + * @param {number} adType + */ + @Cordova() + static confirm(adType: number): void {}; + + /** + * check if ad of specified type has been loaded + * @param {number} adType + * @returns {Promise} + */ + @Cordova() + static isLoaded(adType: number): Promise { return; }; + + /** + * check if ad of specified + * @param {number} adType + * @returns {Promise} + */ + @Cordova() + static isPrecache(adType: number): Promise { return; }; + + /** + * + * @param {number} adType + * @param autoCache + */ + @Cordova() + static setAutoCache(adType: number, autoCache: any): void {}; + + /** + * forcefully cache an ad by type + * @param {number} adType + */ + @Cordova() + static cache(adType: number): void {}; + + /** + * + * @param {boolean} set + */ + @Cordova() + static setOnLoadedTriggerBoth(set: boolean): void {}; + + /** + * enable or disable Smart Banners + * @param {boolean} enabled + */ + @Cordova() + static setSmartBanners(enabled: boolean): void {}; + + /** + * enable or disable banner backgrounds + * @param {boolean} enabled + */ + @Cordova() + static setBannerBackground(enabled: boolean): void {}; + + /** + * enable or disable banner animations + * @param {boolean} enabled + */ + @Cordova() + static setBannerAnimation(enabled: boolean): void {}; + + /** + * + * @param value + */ + @Cordova() + static set728x90Banners(value: any): void {}; + + /** + * enable or disable logging + * @param {boolean} logging + */ + @Cordova() + static setLogging(logging: boolean): void {}; + + /** + * enable or disable testing mode + * @param {boolean} testing + */ + @Cordova() + static setTesting(testing: boolean): void {}; + + /** + * reset device ID + */ + @Cordova() + static resetUUID(): void {}; + + /** + * get version of Appdeal SDK + */ + @Cordova() + static getVersion(): Promise { return; }; + + /** + * + * @param {string} network + * @param {number} adType + */ + @Cordova() + static disableNetwork(network?: string, adType?: number): void {}; + + /** + * + * @param {string} network + * @param {number} adType + */ + @Cordova() + static disableNetworkType(network?: string, adType?: number): void {}; + + /** + * disable Location permissions for Appodeal SDK + */ + @Cordova() + static disableLocationPermissionCheck(): void {}; + + /** + * disable Storage permissions for Appodeal SDK + */ + @Cordova() + static disableWriteExternalStoragePermissionCheck(): void {}; + + /** + * enable event listeners + * @param {boolean} enabled + */ + @Cordova() + static enableInterstitialCallbacks(enabled: boolean): void {}; + + /** + * enable event listeners + * @param {boolean} enabled + */ + @Cordova() + static enableSkippableVideoCallbacks(enabled: boolean): void {}; + + /** + * enable event listeners + * @param {boolean} enabled + */ + @Cordova() + static enableNonSkippableVideoCallbacks(enabled: boolean): void {}; + + /** + * enable event listeners + * @param {boolean} enabled + */ + @Cordova() + static enableBannerCallbacks(enabled: boolean): void {}; + + /** + * enable event listeners + * @param {boolean} enabled + */ + @Cordova() + static enableRewardedVideoCallbacks(enabled: boolean): void {}; + + /** + * + * @param {string} name - name of rule + * @param {boolean} value + */ + @Cordova() + static setCustomBooleanRule(name: string, value: boolean): void {}; + + /** + * + * @param {string} name - name of rule + * @param {number} value + */ + @Cordova() + static setCustomIntegerRule(name: string, value: number): void {}; + + /** + * set rule with float value + * @param {string} name + * @param {number} value + */ + @Cordova() + static setCustomDoubleRule(name: string, value: number): void {}; + + /** + * set rule with string value + * @param {string} name - name of rule + * @param {string} value + */ + @Cordova() + static setCustomStringRule(name: string, value: string): void {}; + + /** + * set ID preference in Appodeal for current user + * @param id + */ + @Cordova() + static setUserId(id: any): void {}; + + /** + * set Email preference in Appodeal for current user + * @param email + */ + @Cordova() + static setEmail(email: any): void {}; + + /** + * set Birthday preference in Appodeal for current user + * @param birthday + */ + @Cordova() + static setBirthday(birthday: any): void {}; + + /** + * et Age preference in Appodeal for current user + * @param age + */ + @Cordova() + static setAge(age: any): void {}; + + /** + * set Gender preference in Appodeal for current user + * @param gender + */ + @Cordova() + static setGender(gender: any): void {}; + + /** + * set Occupation preference in Appodeal for current user + * @param occupation + */ + @Cordova() + static setOccupation(occupation: any): void {}; + + /** + * set Relation preference in Appodeal for current user + * @param relation + */ + @Cordova() + static setRelation(relation: any): void {}; + + /** + * set Smoking preference in Appodeal for current user + * @param smoking + */ + @Cordova() + static setSmoking(smoking: any): void {}; + + /** + * set Alcohol preference in Appodeal for current user + * @param alcohol + */ + @Cordova() + static setAlcohol(alcohol: any): void {}; + + /** + * set Interests preference in Appodeal for current user + * @param interests + */ + @Cordova() + static setInterests(interests: any): void {}; + + /********************* + * event Observables * + *********************/ + + static onInterstitialLoaded(): Observable { + return Observable.fromEvent(document, 'onInterstitialLoaded'); + } + + static onInterstitialFailedToLoad(): Observable { + return Observable.fromEvent(document, 'onInterstitialFailedToLoad'); + } + + static onInterstitialShown(): Observable { + return Observable.fromEvent(document, 'onInterstitialShown'); + } + + static onInterstitialClicked(): Observable { + return Observable.fromEvent(document, 'onInterstitialClicked'); + } + + static onInterstitialClosed(): Observable { + return Observable.fromEvent(document, 'onInterstitialClosed'); + } + + static onSkippableVideoLoaded(): Observable { + return Observable.fromEvent(document, 'onSkippableVideoLoaded'); + } + + static onSkippableVideoFailedToLoad(): Observable { + return Observable.fromEvent(document, 'onSkippableVideoFailedToLoad'); + } + + static onSkippableVideoShown(): Observable { + return Observable.fromEvent(document, 'onSkippableVideoShown'); + } + + static onSkippableVideoFinished(): Observable { + return Observable.fromEvent(document, 'onSkippableVideoFinished'); + } + + static onSkippableVideoClosed(): Observable { + return Observable.fromEvent(document, 'onSkippableVideoClosed'); + } + + static onRewardedVideoLoaded(): Observable { + return Observable.fromEvent(document, 'onRewardedVideoLoaded'); + } + + static onRewardedVideoFailedToLoad(): Observable { + return Observable.fromEvent(document, 'onRewardedVideoFailedToLoad'); + } + + static onRewardedVideoShown(): Observable { + return Observable.fromEvent(document, 'onRewardedVideoShown'); + } + + static onRewardedVideoFinished(): Observable { + return Observable.fromEvent(document, 'onRewardedVideoFinished'); + } + + static onRewardedVideoClosed(): Observable { + return Observable.fromEvent(document, 'onRewardedVideoClosed'); + } + + static onNonSkippableVideoLoaded(): Observable { + return Observable.fromEvent(document, 'onNonSkippableVideoLoaded'); + } + + static onNonSkippableVideoFailedToLoad(): Observable { + return Observable.fromEvent(document, 'onNonSkippableVideoFailedToLoad'); + } + + static onNonSkippableVideoShown(): Observable { + return Observable.fromEvent(document, 'onNonSkippableVideoShown'); + } + + static onNonSkippableVideoFinished(): Observable { + return Observable.fromEvent(document, 'onNonSkippableVideoFinished'); + } + + static onNonSkippableVideoClosed(): Observable { + return Observable.fromEvent(document, 'onNonSkippableVideoClosed'); + } + + static onBannerClicked(): Observable { + return Observable.fromEvent(document, 'onBannerClicked'); + } + + static onBannerFailedToLoad(): Observable { + return Observable.fromEvent(document, 'onBannerFailedToLoad'); + } + + static onBannerLoaded(): Observable { + return Observable.fromEvent(document, 'onBannerLoaded'); + } + + static onBannerShown(): Observable { + return Observable.fromEvent(document, 'onBannerShown'); + } +}