This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| admin.initializeApp(); | |
| const message = { | |
| data: { | |
| time: '1:15 PM', | |
| symbol: 'GOOG', | |
| value: '1184.46' | |
| }, | |
| tokens: [token1, token2, /* up to 100 tokens... */], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const admin = require('firebase-admin'); | |
| (async () => { | |
| admin.initializeApp(); | |
| const message = { | |
| data: { | |
| time: '1:15 PM', | |
| symbol: 'GOOG', | |
| value: '1184.46' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func ScoreReview(ctx context.Context, e FirestoreEvent) error { | |
| review := e.Value.Fields | |
| reviweScore := score(review.Text.Value) | |
| ref := client.NewRef("scores").Child(review.Author.Value) | |
| updateTxn := func(node db.TransactionNode) (interface{}, error) { | |
| var currentScore int | |
| if err := node.Unmarshal(¤tScore); err != nil { | |
| return nil, err | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scorer | |
| import ( | |
| "context" | |
| "log" | |
| "time" | |
| firebase "firebase.google.com/go" | |
| "firebase.google.com/go/db" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ( | |
| "context" | |
| "cloud.google.com/go/firestore" | |
| firebase "firebase.google.com/go" | |
| ) | |
| // FirebaseClient is a helper for interacting with Firebase services. | |
| type FirebaseClient struct { | |
| db *firestore.Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as functions from 'firebase-functions'; | |
| import * as admin from 'firebase-admin'; | |
| admin.initializeApp(); | |
| const firestore = admin.firestore(); | |
| export const sendCryptoAlerts = functions.firestore.document('prices/{currency}') | |
| .onUpdate(async (change, context) => { | |
| const currencyId: string = context.params.currency; | |
| const data = change.after.data(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cron: | |
| - description: "cryptocurrency price updater" | |
| url: /fetch | |
| schedule: every 30 minutes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Prices is a map of crypto currency prices. | |
| type Prices map[string]float64 | |
| // SavePrices saves the given crypto currency prices to the database. | |
| func (client *FirebaseClient) SavePrices(ctx context.Context, prices Prices) error { | |
| collection := client.db.Collection("prices") | |
| batch := client.db.Batch() | |
| for curr, price := range prices { | |
| batch.Set(collection.Doc(curr), map[string]interface{}{"value": price}, firestore.MergeAll) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.android.gms.tasks.Task | |
| import kotlinx.coroutines.experimental.suspendCancellableCoroutine | |
| suspend fun <T> Task<T>.await() = | |
| suspendCancellableCoroutine<T> { | |
| this.addOnSuccessListener(it::resume) | |
| this.addOnFailureListener(it::resumeWithException) | |
| this.addOnCanceledListener { it.cancel() } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CryptoAlertMessagingService: FirebaseMessagingService() { | |
| override fun onMessageReceived(message: RemoteMessage?) { | |
| message?.notification?.let { | |
| Log.d(TAG, "Message Notification Body: ${it.body}") | |
| val mainHandler = Handler(mainLooper) | |
| mainHandler.post { | |
| Toast.makeText(applicationContext, "${it.body}", Toast.LENGTH_SHORT).show() | |
| } | |
| } |