From 5e569b908f714daf58dc5c7991b6fe1c1c96ab15 Mon Sep 17 00:00:00 2001 From: William Shepherd Date: Fri, 9 Sep 2022 04:00:21 +0900 Subject: [PATCH 1/2] Add functions to support sending emails --- src/main.rs | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d938886..25a3b01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use onesignal::{ #[tokio::main] async fn main() { send_notification().await; + send_email().await; println!("Done"); } @@ -14,13 +15,18 @@ async fn main() { // API Client fn create_configuration() -> Box { let mut configuration = apis::configuration::Configuration::new(); - configuration.app_key_token = Some(String::from("APP_ID")); - configuration.user_key_token = Some(String::from("REST_API_KEY")); + configuration.app_key_token = Some(String::from( + "OGJlYzAxZDItYzA1Yy00ZDJlLWEzY2ItOTZmMTVjMmY1ZTM3", + )); + configuration.user_key_token = Some(String::from( + "NWE5NTJjMmMtMDcxMy00ZGJkLWFmY2MtZGM5N2E3OTEyNmY1 + ", + )); Box::new(configuration) } fn create_notification() -> Box { - let mut notification = Notification::new(String::from("APP_ID")); + let mut notification = Notification::new(String::from("b1ae09b2-5311-432e-b69c-65cb354f3472")); let mut string_map = StringMap::new(); string_map.en = Some(String::from("Rust test notification")); @@ -43,12 +49,42 @@ async fn send_notification() { // Check the result if let Ok(ref created_notification) = create_notification_response { - println!("Created notification id: {}", created_notification.id); + println!("Sent push notification: {}", created_notification.id); } if let Err(ref created_notification_error) = create_notification_response { println!( - "Created notification error: {}", + "Send push notification error: {}", + created_notification_error.to_string() + ); + } +} + +fn create_email() -> Box { + let mut email_notification = + Notification::new(String::from("b1ae09b2-5311-432e-b69c-65cb354f3472")); + + email_notification.email_subject = Some(String::from("Test from Rust")); + email_notification.email_body = Some(String::from("Sent from Rust!")); + email_notification.email_from_address = Some(String::from("william@onesignal.com")); + email_notification.included_segments = Some(vec![String::from("Email Users")]); + + Box::new(email_notification) +} + +async fn send_email() { + let config = create_configuration(); + let email = create_email(); + let create_notification_response = + apis::default_api::create_notification(&config, *email).await; + + if let Ok(ref created_notification) = create_notification_response { + println!("Sent email: {}", created_notification.id); + } + + if let Err(ref created_notification_error) = create_notification_response { + println!( + "Send email error: {}", created_notification_error.to_string() ); } From 30be1cf841362fff35fde775c9cef7a379ff2f20 Mon Sep 17 00:00:00 2001 From: William Shepherd Date: Tue, 13 Sep 2022 09:42:41 +0900 Subject: [PATCH 2/2] Add support section and other refinements --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 787bda4..c0cd4ef 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,9 @@ OneSignal makes engaging customers simple and is the fastest, most reliable serv This project demonstrates sending push notifications using the OneSignal Rust API client. You can use this project as a boilerplate or reference to start your project. - ## 🚦 Getting started -This project assumes that you already have a OneSignal app created with push notifications setup. If you don't yet have a OneSignal app, [create one](#) first, then follow the steps to [integrate the OneSignal SDK](#) into your Android or iOS app. +This project assumes that you already have a OneSignal app created with push notifications setup. If you don't yet have a OneSignal app, [create one](https://documentation.onesignal.com/docs/apps-organizations#create-an-app) first, then follow the steps to integrate the OneSignal SDK into your [Android](https://documentation.onesignal.com/docs/android-sdk-setup) or [iOS](https://documentation.onesignal.com/docs/ios-sdk-setup) app. ### Steps @@ -29,18 +28,32 @@ This project assumes that you already have a OneSignal app created with push not 2. Replace the variable descriptions with its respective value from your OneSignal app on the dashboard. 3. Run the command `cargo run` -## ❤️ Developer Community +# Support + +## Ask a question about OneSignal + +You can ask questions about the OneSignal xxx SDK and related topics in the onesignal-xxx-sdk repository. + +🙋‍♂️ [Ask a question](https://github.com/OneSignal/onesignal-rust-api/issues/new?assignees=&labels=triage&template=ask-question.yml&title=%5Bquestion%5D%3A+) + +## Create a bug report + +If you receive an error message or get blocked by an issue, please create a bug report! + +🪳 [Create bug report](https://github.com/OneSignal/onesignal-rust-api/issues/new?assignees=&labels=bug%2Ctriage&template=bug-report.yml&title=%5BBug%5D%3A+) + +# ❤️ Developer Community -Please join the [OneSignal Developer Community](https://onesignal.com/onesignal-developers) for additional resources. +For additional resources, please join the [OneSignal Developer Community](https://onesignal.com/onesignal-developers). -Get in touch with us or learn more about OneSignal through channels below. +Get in touch with us or learn more about OneSignal through the channels below. - [Follow us on Twitter](https://twitter.com/onesignaldevs) to never miss any updates from the OneSignal team, ecosystem & community - [Join us on Discord](https://discord.gg/EP7gf6Uz7G) to be a part of the OneSignal Developers community, showcase your work and connect with other OneSignal developers -- [OneSignal Blog](https://onesignal.com/blog/): Announcements, tutorials, in-depth articles & more -- [YouTube](https://www.youtube.com/channel/UCe63d5EDQsSkOov-bIE_8Aw/featured): Video walkthroughs, courses, talks, workshops & more -- [Twitch](https://www.twitch.tv/onesignaldevelopers): Livestreams, office hours, support & more +- [Read the OneSignal Blog](https://onesignal.com/blog/) for the latest announcements, tutorials, in-depth articles & more. +- [Subscribe to us on YouTube](https://www.youtube.com/channel/UCe63d5EDQsSkOov-bIE_8Aw/featured) for walkthroughs, courses, talks, workshops & more. +- [Follow us on Twitch](https://www.twitch.tv/onesignaldevelopers) for live streams, office hours, support & more. -### Show you support +## Show your support -Give a ⭐️ if this project helped you and watch this repo to stay up to date. +Give a ⭐️ if this project helped you, and watch this repo to stay up to date.