Skip to main content

ShopifyConfigBuilder

Struct ShopifyConfigBuilder 

Source
pub struct ShopifyConfigBuilder { /* private fields */ }
Expand description

Builder for constructing ShopifyConfig instances.

This builder provides a fluent API for configuring the SDK. Required fields are api_key and api_secret_key. All other fields have sensible defaults.

§Defaults

  • api_version: Latest stable version
  • is_embedded: true
  • scopes: Empty
  • host: None
  • user_agent_prefix: None
  • old_api_secret_key: None
  • reject_deprecated_versions: false

§Example

use shopify_sdk::{ShopifyConfig, ApiKey, ApiSecretKey, ApiVersion, HostUrl};

let config = ShopifyConfig::builder()
    .api_key(ApiKey::new("key").unwrap())
    .api_secret_key(ApiSecretKey::new("secret").unwrap())
    .api_version(ApiVersion::V2024_10)
    .host(HostUrl::new("https://myapp.example.com").unwrap())
    .is_embedded(false)
    .user_agent_prefix("MyApp/1.0")
    .build()
    .unwrap();

Implementations§

Source§

impl ShopifyConfigBuilder

Source

pub fn new() -> Self

Creates a new builder with default values.

Source

pub fn api_key(self, key: ApiKey) -> Self

Sets the API key (required).

Source

pub fn api_secret_key(self, key: ApiSecretKey) -> Self

Sets the API secret key (required).

Source

pub fn old_api_secret_key(self, key: ApiSecretKey) -> Self

Sets the old API secret key for key rotation support.

When validating OAuth HMAC signatures, the SDK will try the primary secret key first, then fall back to this old key if validation fails. This allows in-flight OAuth flows to complete during key rotation.

§Example
use shopify_sdk::{ShopifyConfig, ApiKey, ApiSecretKey};

// During key rotation, configure both keys
let config = ShopifyConfig::builder()
    .api_key(ApiKey::new("key").unwrap())
    .api_secret_key(ApiSecretKey::new("new-secret").unwrap())
    .old_api_secret_key(ApiSecretKey::new("old-secret").unwrap())
    .build()
    .unwrap();
Source

pub fn scopes(self, scopes: AuthScopes) -> Self

Sets the OAuth scopes.

Source

pub fn host(self, host: HostUrl) -> Self

Sets the host URL.

Source

pub fn api_version(self, version: ApiVersion) -> Self

Sets the API version.

Source

pub const fn is_embedded(self, embedded: bool) -> Self

Sets whether the app is embedded in the Shopify admin.

Source

pub fn user_agent_prefix(self, prefix: impl Into<String>) -> Self

Sets the user agent prefix for HTTP requests.

Source

pub const fn reject_deprecated_versions(self, reject: bool) -> Self

Sets whether to reject deprecated API versions.

When true, build() will return a ConfigError::DeprecatedApiVersion error if the configured API version is past Shopify’s support window.

When false (the default), deprecated versions will log a warning via tracing but the configuration will still be created.

§Example
use shopify_api::{ShopifyConfig, ApiKey, ApiSecretKey, ApiVersion, ConfigError};

// This will fail because V2024_01 is deprecated
let result = ShopifyConfig::builder()
    .api_key(ApiKey::new("key").unwrap())
    .api_secret_key(ApiSecretKey::new("secret").unwrap())
    .api_version(ApiVersion::V2024_01)
    .reject_deprecated_versions(true)
    .build();

assert!(matches!(result, Err(ConfigError::DeprecatedApiVersion { .. })));
Source

pub fn on_deprecation<F>(self, callback: F) -> Self
where F: Fn(&ApiDeprecationInfo) + Send + Sync + 'static,

Sets a callback to be invoked when API deprecation notices are received.

The callback is called whenever the SDK receives a response with the X-Shopify-API-Deprecated-Reason header. This allows you to track deprecated API usage in your monitoring systems.

§Example
use shopify_api::{ShopifyConfig, ApiKey, ApiSecretKey};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

let deprecation_count = Arc::new(AtomicUsize::new(0));
let count_clone = Arc::clone(&deprecation_count);

let config = ShopifyConfig::builder()
    .api_key(ApiKey::new("key").unwrap())
    .api_secret_key(ApiSecretKey::new("secret").unwrap())
    .on_deprecation(move |info| {
        count_clone.fetch_add(1, Ordering::SeqCst);
        eprintln!("Deprecated: {} at {:?}", info.reason, info.path);
    })
    .build()
    .unwrap();
Source

pub fn build(self) -> Result<ShopifyConfig, ConfigError>

Builds the ShopifyConfig, validating that required fields are set.

§Errors

Returns ConfigError::MissingRequiredField if api_key or api_secret_key are not set.

Returns ConfigError::DeprecatedApiVersion if reject_deprecated_versions(true) is set and the configured API version is deprecated.

Trait Implementations§

Source§

impl Debug for ShopifyConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShopifyConfigBuilder

Source§

fn default() -> ShopifyConfigBuilder

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

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

Source§

type Output = T

Should always be Self
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