Skip to content

Commit a9f3037

Browse files
authored
Merge pull request #6 from infobip-community/add-whatsapp
Add Whatsapp support
2 parents 5cf14eb + 8cd2d90 commit a9f3037

File tree

15 files changed

+5445
-97
lines changed

15 files changed

+5445
-97
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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.1.1"
10+
version = "0.2.0"
1111

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

@@ -19,7 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
1919
serde_derive = "1.0"
2020
serde_json = "1.0"
2121
thiserror = "1.0"
22-
tokio = { version = "1.20", features = ["full"] }
22+
tokio = { version = "1.21", features = ["full"] }
2323
validator = { version = "0.16", features = ["derive"] }
2424

2525
[dev-dependencies]

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22

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

89
Client SDK to use the Infobip API with pure Rust.
910

10-
This library enables you to use multiple Infobip communication channels, like SMS, MMS,
11-
Whatsapp, Email, etc. It abstracts the needed HTTP calls, and models payloads and error
12-
handling. The module structure is divided by communication channel.
11+
This crate enables you to use multiple Infobip communication channels, like SMS, MMS,
12+
WhatsApp, Email, etc. It abstracts the needed HTTP calls, models and validates payloads and
13+
models errors. The module structure is divided by communication channel.
1314

1415
---
1516

1617
## 📡 Supported Channels
1718
- [SMS](https://www.infobip.com/docs/api/channels/sms)
18-
- [WhatsApp](https://www.infobip.com/docs/api/channels/whatsapp) (partially, in progress)
19+
- [WhatsApp](https://www.infobip.com/docs/api/channels/whatsapp)
1920

2021
More Channels to be added in the near future!
2122

2223
## 🔐 Authentication
23-
To use the library, you'll need to set up an Infobip account. Then you can use your API Key and
24-
custom URL to call the endpoints. You can use the `Configuration::from_env_api_key()` method to
25-
load the configuration from the environment. To do that, export the variables `IB_API_KEY` and
26-
`IB_BASE_URL`.
24+
To use the library, you'll need to set up an [Infobip account](https://www.infobip.com/signup).
25+
Then you can use your API Key and custom base URL to call the endpoints. You can use the
26+
`Configuration::from_env_api_key()` method to load the configuration from the environment. To
27+
do that, set the `IB_API_KEY` and `IB_BASE_URL` variables.
2728

2829
## 📦 Installation
2930
To use the library, add the dependency to your projects `Cargo.toml`
@@ -67,10 +68,10 @@ async fn main() {
6768
```
6869

6970
## 👀 Examples
70-
The best way to learn how to use the library is to look at the official docs.rs documentation,
71-
which has simple examples on how to use every endpoint. You can also look at integration tests
72-
under the [tests](./tests) directory, which work similarly to how you would use them in a real
73-
scenario.
71+
The best way to learn how to use the library is to look at the official
72+
[docs.rs documentation](https://docs.rs/infobip_sdk/), which has simple examples on how to use
73+
every endpoint. You can also look at integration tests under the [tests](./tests) directory,
74+
which work similarly to how you would use them in a real scenario.
7475

7576
## 🗒 Notes
7677

@@ -131,7 +132,7 @@ is done automatically when calling an endpoint, or you can call the `.validate()
131132
model.
132133

133134
### Using features
134-
You can speed up compile-times a bit by turning only the needed channels as library features.
135+
You can speed up compile time by turning only the needed channels as library features.
135136
For example, to only build SMS, add the dependency like this:
136137
```toml
137138
infobip_sdk = { version = "0.1", features = ["sms"] }

README.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

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

89
{{readme}}

src/api/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ impl fmt::Display for ApiError {
5252

5353
/// Holds information about a server-side error.
5454
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
55+
#[serde(rename_all = "camelCase")]
5556
pub struct ServiceException {
56-
#[serde(rename = "messageId")]
57+
/// Identifier of the error.
58+
#[serde(skip_serializing_if = "Option::is_none")]
5759
pub message_id: Option<String>,
58-
#[serde(rename = "text")]
59-
pub text: String,
60-
#[serde(rename = "validationErrors", skip_serializing_if = "Option::is_none")]
61-
pub validation_errors: Option<String>,
60+
61+
/// Detailed error description.
62+
#[serde(skip_serializing_if = "Option::is_none")]
63+
pub text: Option<String>,
64+
65+
/// Map of validation errors.
66+
#[serde(skip_serializing_if = "Option::is_none")]
67+
pub validation_errors: Option<HashMap<String, Vec<String>>>,
6268
}
6369

6470
/// Holds the exception produced by a server-side error.

src/api/sms.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl SmsClient {
5050
}
5151

5252
/// Check how different message configurations will affect your message text, number of
53-
/// characters and message parts.
53+
/// characters, and message parts.
5454
///
5555
/// # Example
5656
///
@@ -273,7 +273,8 @@ impl SmsClient {
273273
}
274274
}
275275

276-
/// See the status and the scheduled time of your SMS messages.
276+
/// See all scheduled messages and their scheduled date and time. To schedule a message, use
277+
/// the sendAt field when sending a message.
277278
///
278279
/// # Example
279280
/// ```no_run
@@ -567,7 +568,8 @@ impl SmsClient {
567568
}
568569
}
569570

570-
/// Change the date and time for sending scheduled messages.
571+
/// Change the date and time of already scheduled messages. To schedule a message, use the
572+
/// sendAt field when sending a message.
571573
///
572574
/// # Example
573575
/// ```no_run
@@ -674,7 +676,8 @@ impl SmsClient {
674676
}
675677
}
676678

677-
/// Change status or completely cancel sending of scheduled messages.
679+
/// Change status or completely cancel sending of scheduled messages. To schedule a message,
680+
/// use the sendAt field when sending a message.
678681
///
679682
/// # Example
680683
/// ```no_run
@@ -691,6 +694,7 @@ impl SmsClient {
691694
/// let request_body = UpdateScheduledStatusRequestBody::new(ScheduledStatus::CANCELED);
692695
///
693696
/// let response = sms_client.update_scheduled_status(query_parameters, request_body).await?;
697+
///
694698
/// assert_eq!(response.status, StatusCode::OK);
695699
/// # Ok(())
696700
/// # }
@@ -736,7 +740,7 @@ pub struct BlockingSmsClient {
736740
}
737741

738742
impl BlockingSmsClient {
739-
/// Builds and returns a new `BlockingSmsClient` with specified configuration.
743+
/// Builds and returns a new `BlockingSmsClient` with a specified configuration.
740744
pub fn with_configuration(configuration: Configuration) -> BlockingSmsClient {
741745
BlockingSmsClient {
742746
configuration,

src/api/tests/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use crate::configuration::{ApiKey, Configuration};
77
#[cfg(test)]
88
mod sms;
99

10+
#[cfg(test)]
11+
mod whatsapp;
12+
1013
const DUMMY_TEXT: &str = "Some text for tests.";
1114

1215
async fn mock_json_endpoint(

src/api/tests/sms.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ async fn test_preview_server_error() {
128128
.request_error
129129
.service_exception
130130
.text
131-
.is_empty())
131+
.unwrap()
132+
.is_empty());
132133
} else {
133134
assert!(false, "not an API error")
134135
}
@@ -235,8 +236,6 @@ async fn test_get_delivery_reports_bad_parameters() {
235236
.unwrap_err();
236237
if let SdkError::Validation(validation_error) = error {
237238
assert!(!validation_error.errors().is_empty());
238-
} else {
239-
assert!(false, "not validation error")
240239
}
241240
}
242241

0 commit comments

Comments
 (0)