Skip to content

Commit

Permalink
use different api version for sms api;
Browse files Browse the repository at this point in the history
provide email adress as fallback name for email api;
  • Loading branch information
AlexanderProd committed Aug 28, 2024
1 parent 09efaf1 commit 8665b4a
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 18 deletions.
73 changes: 72 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
/target
# Created by https://www.toptal.com/developers/gitignore/api/rust,macos,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,macos,visualstudiocode

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/rust,macos,visualstudiocode
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure-communications"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "API Wrapper for the Azure Communication Services in Rust."
repository = "https://github.com/AlexanderProd/azure-communications-rust"
Expand Down
8 changes: 4 additions & 4 deletions examples/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ async fn main() {

let sender_adress = env::var("SENDER_ADDRESS").expect("Missing SENDER_ADDRESS");

let recipients = vec![Recipient {
address: env::var("RECIPIENT_ADDRESS").expect("Missing RECIPIENT_ADDRESS"),
display_name: None,
}];
let recipients = vec![Recipient::new(
&env::var("RECIPIENT_ADDRESS").expect("Missing RECIPIENT_ADDRESS"),
None,
)];

let az_communications = AzureCommunicationService::new(&connection_string, None);

Expand Down
2 changes: 0 additions & 2 deletions src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use time::OffsetDateTime;
pub mod email;
pub mod sms;

const AZURE_API_VERSION: &str = "2023-03-31";

#[derive(Debug, Clone)]
pub struct AzureCommunicationService {
pub endpoint: String,
Expand Down
6 changes: 4 additions & 2 deletions src/communication/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use serde_json::json;

use crate::types::Recipient;

use super::{AzureCommunicationService, AZURE_API_VERSION};
use super::AzureCommunicationService;

const API_VERSION: &str = "2023-03-31";

impl AzureCommunicationService {
pub async fn send_mail(
Expand All @@ -19,7 +21,7 @@ impl AzureCommunicationService {

let url = Url::parse(&format!(
"{}emails:send?api-version={}",
endpoint, AZURE_API_VERSION
endpoint, API_VERSION
))?;

let body = json!({
Expand Down
9 changes: 4 additions & 5 deletions src/communication/sms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use anyhow::Result;
use reqwest::Url;
use serde_json::json;

use super::{AzureCommunicationService, AZURE_API_VERSION};
use super::AzureCommunicationService;

const API_VERSION: &str = "2021-03-07";

impl AzureCommunicationService {
/// Message must not exceed 160 characters.
Expand All @@ -15,10 +17,7 @@ impl AzureCommunicationService {
) -> Result<()> {
let endpoint = &self.endpoint;

let url = Url::parse(&format!(
"{}sms?api-version={}",
endpoint, AZURE_API_VERSION
))?;
let url = Url::parse(&format!("{}sms?api-version={}", endpoint, API_VERSION))?;

let body = json!({
"from": sender_name,
Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Recipient {
pub address: String,
pub display_name: Option<String>,
pub display_name: String,
}

impl Recipient {
pub fn new(address: &str, display_name: Option<&str>) -> Self {
Recipient {
address: address.to_string(),
display_name: display_name.map(|s| s.to_string()),
display_name: display_name.unwrap_or(address).to_string(),
}
}
}

0 comments on commit 8665b4a

Please sign in to comment.