Skip to content

Commit d1ee994

Browse files
authored
Merge pull request #10 from strosek/feat/add-tfa
Add 2FA endpoints
2 parents 87f4435 + 43d1319 commit d1ee994

File tree

22 files changed

+2745
-637
lines changed

22 files changed

+2745
-637
lines changed

.cspell.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@
33
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
44
"language": "en",
55
"words": [
6+
"DTMF",
7+
"ENROUTE",
8+
"Istarska",
9+
"MULTIPRODUCT",
10+
"Multiproduct",
11+
"Structs",
12+
"Vodnjan",
13+
"aabe",
14+
"bpgk",
15+
"chrono",
16+
"dtmf",
17+
"httpmock",
18+
"ibsso",
19+
"ijkl",
620
"infobip",
7-
"ibsso"
21+
"msisdn",
22+
"norun",
23+
"reqwest",
24+
"rustc",
25+
"thiserror",
26+
"xihiy",
27+
"yirml",
28+
"áéíø"
829
],
930
"flagWords": [],
1031
"patterns": [

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ homepage = "https://www.infobip.com/"
77
license = "MIT OR Apache-2.0"
88
name = "infobip_sdk"
99
repository = "https://github.com/infobip-community/infobip-api-rust-sdk"
10-
version = "0.4.0"
10+
version = "0.5.0"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
dotenv = "0.15.0"
15+
cargo_metadata = "0.15"
1616
lazy_static = "1.4"
17-
regex = "1.6"
17+
regex = "1.7"
1818
reqwest = { version = "0.11", features = ["blocking", "json", "multipart"] }
19+
rustc_version = "0.4"
1920
serde = { version = "1.0", features = ["derive"] }
2021
serde_derive = "1.0"
2122
serde_json = "1.0"

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
# Infobip API Rust SDK
22

33
![Workflow](https://github.com/infobip-community/infobip-api-rust-sdk/actions/workflows/rust.yml/badge.svg)
4-
[![Licence](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-MIT)
5-
[![Licence](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-APACHE)
4+
[![License](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-MIT)
5+
[![License](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-APACHE)
66
[![Crates.io](https://img.shields.io/crates/v/infobip_sdk)](https://crates.io/crates/infobip_sdk)
7-
![Crate downlads](https://img.shields.io/crates/d/rust_sdk)
7+
![Crate downloads](https://img.shields.io/crates/d/rust_sdk)
88

99
Client SDK to use the Infobip API with pure Rust.
1010

11-
This crate enables you to use multiple Infobip communication channels, like SMS, MMS,
11+
This crate enables you to use multiple Infobip communication channels, like SMS, 2FA,
1212
WhatsApp, Email, etc. It abstracts the needed HTTP calls, models and validates payloads and
1313
models errors. The module structure is divided by communication channel.
1414

1515
---
1616

1717
## 📡 Supported Channels
18-
- [SMS](https://www.infobip.com/docs/api/channels/sms)
18+
Currently, we support the following channels:
19+
- [SMS + 2FA](https://www.infobip.com/docs/api/channels/sms)
1920
- [WhatsApp](https://www.infobip.com/docs/api/channels/whatsapp)
2021
- [Email](https://www.infobip.com/docs/api/channels/email)
2122

22-
More Channels to be added in the near future!
23+
More channels to be added in the near future!
2324

2425
## 🔐 Authentication
2526
To use the library, you'll need to set up an [Infobip account](https://www.infobip.com/signup).
2627
Then you can use your API Key and custom base URL to call the endpoints. You can use the
2728
`Configuration::from_env_api_key()` method to load the configuration from the environment. To
28-
do that, set the `IB_API_KEY` and `IB_BASE_URL` variables. Alternatively, you can use the
29-
`Configuration::from_dotenv_api_key()` method to load the configuration from a `.env` file.
29+
do that, set the `IB_API_KEY` and `IB_BASE_URL` variables.
3030

3131
## 📦 Installation
32-
To use the library, add the dependency to your projects `Cargo.toml`
32+
To install the library, run the following command under your project's root directory:
33+
```bash
34+
cargo add infobip_sdk
35+
```
36+
Alternatively, you can add the dependency to your project's `Cargo.toml`
3337
```toml
3438
[dependencies]
3539
infobip_sdk = "<version>"
3640
```
37-
Replace <version> is the latest (or desired) release of the library. For example `0.2.0`.
41+
Replace `<version>` with the latest (or desired) release of the library. For example `0.5.0`.
3842

3943
## 🚀 Usage
4044
To use the library, import the client and channel-specific models. Then create a client and
@@ -54,7 +58,7 @@ async fn main() {
5458

5559
// Create a message.
5660
let mut message = Message::new(
57-
vec![Destination::new("123456789012".to_string())]
61+
vec![Destination::new("123456789012")]
5862
);
5963
message.text = Some("Your message text".to_string());
6064

@@ -84,7 +88,7 @@ provided `new()` functions, with `serde_json::from_str()`, or with the true cons
8488
For example, to build a `Message` instance, you can do this:
8589
```rust
8690
let mut message = Message::new(
87-
vec![Destination::new("123456789012".to_string())]
91+
vec![Destination::new("123456789012")]
8892
);
8993
message.text = Some("Your message text".to_string());
9094
```
@@ -138,7 +142,7 @@ model.
138142
You can speed up compile time by turning only the needed channels as library features.
139143
For example, to only build SMS, add the dependency like this:
140144
```toml
141-
infobip_sdk = { version = "0.3", features = ["sms"] }
145+
infobip_sdk = { version = "0.5", features = ["sms"] }
142146
```
143147
You can see the complete list of features in the Cargo.toml of the project. Feature names
144148
follow channel names.

README.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Infobip API Rust SDK
22

33
![Workflow](https://github.com/infobip-community/infobip-api-rust-sdk/actions/workflows/rust.yml/badge.svg)
4-
[![Licence](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-MIT)
5-
[![Licence](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-APACHE)
4+
[![License](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-MIT)
5+
[![License](https://img.shields.io/github/license/infobip-community/infobip-api-rust-sdk)](LICENSE-APACHE)
66
[![Crates.io](https://img.shields.io/crates/v/infobip_sdk)](https://crates.io/crates/infobip_sdk)
7-
![Crate downlads](https://img.shields.io/crates/d/rust_sdk)
7+
![Crate downloads](https://img.shields.io/crates/d/rust_sdk)
88

99
{{readme}}
1010

src/api/email.rs

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ impl EmailClient {
159159
/// #
160160
/// # #[tokio::main]
161161
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
162-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
162+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
163163
///
164-
/// let mut request_body = SendRequestBody::new("[email protected]".to_string());
164+
/// let mut request_body = SendRequestBody::new("[email protected]");
165165
/// request_body.from = Some("[email protected]".to_string());
166166
/// request_body.subject = Some("Test subject".to_string());
167167
/// request_body.text = Some("Hello world!".to_string());
@@ -213,9 +213,9 @@ impl EmailClient {
213213
/// #
214214
/// # #[tokio::main]
215215
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
216-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
216+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
217217
///
218-
/// let query_parameters = GetBulksQueryParameters::new("some-bulk-id".to_string());
218+
/// let query_parameters = GetBulksQueryParameters::new("some-bulk-id");
219219
///
220220
/// let response = client.get_bulks(query_parameters).await?;
221221
///
@@ -264,10 +264,10 @@ impl EmailClient {
264264
/// #
265265
/// # #[tokio::main]
266266
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
267-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
267+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
268268
///
269-
/// let query_params = RescheduleQueryParameters::new("test-bulk-id-rust-003".to_string());
270-
/// let request_body = RescheduleRequestBody::new("2022-10-05T17:29:52Z".to_string());
269+
/// let query_params = RescheduleQueryParameters::new("test-bulk-id-rust-003");
270+
/// let request_body = RescheduleRequestBody::new("2022-10-05T17:29:52Z");
271271
///
272272
/// let response = client.reschedule(query_params, request_body).await?;
273273
///
@@ -318,9 +318,9 @@ impl EmailClient {
318318
/// #
319319
/// # #[tokio::main]
320320
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
321-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
321+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
322322
///
323-
/// let query_params = GetScheduledStatusQueryParameters::new("some-bulk-id".to_string());
323+
/// let query_params = GetScheduledStatusQueryParameters::new("some-bulk-id");
324324
///
325325
/// let response = client.get_scheduled_status(query_params).await?;
326326
///
@@ -369,9 +369,9 @@ impl EmailClient {
369369
/// #
370370
/// # #[tokio::main]
371371
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
372-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
372+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
373373
///
374-
/// let query_params = UpdateScheduledStatusQueryParameters::new("some-bulk-id".to_string());
374+
/// let query_params = UpdateScheduledStatusQueryParameters::new("some-bulk-id");
375375
/// let request_body = UpdateScheduledStatusRequestBody::new(BulkStatus::CANCELED);
376376
///
377377
/// let response = client.update_scheduled_status(query_params, request_body).await?;
@@ -423,7 +423,7 @@ impl EmailClient {
423423
/// #
424424
/// # #[tokio::main]
425425
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
426-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
426+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
427427
///
428428
/// let query_params = GetDeliveryReportsQueryParameters::default();
429429
///
@@ -484,7 +484,7 @@ impl EmailClient {
484484
/// #
485485
/// # #[tokio::main]
486486
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
487-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
487+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
488488
///
489489
/// let query_params = GetLogsQueryParameters::default();
490490
///
@@ -559,9 +559,9 @@ impl EmailClient {
559559
/// #
560560
/// # #[tokio::main]
561561
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
562-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
562+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
563563
///
564-
/// let request_body = ValidateAddressRequestBody::new("[email protected]".to_string());
564+
/// let request_body = ValidateAddressRequestBody::new("[email protected]");
565565
///
566566
/// let response = client.validate_address(request_body).await?;
567567
///
@@ -608,7 +608,7 @@ impl EmailClient {
608608
/// #
609609
/// # #[tokio::main]
610610
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
611-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
611+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
612612
///
613613
/// let query_params = GetDomainsQueryParameters::default();
614614
///
@@ -666,9 +666,9 @@ impl EmailClient {
666666
/// #
667667
/// # #[tokio::main]
668668
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
669-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
669+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
670670
///
671-
/// let request_body = AddDomainRequestBody::new("example.com".to_string());
671+
/// let request_body = AddDomainRequestBody::new("example.com");
672672
///
673673
/// let response = client.add_domain(request_body).await?;
674674
///
@@ -714,19 +714,19 @@ impl EmailClient {
714714
/// #
715715
/// # #[tokio::main]
716716
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
717-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
717+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
718718
///
719-
/// let response = client.get_domain("example.com".to_string()).await?;
719+
/// let response = client.get_domain("example.com").await?;
720720
///
721721
/// assert_eq!(response.status, StatusCode::OK);
722722
/// # Ok(())
723723
/// # }
724724
/// ```
725725
pub async fn get_domain(
726726
&self,
727-
domain_name: String,
727+
domain_name: &str,
728728
) -> Result<SdkResponse<GetDomainResponseBody>, SdkError> {
729-
let path = PATH_GET_DOMAIN.replace("{domainName}", domain_name.as_str());
729+
let path = PATH_GET_DOMAIN.replace("{domainName}", domain_name);
730730

731731
let response = send_no_body_request(
732732
&self.client,
@@ -760,19 +760,16 @@ impl EmailClient {
760760
/// #
761761
/// # #[tokio::main]
762762
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
763-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
763+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
764764
///
765-
/// let status = client.delete_domain("example.com".to_string()).await?;
765+
/// let status = client.delete_domain("example.com").await?;
766766
///
767767
/// assert_eq!(status, StatusCode::NO_CONTENT);
768768
/// # Ok(())
769769
/// # }
770770
/// ```
771-
pub async fn delete_domain(
772-
&self,
773-
domain_name: String,
774-
) -> Result<reqwest::StatusCode, SdkError> {
775-
let path = PATH_DELETE_DOMAIN.replace("{domainName}", domain_name.as_str());
771+
pub async fn delete_domain(&self, domain_name: &str) -> Result<reqwest::StatusCode, SdkError> {
772+
let path = PATH_DELETE_DOMAIN.replace("{domainName}", domain_name);
776773

777774
let response = send_no_body_request(
778775
&self.client,
@@ -805,23 +802,23 @@ impl EmailClient {
805802
/// #
806803
/// # #[tokio::main]
807804
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
808-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
805+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
809806
///
810807
/// let mut request_body = UpdateTrackingRequestBody::default();
811808
/// request_body.clicks = Some(true);
812809
///
813-
/// let response = client.update_tracking("domain.com".to_string(), request_body).await?;
810+
/// let response = client.update_tracking("domain.com", request_body).await?;
814811
///
815812
/// assert_eq!(response.status, StatusCode::OK);
816813
/// # Ok(())
817814
/// # }
818815
/// ```
819816
pub async fn update_tracking(
820817
&self,
821-
domain_name: String,
818+
domain_name: &str,
822819
request_body: UpdateTrackingRequestBody,
823820
) -> Result<SdkResponse<UpdateTrackingResponseBody>, SdkError> {
824-
let path = PATH_UPDATE_TRACKING.replace("{domainName}", domain_name.as_str());
821+
let path = PATH_UPDATE_TRACKING.replace("{domainName}", domain_name);
825822

826823
let response = send_valid_json_request(
827824
&self.client,
@@ -856,19 +853,16 @@ impl EmailClient {
856853
/// #
857854
/// # #[tokio::main]
858855
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
859-
/// let client = EmailClient::with_configuration(Configuration::from_dotenv_api_key()?);
856+
/// let client = EmailClient::with_configuration(Configuration::from_env_api_key()?);
860857
///
861-
/// let status = client.verify_domain("example.com".to_string()).await?;
858+
/// let status = client.verify_domain("example.com").await?;
862859
///
863860
/// assert_eq!(status, StatusCode::ACCEPTED);
864861
/// # Ok(())
865862
/// # }
866863
/// ```
867-
pub async fn verify_domain(
868-
&self,
869-
domain_name: String,
870-
) -> Result<reqwest::StatusCode, SdkError> {
871-
let path = PATH_VERIFY_DOMAIN.replace("{domainName}", domain_name.as_str());
864+
pub async fn verify_domain(&self, domain_name: &str) -> Result<reqwest::StatusCode, SdkError> {
865+
let path = PATH_VERIFY_DOMAIN.replace("{domainName}", domain_name);
872866

873867
let response = send_no_body_request(
874868
&self.client,

0 commit comments

Comments
 (0)