Skip to content

Commit

Permalink
Add client examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Apr 30, 2024
1 parent f36a183 commit 8523e7f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Tests
run: nix develop --command cargo test

- name: Build examples
run: nix develop --command cargo build --examples

build:
name: Build
needs:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
url.workspace = true

[dev-dependencies]
anyhow.workspace = true
tokio.workspace = true
19 changes: 19 additions & 0 deletions client/examples/now_and_next.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use anyhow::Result;
use chrono::Local;
use url::Url;

#[tokio::main]
async fn main() -> Result<()> {
let url = Url::parse("https://www.emfcamp.org/schedule/2022.json")?;

let client = emfcamp_schedule_api::Client::new(url);

let schedule = client.get_schedule().await?;

let now = Local::now();
let now_and_next = schedule.now_and_next(now.into());

println!("{:#?}", now_and_next);

Ok(())
}
18 changes: 18 additions & 0 deletions client/examples/schedule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Result;
use url::Url;

#[tokio::main]
async fn main() -> Result<()> {
let url = Url::parse("https://www.emfcamp.org/schedule/2022.json")?;

let client = emfcamp_schedule_api::Client::new(url);

let schedule = client.get_schedule().await?;

println!("Found {} events", schedule.events.len());
for event in schedule.events {
println!("- {:?}", event);
}

Ok(())
}
20 changes: 20 additions & 0 deletions client/examples/venues.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Result;
use url::Url;

#[tokio::main]
async fn main() -> Result<()> {
let url = Url::parse("https://www.emfcamp.org/schedule/2022.json")?;

let client = emfcamp_schedule_api::Client::new(url);

let schedule = client.get_schedule().await?;

let venues = schedule.venues();

println!("Found {} venues:", venues.len());
for venue in venues {
println!("- {}", venue);
}

Ok(())
}
4 changes: 0 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

version = cargoToml.workspace.package.version;
gitRevision = self.shortRev or self.dirtyShortRev;

lintingRustFlags = "-D unused-crate-dependencies";
in rec {
devShell = pkgs.mkShell {
packages = with pkgs; [
Expand All @@ -49,8 +47,6 @@
# Container image management tool
skopeo
];

RUSTFLAGS = lintingRustFlags;
};

packages =
Expand Down

0 comments on commit 8523e7f

Please sign in to comment.