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.