-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endpoints): add v2 endpoints (#360)
* feat(endpoints): add v2 api * reorganize --------- Co-authored-by: Galileo Daras <[email protected]>
- Loading branch information
1 parent
cb33d0e
commit 8def586
Showing
4 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,10 @@ description = "Common location for all endpoints associated with the orb" | |
authors = ["Ryan Butler <[email protected]>"] | ||
publish = false | ||
|
||
# orb-core can't consume crates that use workspace inheritance :( | ||
edition = "2021" | ||
license = "MIT OR (Apache-2.0 WITH LLVM-exception)" | ||
repository = "https://github.com/worldcoin/orb-software" | ||
rust-version = "1.77.0" | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
hex = "0.4.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use url::Url; | ||
|
||
use crate::{concat_urls, Backend, OrbId}; | ||
|
||
#[derive(Debug, Eq, PartialEq, Hash, Clone)] | ||
pub struct Endpoints { | ||
pub status: Url, | ||
} | ||
|
||
impl Endpoints { | ||
pub fn new(backend: Backend, orb_id: &OrbId) -> Self { | ||
let subdomain = match backend { | ||
Backend::Prod => "orb", | ||
Backend::Staging => "stage.orb", | ||
Backend::Analysis => unimplemented!(), | ||
}; | ||
|
||
Self { | ||
status: concat_urls( | ||
&format!("https://management.{subdomain}.worldcoin.org/api/v2/orbs/"), | ||
orb_id, | ||
"status", | ||
), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_endpoints() { | ||
let orb_id = "ea2ea744".parse().unwrap(); | ||
let stage = Endpoints::new(Backend::Staging, &orb_id); | ||
let prod = Endpoints::new(Backend::Prod, &orb_id); | ||
|
||
assert_eq!( | ||
stage.status.as_str(), | ||
"https://management.stage.orb.worldcoin.org/api/v2/orbs/ea2ea744/status" | ||
); | ||
assert_eq!( | ||
prod.status.as_str(), | ||
"https://management.orb.worldcoin.org/api/v2/orbs/ea2ea744/status" | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "not implemented")] | ||
fn test_analysis_backend_unimplemented() { | ||
let orb_id = "ea2ea744".parse().unwrap(); | ||
let _analysis = Endpoints::new(Backend::Analysis, &orb_id); | ||
} | ||
} |