Skip to content

Commit

Permalink
Merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed Feb 7, 2017
1 parent 9e379e6 commit 5b5058e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/certificate_client.rs
Expand Up @@ -35,7 +35,7 @@ fn main() {
let client = CertificateClient::new(sandbox, &mut cert_file, &mut key_file).unwrap();

// APNs payload
let payload = Payload::new(APSAlert::Plain(message), 1u32, "default", None, None);
let payload = Payload::new(APSAlert::Plain(message), "default", Some(1u32), None, None);

let options = NotificationOptions {
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/token_client.rs
Expand Up @@ -43,7 +43,7 @@ fn main() {
let client = TokenClient::new(sandbox, &ca_certs).unwrap();

// APNs payload
let payload = Payload::new(APSAlert::Plain(message), 1u32, "default", None, None);
let payload = Payload::new(APSAlert::Plain(message), "default", Some(1u32), None, None);

let options = NotificationOptions {
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion src/client/certificate.rs
Expand Up @@ -38,7 +38,7 @@ pub struct CertificateClient {
///
/// let client = CertificateClient::new(false, &mut cert_file, &mut key_file).unwrap();
/// let alert = APSAlert::Plain(String::from("Hi there!"));
/// let payload = Payload::new(alert, 1u32, "default", None, None);
/// let payload = Payload::new(alert, "default", Some(1u32), None, None);
/// let options = NotificationOptions { ..Default::default() };
/// let request = client.push(Notification::new(payload, "apple_device_token", options));
///
Expand Down
2 changes: 1 addition & 1 deletion src/client/token.rs
Expand Up @@ -40,7 +40,7 @@ pub struct TokenClient {
/// let client = TokenClient::new(false, "/etc/ssl/certs/ca-certificates.crt").unwrap();
///
/// let alert = APSAlert::Plain(String::from("Hi there!"));
/// let payload = Payload::new(alert, 1u32, "default", None, None);
/// let payload = Payload::new(alert, "default", Some(1u32), None, None);
/// let options = NotificationOptions { ..Default::default() };
/// let request = client.push(Notification::new(payload, "Hi there!", options), apns_token.signature());
///
Expand Down
12 changes: 1 addition & 11 deletions src/notification.rs
Expand Up @@ -16,7 +16,7 @@ pub struct Notification<'a> {
}

impl<'a> Notification<'a> {
pub fn new(payload: Payload<'a>, token: DeviceToken<'a>, options: NotificationOptions<'a>) -> Notification<'a> {
pub fn new(payload: Payload, token: &'a str, options: NotificationOptions<'a>) -> Notification<'a> {
Notification {
payload: payload,
device_token: token,
Expand Down Expand Up @@ -51,13 +51,3 @@ impl<'a> Default for NotificationOptions<'a> {
}
}
}

impl<'a> Notification<'a> {
pub fn new(payload: Payload, token: &'a str, options: NotificationOptions<'a>) -> Notification<'a> {
Notification {
payload: payload,
device_token: token,
options: options,
}
}
}
54 changes: 12 additions & 42 deletions src/payload.rs
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::collections::BTreeMap;
use rustc_serialize::json::{Json, ToJson};

Expand All @@ -10,46 +9,17 @@ pub struct Payload {
pub custom: Option<CustomData>,
}

pub struct APS {
pub alert: Option<APSAlert>,

/// The number to display as the badge of the app icon.
pub badge: Option<u32>,

/// The name of a sound file in the app bundle or in the Library/Sounds folder of
/// the app’s data container.
pub sound: Option<String>,

/// Provide this key with a value of 1 to indicate that new content is available.
pub content_available: Option<u32>,

/// Provide this key with a string value that represents the identifier property.
pub category: Option<String>,
}

pub enum APSAlert {
Plain(String),
Localized(APSLocalizedAlert),
}

pub struct APSLocalizedAlert {
pub title: String,
pub body: String,
pub title_loc_key: Option<String>,
pub title_loc_args: Option<Vec<String>>,
pub action_loc_key: Option<String>,
pub loc_key: Option<String>,
pub loc_args: Option<Vec<String>>,
pub launch_image: Option<String>,
}

pub struct CustomData {
/// The JSON root key for app specific custom data.
pub key: String,

/// The custom data.
pub body: Json,
}

impl Payload {
pub fn new<S>(alert: APSAlert, badge: u32, sound: S, category: Option<String>, custom_data: Option<CustomData>) -> Payload
pub fn new<S>(alert: APSAlert, sound: S, badge: Option<u32>, category: Option<String>,
custom_data: Option<CustomData>) -> Payload
where S: Into<String>
{
Payload {
Expand Down Expand Up @@ -86,7 +56,7 @@ impl Payload {
}
}

impl<'a> ToJson for Payload<'a> {
impl ToJson for Payload {
fn to_json(&self) -> Json {
let mut d = BTreeMap::new();
d.insert("aps".to_string(), self.aps.to_json());
Expand All @@ -103,7 +73,7 @@ impl<'a> ToJson for Payload<'a> {
/// - an alert message to display to the user
/// - a number to badge the app icon with
/// - a sound to play
pub struct APS<'a> {
pub struct APS {
/// If this property is included, the system displays a standard alert or a banner,
/// based on the user’s setting.
pub alert: Option<APSAlert>,
Expand All @@ -113,16 +83,16 @@ pub struct APS<'a> {

/// The name of a sound file in the app bundle or in the Library/Sounds folder of
/// the app’s data container.
pub sound: Option<Cow<'a, str>>,
pub sound: Option<String>,

/// Provide this key with a value of 1 to indicate that new content is available.
pub content_available: Option<u32>,

/// Provide this key with a string value that represents the identifier property.
pub category: Option<Cow<'a, str>>,
pub category: Option<String>,
}

impl<'a> ToJson for APS<'a> {
impl ToJson for APS {
fn to_json(&self) -> Json {
let mut d = BTreeMap::new();
match self.alert {
Expand Down Expand Up @@ -174,10 +144,10 @@ pub struct APSLocalizedAlert {
pub action_loc_key: Option<String>,

/// A key to an alert-message string in a Localizable.strings file for the current localization.
pub loc_key: String,
pub loc_key: Option<String>,

/// Variable string values to appear in place of the format specifiers in loc-key.
pub loc_args: Vec<String>,
pub loc_args: Option<Vec<String>>,

/// The filename of an image file in the app bundle.
/// The image is used as the launch image when users tap the action button or move the action slider.
Expand Down

0 comments on commit 5b5058e

Please sign in to comment.