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.api.client.http.HttpTransport; | |
import com.google.api.client.http.javanet.NetHttpTransport; | |
import com.google.auth.http.HttpTransportFactory; | |
import com.google.auth.oauth2.GoogleCredentials; | |
import com.google.firebase.FirebaseApp; | |
import com.google.firebase.FirebaseOptions; | |
import com.google.firebase.messaging.FirebaseMessaging; | |
import com.google.firebase.messaging.Message; | |
import com.google.firebase.messaging.Notification; |
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 main | |
import ( | |
"context" | |
"log" | |
firebase "firebase.google.com/go" | |
"firebase.google.com/go/messaging" | |
) |
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'); | |
const HttpsProxyAgent = require('https-proxy-agent'); | |
const agent = new HttpsProxyAgent('http://localhost:3128'); | |
const app = admin.initializeApp({ | |
credential: admin.credential.applicationDefault(agent), | |
httpAgent: agent | |
}); | |
(async () => { | |
const db = admin.firestore(); |
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 firebase_admin | |
from firebase_admin import messaging | |
from firebase_admin import firestore | |
firebase_admin.initialize_app() | |
client = firestore.client() | |
snapshot = client.collection('users').document('alice').get() | |
data = snapshot.to_dict() | |
msg = messaging.Message( |
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
private val db = FirebaseFirestore.getInstance() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setupPriceListeners() | |
} | |
private fun setupPriceListeners() { | |
db.collection("prices") | |
.addSnapshotListener(EventListener<QuerySnapshot> { value, e -> |
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
private suspend fun savePref(currency: String, min: Double, max: Double) { | |
val instanceId = FirebaseInstanceId.getInstance().instanceId.await() | |
val data = mapOf( | |
"${currency}_min" to min, | |
"${currency}_max" to max, | |
"token" to instanceId.token | |
) | |
db.collection("prefs").document(instanceId.id) | |
.set(data, SetOptions.merge()).await() | |
} |
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() | |
} | |
} |
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
// 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
cron: | |
- description: "cryptocurrency price updater" | |
url: /fetch | |
schedule: every 30 minutes |