Files
react-native-firebase/packages/admob/lib/AdsConsent.js
2019-08-09 08:19:04 +01:00

162 lines
4.3 KiB
JavaScript

/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { NativeModules } from 'react-native';
import { hasOwnProperty, isArray, isBoolean, isObject, isString, isUndefined } from '@react-native-firebase/common';
import AdsConsentDebugGeography from './AdsConsentDebugGeography';
import AdsConsentStatus from './AdsConsentStatus';
const native = NativeModules.RNFBAdmobConsentModule;
export default {
/**
*
* @param publisherIds
* @returns {*}
*/
requestInfoUpdate(publisherIds) {
if (!isArray(publisherIds)) {
throw new Error(
"firebase.admob.AdsConsent.requestInfoUpdate(*) 'publisherIds' expected an array of string values."
);
}
for (let i = 0; i < publisherIds.length; i++) {
if (!isString(publisherIds[i])) {
throw new Error(
`firebase.admob.AdsConsent.requestInfoUpdate(*) 'publisherIds[${i}]' expected a string value.`
);
}
}
return native.requestInfoUpdate(publisherIds);
},
/**
*
* @param options
* @returns {*}
*/
showForm(options) {
if (!isUndefined(options) && !isObject(options)) {
throw new Error(
"firebase.admob.AdsConsent.showForm(*) 'options' expected an object value."
);
}
// TODO
// if (!isValidUrl(options.privacyPolicy)) {
// throw new Error(
// "firebase.admob.AdsConsent.showForm(*) 'options.privacyPolicy' expected a valid HTTP or HTTPS URL."
// );
// }
if (hasOwnProperty(options, 'withPersonalizedAds') && !isBoolean(options.withPersonalizedAds)) {
throw new Error(
"firebase.admob.AdsConsent.showForm(*) 'options.withPersonalizedAds' expected a boolean value."
);
}
if (hasOwnProperty(options, 'withNonPersonalizedAds') && !isBoolean(options.withNonPersonalizedAds)) {
throw new Error(
"firebase.admob.AdsConsent.showForm(*) 'options.withNonPersonalizedAds' expected a boolean value."
);
}
if (hasOwnProperty(options, 'withAdFree') && !isBoolean(options.withAdFree)) {
throw new Error(
"firebase.admob.AdsConsent.showForm(*) 'options.withAdFree' expected a boolean value."
);
}
return native.showForm(options);
},
/**
*
*/
getAdProviders() {
return native.getAdProviders();
},
/**
*
* @param geography
*/
setDebugGeography(geography) {
if (
geography !== AdsConsentDebugGeography.DISABLED &&
geography !== AdsConsentDebugGeography.EEA &&
geography !== AdsConsentDebugGeography.NOT_EEA
) {
throw new Error(
"firebase.admob.AdsConsent.setDebugGeography(*) 'geography' expected one of AdsConsentDebugGeography.DISABLED, AdsConsentDebugGeography.EEA or AdsConsentDebugGeography.NOT_EEA."
);
}
return native.setDebugGeography(geography);
},
/**
*
* @param status
*/
setStatus(status) {
if (
status !== AdsConsentStatus.UNKNOWN &&
status !== AdsConsentStatus.PERSONALIZED &&
status !== AdsConsentStatus.UNPERSONALIZED
) {
throw new Error(
"firebase.admob.AdsConsent.setStatus(*) 'status' expected one of AdsConsentStatus.UNKNOWN, AdsConsentStatus.PERSONALIZED or AdsConsentStatus.UNPERSONALIZED."
);
}
return native.setStatus(status);
},
/**
*
* @param tag
*/
setTagForUnderAgeOfConsent(tag) {
if (!isBoolean(tag)) {
throw new Error(
"firebase.admob.AdsConsent.setTagForUnderAgeOfConsent(*) 'tag' expected a boolean value."
);
}
return native.setTagForUnderAgeOfConsent(tag);
},
/**
*
* @param deviceId
*/
addTestDevice(deviceId) {
if (!isString(deviceId)) {
throw new Error(
"firebase.admob.AdsConsent.addTestDevice(*) 'deviceId' expected a string value."
);
}
return native.addTestDevice(deviceId);
}
}