pub struct ApiClient { /* private fields */ }Expand description
HTTP client for the Socket Patch API.
Supports both the authenticated Socket API (api.socket.dev) and the
public proxy (patches-api.socket.dev) which serves free patches
without authentication.
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(options: ApiClientOptions) -> Self
pub fn new(options: ApiClientOptions) -> Self
Create a new API client from the given options.
Constructs a reqwest::Client with proper default headers
(User-Agent, Accept, and optionally Authorization).
Sourcepub async fn fetch_patch(
&self,
org_slug: Option<&str>,
uuid: &str,
) -> Result<Option<PatchResponse>, ApiError>
pub async fn fetch_patch( &self, org_slug: Option<&str>, uuid: &str, ) -> Result<Option<PatchResponse>, ApiError>
Fetch a patch by UUID (full details with blob content).
Returns Ok(None) when the patch is not found (404).
Sourcepub async fn search_patches_by_cve(
&self,
org_slug: Option<&str>,
cve_id: &str,
) -> Result<SearchResponse, ApiError>
pub async fn search_patches_by_cve( &self, org_slug: Option<&str>, cve_id: &str, ) -> Result<SearchResponse, ApiError>
Search patches by CVE ID.
Sourcepub async fn search_patches_by_ghsa(
&self,
org_slug: Option<&str>,
ghsa_id: &str,
) -> Result<SearchResponse, ApiError>
pub async fn search_patches_by_ghsa( &self, org_slug: Option<&str>, ghsa_id: &str, ) -> Result<SearchResponse, ApiError>
Search patches by GHSA ID.
Sourcepub async fn search_patches_by_package(
&self,
org_slug: Option<&str>,
purl: &str,
) -> Result<SearchResponse, ApiError>
pub async fn search_patches_by_package( &self, org_slug: Option<&str>, purl: &str, ) -> Result<SearchResponse, ApiError>
Search patches by package PURL.
The PURL must be a valid Package URL starting with pkg:.
Examples: pkg:npm/lodash@4.17.21, pkg:pypi/django@3.2.0
Sourcepub async fn search_patches_batch(
&self,
org_slug: Option<&str>,
purls: &[String],
) -> Result<BatchSearchResponse, ApiError>
pub async fn search_patches_batch( &self, org_slug: Option<&str>, purls: &[String], ) -> Result<BatchSearchResponse, ApiError>
Search patches for multiple packages (batch).
For authenticated API, uses the POST /patches/batch endpoint.
For the public proxy (which cannot cache POST bodies on CDN), falls
back to individual GET requests per PURL with a concurrency limit of
10.
Maximum 500 PURLs per request.
Sourcepub async fn fetch_organizations(
&self,
) -> Result<Vec<OrganizationInfo>, ApiError>
pub async fn fetch_organizations( &self, ) -> Result<Vec<OrganizationInfo>, ApiError>
Fetch organizations accessible to the current API token.
Sourcepub async fn resolve_org_slug(&self) -> Result<String, ApiError>
pub async fn resolve_org_slug(&self) -> Result<String, ApiError>
Resolve the org slug from the API token by querying /v0/organizations.
If there is exactly one org, returns its slug. If there are multiple, picks the first and prints a warning. If there are none, returns an error.
Sourcepub async fn fetch_blob(&self, hash: &str) -> Result<Option<Vec<u8>>, ApiError>
pub async fn fetch_blob(&self, hash: &str) -> Result<Option<Vec<u8>>, ApiError>
Fetch a blob by its SHA-256 hash.
Returns the raw binary content, or Ok(None) if not found.
Uses the authenticated endpoint when token and org slug are
available, otherwise falls back to the public proxy.
Sourcepub async fn fetch_diff(&self, uuid: &str) -> Result<Option<Vec<u8>>, ApiError>
pub async fn fetch_diff(&self, uuid: &str) -> Result<Option<Vec<u8>>, ApiError>
Fetch a per-file diff archive (tar.gz of bsdiff deltas) by patch UUID.
Returns the raw archive bytes, or Ok(None) if not found (404). The
public proxy serves these under /patch/diff/<uuid>; the
authenticated API serves them under /v0/orgs/<slug>/patches/diff/<uuid>.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl UnsafeUnpin for ApiClient
impl !UnwindSafe for ApiClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more