pub struct Client { /* private fields */ }
Available on crate feature
api
only.Expand description
A client for the Fly.io Machines API.
use flytrap::api::Client;
let token = std::env::var("FLY_API_TOKEN")?;
let client = Client::new(token);
for app in client.apps("personal").await? {
println!("{}: {} machine(s)", app.name, app.machine_count);
}
for machine in client.peers().await? {
println!("{} in {}: {:?}", machine.name, machine.location, machine.state);
}
Ok(())
Implementations§
source§impl Client
impl Client
pub const PUBLIC_ORIGIN: &'static str = "https://api.machines.dev"
pub const PRIVATE_ORIGIN: &'static str = "http://_api.internal:4280"
pub const USER_AGENT: &'static str = "flytrap/0.2.1"
sourcepub fn new(token: impl Into<String>) -> Self
Available on crate feature environment
only.
pub fn new(token: impl Into<String>) -> Self
environment
only.Create a Client for the Machines API. An authentication token is required.
When called under a Fly.io hosted environment (or when the detect
feature is active and a Fly.io Wireguard connection is present), uses
the http://_api.internal
origin. Otherwise, uses the
https://api.machines.dev
origin.
sourcepub fn with_origin(origin: impl IntoUrl, token: impl Into<String>) -> Self
pub fn with_origin(origin: impl IntoUrl, token: impl Into<String>) -> Self
Create a Client which sends API Requests to the given origin
.
sourcepub fn with_client(
http_client: Client,
origin: impl IntoUrl,
token: impl Into<String>
) -> Self
pub fn with_client( http_client: Client, origin: impl IntoUrl, token: impl Into<String> ) -> Self
Create a Client wrapping an explicit reqwest::Client
.
sourcepub async fn apps(
&self,
organization: impl AsRef<str>
) -> Result<OrganizationApps, Error>
pub async fn apps( &self, organization: impl AsRef<str> ) -> Result<OrganizationApps, Error>
List the Fly.io apps under the given organization
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more