Class: Imagekitio::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/imagekitio/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(private_key: , password: ENV.fetch("OPTIONAL_IMAGEKIT_IGNORES_THIS", "do_not_set"), webhook_secret: , base_url: , max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

[ImageKit dashboard](imagekit.io/dashboard/developer/api-keys). Defaults to ‘ENV`

dummy value. You can ignore this field. Defaults to ‘ENV`

‘whsec_`). You can find this in the [ImageKit dashboard](imagekit.io/dashboard/developer/webhooks). Only required if you’re using webhooks. Defaults to ‘ENV`

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • private_key (String, nil) (defaults to: )

    Your ImageKit private API key (starts with ‘private_`). You can find this in the

  • password (String, nil) (defaults to: ENV.fetch("OPTIONAL_IMAGEKIT_IGNORES_THIS", "do_not_set"))

    ImageKit uses your API key as username and ignores the password. The SDK sets a

  • webhook_secret (String, nil) (defaults to: )

    Your ImageKit webhook secret for verifying webhook signatures (starts with

  • base_url (String, nil) (defaults to: )

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/imagekitio/client.rb', line 105

def initialize(
  private_key: ENV["IMAGEKIT_PRIVATE_KEY"],
  password: ENV.fetch("OPTIONAL_IMAGEKIT_IGNORES_THIS", "do_not_set"),
  webhook_secret: ENV["IMAGEKIT_WEBHOOK_SECRET"],
  base_url: ENV["IMAGE_KIT_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  @base_url_overridden = !base_url.nil?

  base_url ||= "https://api.imagekit.io"

  if private_key.nil? || private_key.to_s.empty?
    raise ArgumentError.new("private_key is required, and can be set via environ: \"IMAGEKIT_PRIVATE_KEY\"")
  end

  @private_key = private_key.to_s
  @password = password.to_s
  @webhook_secret = webhook_secret&.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )

  @custom_metadata_fields = Imagekitio::Resources::CustomMetadataFields.new(client: self)
  @files = Imagekitio::Resources::Files.new(client: self)
  @saved_extensions = Imagekitio::Resources::SavedExtensions.new(client: self)
  @assets = Imagekitio::Resources::Assets.new(client: self)
  @cache = Imagekitio::Resources::Cache.new(client: self)
  @folders = Imagekitio::Resources::Folders.new(client: self)
  @accounts = Imagekitio::Resources::Accounts.new(client: self)
  @beta = Imagekitio::Resources::Beta.new(client: self)
  @webhooks = Imagekitio::Resources::Webhooks.new(client: self)
  @helper = Imagekitio::Helper.new(client: self)
end

Instance Attribute Details

#accountsImagekitio::Resources::Accounts (readonly)



54
55
56
# File 'lib/imagekitio/client.rb', line 54

def accounts
  @accounts
end

#assetsImagekitio::Resources::Assets (readonly)



45
46
47
# File 'lib/imagekitio/client.rb', line 45

def assets
  @assets
end

#betaImagekitio::Resources::Beta (readonly)



57
58
59
# File 'lib/imagekitio/client.rb', line 57

def beta
  @beta
end

#cacheImagekitio::Resources::Cache (readonly)



48
49
50
# File 'lib/imagekitio/client.rb', line 48

def cache
  @cache
end

#custom_metadata_fieldsImagekitio::Resources::CustomMetadataFields (readonly)



36
37
38
# File 'lib/imagekitio/client.rb', line 36

def 
  @custom_metadata_fields
end

#filesImagekitio::Resources::Files (readonly)



39
40
41
# File 'lib/imagekitio/client.rb', line 39

def files
  @files
end

#foldersImagekitio::Resources::Folders (readonly)



51
52
53
# File 'lib/imagekitio/client.rb', line 51

def folders
  @folders
end

#helperImagekitio::Helper (readonly)

Returns:



63
64
65
# File 'lib/imagekitio/client.rb', line 63

def helper
  @helper
end

#passwordString? (readonly)

ImageKit uses your API key as username and ignores the password. The SDK sets a dummy value. You can ignore this field.

Returns:

  • (String, nil)


26
27
28
# File 'lib/imagekitio/client.rb', line 26

def password
  @password
end

#private_keyString (readonly)

Your ImageKit private API key (starts with ‘private_`). You can find this in the [ImageKit dashboard](imagekit.io/dashboard/developer/api-keys).

Returns:

  • (String)


21
22
23
# File 'lib/imagekitio/client.rb', line 21

def private_key
  @private_key
end

#saved_extensionsImagekitio::Resources::SavedExtensions (readonly)



42
43
44
# File 'lib/imagekitio/client.rb', line 42

def saved_extensions
  @saved_extensions
end

#webhook_secretString? (readonly)

Your ImageKit webhook secret for verifying webhook signatures (starts with ‘whsec_`). You can find this in the [ImageKit dashboard](imagekit.io/dashboard/developer/webhooks). Only required if you’re using webhooks.

Returns:

  • (String, nil)


33
34
35
# File 'lib/imagekitio/client.rb', line 33

def webhook_secret
  @webhook_secret
end

#webhooksImagekitio::Resources::Webhooks (readonly)



60
61
62
# File 'lib/imagekitio/client.rb', line 60

def webhooks
  @webhooks
end

Instance Method Details

#base_url_overridden?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


78
# File 'lib/imagekitio/client.rb', line 78

def base_url_overridden? = @base_url_overridden