Skip to content

Commit 44ea714

Browse files
author
Ace Nassri
authored
GCF: Add Firebase remote config sample (GoogleCloudPlatform#1860)
* Add Firebase remote config sample Change-Id: Ic894bdda8f749a3308dd63476bab3e3f64f89be4 * Fix docstring Change-Id: Id5f20206cd45b14f22caa585a5aa10cdf71b93d1
1 parent 71b224c commit 44ea714

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

functions/firebase/main.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ def make_upper_case(data, context):
103103

104104
# [START functions_firebase_analytics]
105105
def hello_analytics(data, context):
106-
print(data)
107-
print(context)
108106
""" Triggered by a Google Analytics for Firebase log event.
109107
Args:
110108
data (dict): The event payload.
@@ -125,3 +123,16 @@ def hello_analytics(data, context):
125123
geo_info = user_obj["geoInfo"]
126124
print(f'Location: {geo_info["city"]}, {geo_info["country"]}')
127125
# [END functions_firebase_analytics]
126+
127+
128+
# [START functions_firebase_remote_config]
129+
def hello_remote_config(data, context):
130+
""" Triggered by a change to a Firebase Remote Config value.
131+
Args:
132+
data (dict): The event payload.
133+
context (google.cloud.functions.Context): Metadata for the event.
134+
"""
135+
print(f'Update type: {data["updateType"]}')
136+
print(f'Origin: {data["updateOrigin"]}')
137+
print(f'Version: {data["versionNumber"]}')
138+
# [END functions_firebase_remote_config]

functions/firebase/main_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,20 @@ def test_analytics(capsys):
148148
assert 'Name: my-event' in out
149149
assert 'Device Model: Pixel' in out
150150
assert 'Location: London, UK' in out
151+
152+
153+
def test_remote_config(capsys):
154+
data = {
155+
'updateOrigin': 'CONSOLE',
156+
'updateType': 'INCREMENTAL_UPDATE',
157+
'versionNumber': '1'
158+
}
159+
context = Context()
160+
161+
main.hello_remote_config(data, context)
162+
163+
out, _ = capsys.readouterr()
164+
165+
assert 'Update type: INCREMENTAL_UPDATE' in out
166+
assert 'Origin: CONSOLE' in out
167+
assert 'Version: 1' in out

0 commit comments

Comments
 (0)