Skip to content

Commit

Permalink
GCF: Add Firebase remote config sample (#1860)
Browse files Browse the repository at this point in the history
* Add Firebase remote config sample

Change-Id: Ic894bdda8f749a3308dd63476bab3e3f64f89be4

* Fix docstring

Change-Id: Id5f20206cd45b14f22caa585a5aa10cdf71b93d1
  • Loading branch information
Ace Nassri authored Nov 22, 2018
1 parent 71b224c commit 44ea714
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 13 additions & 2 deletions functions/firebase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ def make_upper_case(data, context):

# [START functions_firebase_analytics]
def hello_analytics(data, context):
print(data)
print(context)
""" Triggered by a Google Analytics for Firebase log event.
Args:
data (dict): The event payload.
Expand All @@ -125,3 +123,16 @@ def hello_analytics(data, context):
geo_info = user_obj["geoInfo"]
print(f'Location: {geo_info["city"]}, {geo_info["country"]}')
# [END functions_firebase_analytics]


# [START functions_firebase_remote_config]
def hello_remote_config(data, context):
""" Triggered by a change to a Firebase Remote Config value.
Args:
data (dict): The event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
print(f'Update type: {data["updateType"]}')
print(f'Origin: {data["updateOrigin"]}')
print(f'Version: {data["versionNumber"]}')
# [END functions_firebase_remote_config]
17 changes: 17 additions & 0 deletions functions/firebase/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,20 @@ def test_analytics(capsys):
assert 'Name: my-event' in out
assert 'Device Model: Pixel' in out
assert 'Location: London, UK' in out


def test_remote_config(capsys):
data = {
'updateOrigin': 'CONSOLE',
'updateType': 'INCREMENTAL_UPDATE',
'versionNumber': '1'
}
context = Context()

main.hello_remote_config(data, context)

out, _ = capsys.readouterr()

assert 'Update type: INCREMENTAL_UPDATE' in out
assert 'Origin: CONSOLE' in out
assert 'Version: 1' in out

0 comments on commit 44ea714

Please sign in to comment.