Skip to content

Commit

Permalink
fixing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
eklipse2k8 committed Mar 5, 2023
1 parent 2b94195 commit b349078
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
30 changes: 17 additions & 13 deletions rust-apns-core/examples/certificate_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use argparse::{ArgumentParser, Store, StoreOption, StoreTrue};
use rust_apns_core::{request::notification::AlertNotificationBuilder, Client, Endpoint, NotificationOptions};
use tokio;
use uuid::Uuid;

use rust_apns_core::{
client::{client::Client, Endpoint},
notification::AlertNotificationBuilder,
notification::PushNotification,
};

// An example client connectiong to APNs with a certificate and key
#[tokio::main]
Expand Down Expand Up @@ -38,7 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
{
// Which service to call, test or production?
let endpoint = if sandbox {
Endpoint::Sandbox
Endpoint::Development
} else {
Endpoint::Production
};
Expand All @@ -53,19 +59,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
};
let client = new_client()?;

let options = NotificationOptions {
apns_topic: topic.as_deref(),
..Default::default()
};

// Notification payload
let builder = AlertNotificationBuilder::default()
.body(message.as_ref())
.sound("default")
.badge(1u32)
.build()?;
let alert = PushNotification::Alert(
AlertNotificationBuilder::default()
.body(message)
.sound("default")
.badge(1u32)
.build()
.unwrap(),
);

let payload = builder.build(device_token.as_ref(), options);
let payload = alert.build_request(topic, None, device_token, Uuid::new_v4()).unwrap();
let response = client.send(payload).await?;

println!("Sent: {:?}", response);
Expand Down
28 changes: 14 additions & 14 deletions rust-apns-core/examples/token_client.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use argparse::{ArgumentParser, Store, StoreOption, StoreTrue};
use std::fs::File;
use tokio;
use uuid::Uuid;

use rust_apns_core::{
request::notification::AlertNotificationBuilder, Client, Endpoint, NotificationBuilder, NotificationOptions,
client::{client::Client, Endpoint},
notification::AlertNotificationBuilder,
notification::PushNotification,
};

// An example client connectiong to APNs with a JWT token
Expand Down Expand Up @@ -44,28 +47,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {

// Which service to call, test or production?
let endpoint = if sandbox {
Endpoint::Sandbox
Endpoint::Development
} else {
Endpoint::Production
};

// Connecting to APNs
let client = Client::token(&mut private_key, key_id, team_id, endpoint).unwrap();

let options = NotificationOptions {
apns_topic: topic.as_deref(),
..Default::default()
};

let alert = AlertNotificationBuilder::default().build();

// Notification payload
let builder = DefaultNotificationBuilder::new()
.set_body(message.as_ref())
.set_sound("default")
.set_badge(1u32);
let alert = PushNotification::Alert(
AlertNotificationBuilder::default()
.body(message)
.sound("default")
.badge(1u32)
.build()
.unwrap(),
);

let payload = builder.build(device_token.as_ref(), options);
let payload = alert.build_request(topic, None, device_token, Uuid::new_v4()).unwrap();
let response = client.send(payload).await?;

println!("Sent: {:?}", response);
Expand Down

0 comments on commit b349078

Please sign in to comment.