SurgeSdk

Struct SurgeSdk 

Source
pub struct SurgeSdk {
    pub config: Config,
    pub client: Client,
}
Expand description

SDK for interacting with the Surge API.

Encapsulates an HTTP client and configuration for managing domains, publishing projects, and handling account operations.

Fields§

§config: Config

Configuration settings for the SDK, including the API endpoint and timeout settings.

§client: Client

The HTTP client used for making API requests, configured with the provided settings.

Implementations§

Source§

impl SurgeSdk

Source

pub fn new(config: Config) -> Result<Self, SurgeError>

Creates a new SurgeSdk instance with the given configuration.

§Arguments
  • config - Configuration settings for the SDK.
§Returns

A Result containing the SurgeSdk or a SurgeError if the HTTP client cannot be built.

§Example
use surge_sdk::{Config,SurgeSdk};
let config = Config::new("https://api.surge.sh", "0.1.0").unwrap();
let sdk = SurgeSdk::new(config).unwrap();
Source

pub async fn account(&self, auth: &Auth) -> Result<AccountResponse, SurgeError>

Fetches account information.

§Arguments
  • auth - Authentication credentials.
§Returns

A Result containing an AccountResponse or a SurgeError.

Source

pub async fn list( &self, domain: Option<&str>, auth: &Auth, ) -> Result<ListResult, SurgeError>

Lists domains, optionally filtered by a specific domain.

§Arguments
  • domain - Optional domain to filter the list.
  • auth - Authentication credentials.
§Returns

A Result containing a ListResponse or a SurgeError.

Source

pub async fn nuke(&self, auth: &Auth) -> Result<(), SurgeError>

Deletes the account.

§Arguments
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn teardown( &self, domain: &str, auth: &Auth, ) -> Result<TeardownResponse, SurgeError>

Tears down a domain.

§Arguments
  • domain - The domain to tear down.
  • auth - Authentication credentials.
§Returns

A Result containing TeardownResponse if the operation was successful, or a SurgeError.

Source

pub async fn login(&self, auth: &Auth) -> Result<LoginResponse, SurgeError>

Logs in to the API.

§Arguments
  • auth - Authentication credentials.
§Returns

A Result containing a LoginResponse or a SurgeError.

Source

pub async fn publish( &self, project_path: &Path, domain: &str, auth: &Auth, headers: Option<Vec<(String, String)>>, argv: Option<&[String]>, ) -> Result<impl Stream<Item = Result<Event, SurgeError>>, SurgeError>

Publishes a project directory to a domain.

Delegates to stream::publish for tarball creation and streaming.

§Arguments
  • project_path - Path to the project directory.
  • domain - Target domain for publishing.
  • auth - Authentication credentials.
  • headers - Optional custom HTTP headers.
  • argv - Optional command-line arguments.
§Returns

A Result containing a stream of Events or a SurgeError.

Source

pub async fn publish_wip( &self, project_path: &Path, domain: &str, auth: &Auth, headers: Option<Vec<(String, String)>>, argv: Option<&[String]>, ) -> Result<impl Stream<Item = Result<Event, SurgeError>>, SurgeError>

Publishes a work-in-progress version of a project to a preview domain.

Delegates to stream::publish_wip for tarball creation and streaming.

§Arguments
  • project_path - Path to the project directory.
  • domain - Target domain for the preview.
  • auth - Authentication credentials.
  • headers - Optional custom HTTP headers.
  • argv - Optional command-line arguments.
§Returns

A Result containing a stream of Events or a SurgeError.

Source

pub async fn rollback( &self, domain: &str, auth: &Auth, ) -> Result<RollResponse, SurgeError>

Rolls back a domain to a previous revision.

§Arguments
  • domain - The domain to roll back.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn rollfore( &self, domain: &str, auth: &Auth, ) -> Result<RollResponse, SurgeError>

Rolls forward a domain to a newer revision.

§Arguments
  • domain - The domain to roll forward.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn cutover( &self, domain: &str, revision: Option<&str>, auth: &Auth, ) -> Result<(), SurgeError>

Switches a domain to a specific revision (or the latest if none specified).

§Arguments
  • domain - The target domain.
  • revision - Optional revision to switch to.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn discard( &self, revision: &str, auth: &Auth, ) -> Result<DiscardResponse, SurgeError>

Discards a specific revision (or all revisions if none specified) for a domain.

§Arguments
  • domain - The target domain.
  • revision - Optional revision to discard.
  • auth - Authentication credentials.
§Returns

A DiscardResponse indicating success or a SurgeError.

Source

pub async fn certs( &self, domain: &str, auth: &Auth, ) -> Result<CertsResponse, SurgeError>

Fetches SSL certificate information for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a DCertsResponse or a SurgeError.

Source

pub async fn metadata( &self, domain: &str, revision: Option<&str>, auth: &Auth, ) -> Result<MetadataResponse, SurgeError>

Fetches metadata for a domain or specific revision.

§Arguments
  • domain - The target domain.
  • revision - Optional revision to fetch metadata for.
  • auth - Authentication credentials.
§Returns

A Result containing a MetadataResponse or a SurgeError.

Source

pub async fn manifest( &self, domain: &str, revision: Option<&str>, auth: &Auth, ) -> Result<ManifestResponse, SurgeError>

Fetches the manifest for a domain or specific revision.

§Arguments
  • domain - The target domain.
  • revision - Optional revision to fetch the manifest for.
  • auth - Authentication credentials.
§Returns

A Result containing a ManifestResponse or a SurgeError.

Source

pub async fn files( &self, domain: &str, auth: &Auth, ) -> Result<ManifestResponse, SurgeError>

Fetches the file manifest for a domain (alias for manifest with no revision).

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a serde_json::Value or a SurgeError.

Source

pub async fn config( &self, domain: &str, settings: Value, auth: &Auth, ) -> Result<(), SurgeError>

Updates configuration settings for a domain.

§Arguments
  • domain - The target domain.
  • settings - JSON settings to apply.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn dns(&self, domain: &str, auth: &Auth) -> Result<Value, SurgeError>

Fetches DNS records for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a serde_json::Value or a SurgeError.

Source

pub async fn dns_add( &self, domain: &str, record: Value, auth: &Auth, ) -> Result<(), SurgeError>

Adds a DNS record for a domain.

§Arguments
  • domain - The target domain.
  • record - JSON representation of the DNS record.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn dns_remove( &self, domain: &str, id: &str, auth: &Auth, ) -> Result<(), SurgeError>

Removes a DNS record for a domain.

§Arguments
  • domain - The target domain.
  • id - The ID of the DNS record to remove.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn zone(&self, domain: &str, auth: &Auth) -> Result<Value, SurgeError>

Fetches zone information for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a serde_json::Value or a SurgeError.

Source

pub async fn zone_add( &self, domain: &str, record: Value, auth: &Auth, ) -> Result<(), SurgeError>

Adds a zone record for a domain.

§Arguments
  • domain - The target domain.
  • record - JSON representation of the zone record.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn zone_remove( &self, domain: &str, id: &str, auth: &Auth, ) -> Result<(), SurgeError>

Removes a zone record for a domain.

§Arguments
  • domain - The target domain.
  • id - The ID of the zone record to remove.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn bust(&self, domain: &str, auth: &Auth) -> Result<(), SurgeError>

Clears the cache for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn stats(&self, auth: &Auth) -> Result<Value, SurgeError>

Fetches account statistics.

§Arguments
  • auth - Authentication credentials.
§Returns

A Result containing a serde_json::Value or a SurgeError.

Source

pub async fn analytics( &self, domain: &str, auth: &Auth, ) -> Result<DAnalyticsResponse, SurgeError>

Fetches analytics data for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a DAnalyticsResponse or a SurgeError.

Source

pub async fn usage( &self, domain: &str, auth: &Auth, ) -> Result<DAnalyticsResponse, SurgeError>

Fetches usage data for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a DAnalyticsResponse or a SurgeError.

Source

pub async fn audit( &self, domain: &str, auth: &Auth, ) -> Result<DAuditResponse, SurgeError>

Fetches audit logs for a domain.

§Arguments
  • domain - The target domain.
  • auth - Authentication credentials.
§Returns

A Result containing a DAuditResponse or a SurgeError.

Source

pub async fn invite( &self, domain: &str, emails: Value, auth: &Auth, ) -> Result<bool, SurgeError>

Invites collaborators to a domain.

§Arguments
  • domain - The target domain.
  • emails - JSON array of email addresses to invite.
  • auth - Authentication credentials.
§Returns

A bool indicating success or a SurgeError.

Source

pub async fn revoke( &self, domain: &str, emails: Value, auth: &Auth, ) -> Result<bool, SurgeError>

Revokes collaborator access for a domain.

§Arguments
  • domain - The target domain.
  • emails - JSON array of email addresses to revoke.
  • auth - Authentication credentials.
§Returns

A bool indicating success or a SurgeError.

Source

pub async fn plan(&self, plan: Value, auth: &Auth) -> Result<(), SurgeError>

Updates the account plan.

§Arguments
  • plan - JSON representation of the plan.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn card(&self, card: Value, auth: &Auth) -> Result<(), SurgeError>

Updates the payment card for the account.

§Arguments
  • card - JSON representation of the card details.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub async fn plans( &self, domain: Option<&str>, auth: &Auth, ) -> Result<PlansResponse, SurgeError>

Fetches available plans, optionally for a specific domain.

§Arguments
  • domain - Optional domain to filter plans.
  • auth - Authentication credentials.
§Returns

A Result containing a PlansResponse or a SurgeError.

Source

pub async fn ssl( &self, domain: &str, pem_path: &Path, auth: &Auth, ) -> Result<(), SurgeError>

Uploads an SSL certificate for a domain.

§Arguments
  • domain - The target domain.
  • pem_path - Path to the PEM certificate file.
  • auth - Authentication credentials.
§Returns

A Result indicating success or a SurgeError.

Source

pub fn apply_auth(&self, req: RequestBuilder, auth: &Auth) -> RequestBuilder

Applies authentication to an HTTP request.

§Arguments
  • req - The reqwest::RequestBuilder to modify.
  • auth - Authentication credentials (token or username/password).
§Returns

The modified RequestBuilder with authentication headers.

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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>,

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,