Struct flytrap::api::Client

source ·
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

source

pub const PUBLIC_ORIGIN: &'static str = "https://api.machines.dev"

source

pub const PRIVATE_ORIGIN: &'static str = "http://_api.internal:4280"

source

pub const USER_AGENT: &'static str = "flytrap/0.2.1"

source

pub fn new(token: impl Into<String>) -> Self

Available on crate feature 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.

source

pub fn with_origin(origin: impl IntoUrl, token: impl Into<String>) -> Self

Create a Client which sends API Requests to the given origin.

source

pub fn with_client( http_client: Client, origin: impl IntoUrl, token: impl Into<String> ) -> Self

Create a Client wrapping an explicit reqwest::Client.

source

pub async fn apps( &self, organization: impl AsRef<str> ) -> Result<OrganizationApps, Error>

List the Fly.io apps under the given organization.

source

pub async fn machines( &self, app: impl AsRef<str> ) -> Result<Vec<Machine>, Error>

List Fly.io machines for the given app.

source

pub async fn peers(&self) -> Result<Vec<Machine>, Error>

Available on crate feature environment only.

List Fly.io machines for the current app, excluding the current machine.

Trait Implementations§

source§

impl Default for Client

Available on crate feature environment only.
source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more