1 个不稳定版本
| 0.0.1 | 2021年12月14日 | 
|---|
#26 in #send-notifications
39 每月下载次数
18KB
373 行
firebase-client
使用google_authz库在Rust语言中实现的Firebase HTTP v1 客户端
示例
发送通知有两种方式,一种是通过通知构建器
// Get env vars from .env file
let credentials_file_path = std::env::var("CREDENTIALS_FILE_PATH").unwrap();
let project_id = std::env::var("PROJECT_ID").unwrap();
let test_token = std::env::var("TEST_TOKEN").unwrap();
// Instantiate our client
let https = HttpsConnector::with_native_roots();
let client = hyper::Client::builder().build::<_, Body>(https);
let firebase_client =
    FirebaseClient::new_default(client, &credentials_file_path, &project_id).unwrap();
// Build a notification
let mut firebase_notification = NotificationBuilder::new("TEST_TITLE", &test_token)
    .message("TEST_MESSAGE")
    .data(json!({
        "url": "https://firebase.google.com/docs/cloud-messaging/migrate-v1"
    }))
    .android_channel_id("channel_urgent")
    .build();
// Send a notification
firebase_notification.send_notification(firebase_notification).await().unwrap();
另一种是通过发送原始字符串
// Get env vars from .env file
let credentials_file_path = std::env::var("CREDENTIALS_FILE_PATH").unwrap();
let project_id = std::env::var("PROJECT_ID").unwrap();
let test_token = std::env::var("TEST_TOKEN").unwrap();
// Instantiate our client
let https = HttpsConnector::with_native_roots();
let client = hyper::Client::builder().build::<_, Body>(https);
let mut firebase_client =
    FirebaseClient::new_default(client, &credentials_file_path, &project_id).unwrap();
// Send notification directly
let _result = firebase_client
            .send_notification_raw(
                json!(
                {
                  "message":
                  {
                    "token": test_token,
                    "notification":
                        {
                            "title": "TEST_TITLE",
                            "body": "TEST_MESSAGE"
                        }
                  }
                }
                      )
                .to_string(),
            )
            .await;
依赖关系
~19–32MB
~568K SLoC