Skip to content

Commit

Permalink
Tag 1.1.3 (#453)
Browse files Browse the repository at this point in the history
* Tag 1.1.3
  • Loading branch information
sreeise authored Dec 8, 2023
1 parent 0a19ae1 commit 8d27f50
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Cargo.lock
src/bin
examples/example_files/**
examples/test.rs
examples/test2.rs
gen
.run

Expand All @@ -23,5 +24,7 @@ env.toml
env.json
env.yaml
app_registrations.json
app_registrations2.json

# Codegen debugging output
graph-codegen/src/parsed_metadata/**
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "graph-rs-sdk"
version = "1.1.2"
version = "1.1.3"
authors = ["sreeise"]
edition = "2021"
readme = "README.md"
Expand Down Expand Up @@ -36,18 +36,18 @@ serde_json = "1"
url = "2"
lazy_static = "1.4.0"

graph-oauth = { path = "./graph-oauth", version = "1.0.2", default-features=false }
graph-http = { path = "./graph-http", version = "1.1.1", default-features=false }
graph-oauth = { path = "./graph-oauth", version = "1.0.3", default-features=false }
graph-http = { path = "./graph-http", version = "1.1.2", default-features=false }
graph-error = { path = "./graph-error", version = "0.2.2" }
graph-core = { path = "./graph-core", version = "0.4.1" }

[features]
default = ["native-tls"]
native-tls = ["reqwest/native-tls", "graph-http/native-tls", "graph-oauth/native-tls"]
rustls-tls = ["reqwest/rustls-tls", "graph-http/rustls-tls", "graph-oauth/rustls-tls"]
brotli = ["reqwest/brotli"]
deflate = ["reqwest/deflate"]
trust-dns = ["reqwest/trust-dns"]
brotli = ["reqwest/brotli", "graph-http/brotli", "graph-oauth/brotli"]
deflate = ["reqwest/deflate", "graph-http/deflate", "graph-oauth/deflate"]
trust-dns = ["reqwest/trust-dns", "graph-http/trust-dns", "graph-oauth/trust-dns"]
test-util = ["graph-http/test-util"]

[dev-dependencies]
Expand All @@ -56,6 +56,7 @@ futures = "0.3"
lazy_static = "1.4"
tokio = { version = "1.27.0", features = ["full"] }
warp = "0.3.3"
wiremock = "0.5.22"

graph-codegen = { path = "./graph-codegen", version = "0.0.1" }
test-tools = { path = "./test-tools", version = "0.0.1" }
Expand Down
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### Available on [crates.io](https://crates.io/crates/graph-rs-sdk)

```toml
graph-rs-sdk = "1.1.2"
graph-rs-sdk = "1.1.3"
tokio = { version = "1.25.0", features = ["full"] }
```

Expand All @@ -19,13 +19,13 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
```

To use stream features add futures crate:
To use [stream](#streaming) features add the [futures](https://crates.io/crates/futures) crate:

```toml
futures = "0.3"
```

And import `futures::StreamExt` when using [Streaming](#streaming) features.
And import `futures::StreamExt`.

```rust
use futures::StreamExt;
Expand Down Expand Up @@ -87,7 +87,7 @@ The crate can do both an async and blocking requests.

#### Async Client (default)

graph-rs-sdk = "1.1.2"
graph-rs-sdk = "1.1.3"
tokio = { version = "1.25.0", features = ["full"] }

#### Example
Expand Down Expand Up @@ -119,7 +119,7 @@ async fn main() -> GraphResult<()> {
To use the blocking client use the `into_blocking()` method. You should not
use `tokio` when using the blocking client.

graph-rs-sdk = "1.1.2"
graph-rs-sdk = "1.1.3"

#### Example
use graph_rs_sdk::*;
Expand Down Expand Up @@ -148,8 +148,9 @@ fn main() -> GraphResult<()> {
- `native-tls`: Use the `native-tls` TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).
- `rustls-tls`: Use the `rustls-tls` TLS backend (cross-platform backend, only supports TLS 1.2 and 1.3).
- `brotli`: Enables reqwest feature brotli. For more info see the [reqwest](https://crates.io/crates/reqwest) crate.
- `defalte`: Enables reqwest feature deflate. For more info see the [reqwest](https://crates.io/crates/reqwest) crate.
- `deflate`: Enables reqwest feature deflate. For more info see the [reqwest](https://crates.io/crates/reqwest) crate.
- `trust-dns`: Enables reqwest feature trust-dns. For more info see the [reqwest](https://crates.io/crates/reqwest) crate.
- `test-util`: Enables testing features. Currently only enables setting https-only to false for use in mocking frameworks.

Default features: `default=["native-tls"]`

Expand Down Expand Up @@ -179,8 +180,36 @@ pub async fn get_drive_item() -> GraphResult<()> {
}
```

#### Response Errors/Error Types

While the crate does have its own error type and result you will probably want to use crates like
[anyhow](https://crates.io/crates/anyhow) due to the amount of possible errors that could occur.

If the Microsoft Graph API returned an error this is almost always in the body of the response.
The `ResponseExt` for async requests and `BlockingResponseExt` for blocking requests have convenience
methods that can be used to get the error message from the body of the response.

```rust
use graph_rs_sdk::{http::ResponseExt, Graph};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = Graph::new("token");
let response = client.users().list_user().send().await?;

if !response.status().is_success() {
if let Ok(error) = response.into_graph_error_message().await {
println!("{error:#?}");
}
}

Ok(())
}
```

##### Custom Types
You can pass types your own types to API requests that require a request body by implementing `serde::Serialize`.
You can pass your own types to API requests that require a request body by implementing `serde::Serialize`.

You can implement your own types by utilizing methods from reqwest::Response. These types must implement `serde::Deserialize`.
See the reqwest crate for more info.
Expand Down Expand Up @@ -248,7 +277,7 @@ pub async fn get_drive_item() -> GraphResult<()> {
Paging handles scenarios where the response body is a truncated version of the data and a URL is provided
to continue calling and getting the rest of the data. Paging can consist of multiple links in the call chain.

The sdk provides conveniance methods for getting all data in a paging scenario such as using next links or using [delta links to track changes to Graph data](https://learn.microsoft.com/en-us/graph/delta-query-overview).
The sdk provides convenience methods for getting all data in a paging scenario such as using next links or using [delta links to track changes to Graph data](https://learn.microsoft.com/en-us/graph/delta-query-overview).

If you just want a quick and easy way to get all next link responses or the JSON bodies you can use the `paging().json()` method which will exhaust all
next link calls and return all the responses in a `VecDeque<Response<Result<T>>>`. Keep in mind that the larger the volume of next link calls that need to be
Expand Down
5 changes: 4 additions & 1 deletion graph-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "graph-http"
version = "1.1.1"
version = "1.1.2"
authors = ["sreeise"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -33,4 +33,7 @@ graph-core = { path = "../graph-core" }
default = ["native-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
brotli = ["reqwest/brotli"]
deflate = ["reqwest/deflate"]
trust-dns = ["reqwest/trust-dns"]
test-util = []
5 changes: 4 additions & 1 deletion graph-oauth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "graph-oauth"
version = "1.0.2"
version = "1.0.3"
authors = ["sreeise"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -30,3 +30,6 @@ graph-error = { path = "../graph-error" }
default = ["native-tls"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
brotli = ["reqwest/brotli"]
deflate = ["reqwest/deflate"]
trust-dns = ["reqwest/trust-dns"]
2 changes: 1 addition & 1 deletion test-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ url = "2"
graph-core = { path = "../graph-core" }
graph-http = { path = "../graph-http" }
graph-error = { path = "../graph-error" }
graph-rs-sdk = { path = "../" }
graph-rs-sdk = { path = "../", features = ["test-util"] }
26 changes: 26 additions & 0 deletions tests/test-util-feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use graph_rs_sdk::{Graph, GraphClientConfiguration};
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

/// Tests the test-util feature and setting https-only to false.
#[tokio::test]
async fn test_util_feature() {
let mock_server = MockServer::start().await;

Mock::given(method("GET"))
.and(path("/users"))
.respond_with(ResponseTemplate::new(200))
.mount(&mock_server)
.await;

let graph_client_configuration = GraphClientConfiguration::new()
.access_token("token")
.https_only(false);

let mut client = Graph::from(graph_client_configuration);
client.use_endpoint(mock_server.uri().as_str());

let response = client.users().list_user().send().await.unwrap();
let status = response.status();
assert_eq!(status.as_u16(), 200);
}

0 comments on commit 8d27f50

Please sign in to comment.