Skip to content

Instantly share code, notes, and snippets.

View PetkevichPavel's full-sized avatar
💭
🚀 Never Stop 🚀

Pavel Petkevich PetkevichPavel

💭
🚀 Never Stop 🚀
View GitHub Profile
@PetkevichPavel
PetkevichPavel / RemoteConfigObj.ts
Created August 21, 2019 22:09
Cloud Function: The class with all the objects which we will need in the future parsing remote config json.
export interface RemoteConfigObj {
parameters: Parameter;
version: Version;
}
export interface Parameter {
platform_setting: PlatformSettingsRC
}
export interface PlatformSettingsRC {
defaultValue: DefValue
}
@PetkevichPavel
PetkevichPavel / SecretPropertie.ts
Created August 24, 2019 08:00
Cloud Function: secret properties for functions.
export const DB_URL = "https://projec-name.firebaseio.com"
export const SCOPES = ["https://www.googleapis.com/auth/firebase.remoteconfig"];
export const FB_URL_RC =
"https://firebaseremoteconfig.googleapis.com/v1/projects/projec-name/remoteConfig"
export const service: any = {
"type": "service_account",
"project_id": "********************",
"private_key_id": "********************",
"private_key": "********************",
"client_email": "********************",
@PetkevichPavel
PetkevichPavel / RemoteConfigFunctions.ts
Last active August 24, 2019 08:06
Cloud function: class with helpful functions.
import { PlatformSettingsObj, PushTopics, Platform } from './RemoteConfigObj';
import { SCOPES } from '../SecretProperties';
const { google } = require('googleapis');
/**
* This method is for requesting an access token.
* @param service - is the service account data.
*/
export function getAccessToken(service: any) {
return new Promise(function (resolve, reject) {
const jwtClient = new google.auth.JWT(
@PetkevichPavel
PetkevichPavel / index.ts
Last active August 24, 2019 08:14
Cloud function: common class.
"use strict";
import functions = require("firebase-functions");
import admin = require("firebase-admin");
import * as rcFunctions from './RemoteConfigFunctions';
import { RemoteConfigObj } from "./RemoteConfigObj";
import * as secretProps from '../SecretProperties';
const request = require('request');
const STATUS_CODE_OK = 200
Object.defineProperty(exports, "__esModule", { value: true });
admin.initializeApp({
@PetkevichPavel
PetkevichPavel / App.kt
Last active August 28, 2019 15:30
AN_Cloud Function: Application class.
override fun onCreate() {
super.onCreate()
initFirebase()
this.getRCF().setDefaultRC()
}
private fun initFirebase() {
FirebaseApp.initializeApp(this)
firebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
val configSettings = FirebaseRemoteConfigSettings.Builder()
.setFetchTimeoutInSeconds(0)
@PetkevichPavel
PetkevichPavel / AppExtension.kt
Created August 24, 2019 08:17
AN_Cloud Function: App extension class.
/**
* App extension function, which return reference on RemoteConfigFunctions.
* @return reference on RemoteConfigFunctions.
*/
fun App.getRCF() = RemoteConfigFunctions(gson, this, this, remoteConfigManager)
@PetkevichPavel
PetkevichPavel / FCMService.kt
Created August 24, 2019 08:20
AN_Cloud Function: Firebase Messaging Service for processing the notifications.
class FCMService : FirebaseMessagingService() {
companion object {
private const val TAG = "FCMService"
private const val RECEIVER_TAG = "Receiver:"
const val IN_AP_EX_STR_TITLE = "in_ap_ex_str_title"
const val IN_AP_EX_STR_BODY = "in_ap_ex_str_body"
}
@SuppressLint("TimberArgCount")
@PetkevichPavel
PetkevichPavel / BaseActivity.kt
Created August 24, 2019 08:22
AN_Cloud Function: Base activity of the application.
abstract class BaseActivity : AppCompatActivity() {
companion object {
private const val TAG = "BaseActivity:"
private const val RECEIVER_TAG = "BaseActivity-Receiver:"
}
private val localBroadcastManager: LocalBroadcastManager by lazy {
LocalBroadcastManager.getInstance(this)
}
@PetkevichPavel
PetkevichPavel / MainActivity.kt
Last active August 24, 2019 08:27
AN_Cloud Function: Example of handleRcUpdate override in MainActivity.
override fun handleRcUpdate(isItServiceUpdate: Boolean,
isFeatureOnBoardingVisible: Boolean) {
super.handleRcUpdate(isItServiceUpdate, isFeatureOnBoardingVisible)
when {
isItServiceUpdate -> updateUrls()
isFeatureOnBoardingVisible ->
navigateToOnBoardingMenu(true)
}
}
@PetkevichPavel
PetkevichPavel / RemoteConfigConstants.kt
Last active August 24, 2019 08:29
An_Cloud Function: Class for Remote Config constants.
class RemoteConfigConstants {
companion object {
const val DEFAULT_LOCAL_RC_JSON = "RemoteConfig.json"
const val LOCAL_RC_JSON = "DeviceRemoteConfig.json"
const val RC_JSON_PARAM_NAME = "config_json"
const val RC_EXTRA_BACK_NOTIFICATION = "rc_extra_back_notification"
}
}