Options

Configuration for Sponsorkit::new.

On this page

Configuration for Sponsorkit::new. Use ..Default::default() for the rest.

let sk = sponsorkit::Sponsorkit::new(sponsorkit::Options {
    github: Some("octocat".into()),
    app_name: Some("my-cli".into()),
    ..Default::default()
})?;
use sponsorkit::Options;

pub struct Options {
    pub github: Option<String>,
    pub open_collective: Option<String>,
    pub app_name: Option<String>,
    pub cache_ttl: Option<Duration>,
    pub mock: Option<Mock>,
    pub storage_dir: Option<PathBuf>,
    pub api_base_url: Option<String>,
    pub site_base_url: Option<String>,
    pub request_timeout: Option<Duration>,
    pub sign_in_method: SignInMethod,
    pub sign_in_timeout: Option<Duration>,
    pub env: Option<HashMap<String, String>>,
    pub dev_checks: Option<bool>,
    pub checkout_poll_interval: Option<Duration>,
    pub interactive: Option<bool>,
    pub open_browser: Option<OpenBrowserHook>,
    pub prompt_for_code: Option<PromptForCodeHook>,
    pub restart: bool,
}

Fields#

github#

pub github: Option<String>

GitHub Sponsors login that receives contributions.

open_collective#

pub open_collective: Option<String>

Open Collective collective slug that receives contributions.

app_name#

pub app_name: Option<String>

Your app's name, shown on the consent page as "says it is" (max 64 characters).

cache_ttl#

pub cache_ttl: Option<Duration>

How long a cached result is served without calling the API. Default 1 hour; values below 60 s are raised to 60 s.

mock#

pub mock: Option<Mock>

Mock mode: no network, no disk; deterministic data. Beats the SPONSORKIT_MOCK environment variable.

storage_dir#

pub storage_dir: Option<PathBuf>

Storage directory. Default: $XDG_CONFIG_HOME/sponsorkit (Linux), ~/Library/Application Support/sponsorkit (macOS), %APPDATA%\sponsorkit (Windows). When none of these can be determined (e.g. HOME is unset), the session lives in memory for the life of the client; the SDK never falls back to the current working directory.

api_base_url#

pub api_base_url: Option<String>

API origin, used for every API call (/api/v1/…). Default DEFAULT_API_BASE_URL (https://api.sponsorkit.io). Trailing slashes are trimmed; an empty string counts as unset.

site_base_url#

pub site_base_url: Option<String>

Site base URL (origin plus optional base path), used for every page URL: <site_base_url>/connect/, <site_base_url>/checkout/, Sponsorkit::checkout_url and the loopback redirect after a checkout sign-in. Default DEFAULT_SITE_BASE_URL (https://ffmathy.github.io/sponsorkit), or api_base_url when that is set and this is not (single-origin self-hosting, tests). Trailing slashes are trimmed; an empty string counts as unset.

request_timeout#

pub request_timeout: Option<Duration>

Timeout for each HTTP request, including reading the body. Default DEFAULT_REQUEST_TIMEOUT (30 s); Some(Duration::ZERO) disables it. A timeout counts as a network failure: get_financial_contribution serves the (stale) cache, sign_in fails with network_error.

sign_in_method#

pub sign_in_method: SignInMethod

Forces a sign-in method. Default SignInMethod::Auto.

sign_in_timeout#

pub sign_in_timeout: Option<Duration>

How long sign_in (and the sign-in phase of open_checkout) waits for the loopback callback or the paste-back code. Exceeding it fails with timeout. Default DEFAULT_SIGN_IN_TIMEOUT (300 s).

env#

pub env: Option<HashMap<String, String>>

Environment override for SPONSORKIT_DISABLE, SPONSORKIT_MOCK, SPONSORKIT_NO_NAG, SPONSORKIT_DEV_CHECKS and CI. When Some, it replaces the process environment for these variables (it is not merged).

dev_checks#

pub dev_checks: Option<bool>

Forces the dev-time target existence check on or off. Default: on when SPONSORKIT_DEV_CHECKS is set (see Options::env), otherwise off. Rust has no implicit development signal.

checkout_poll_interval#

pub checkout_poll_interval: Option<Duration>

How often open_checkout polls for a new contribution. Default 60 s.

interactive#

pub interactive: Option<bool>

Overrides terminal detection for the nag helper: Some(false) treats the process as non-interactive (nags never due unless forced), Some(true) as interactive. Default: stdout and stderr must both be terminals.

open_browser#

pub open_browser: Option<OpenBrowserHook>

Replaces opening the system browser (tests, custom UIs).

prompt_for_code#

pub prompt_for_code: Option<PromptForCodeHook>

Replaces reading the paste-back code from stdin.

restart#

pub restart: bool

Resets per-process memo state (nag runs counted, dev-check memo, Retry-After memo) before constructing, as if the process restarted. Equivalent to calling Sponsorkit::reset_process_state.

Trait implementations#

  • impl Clone for Options
  • impl Debug for Options
  • impl Default for Options