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"), 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`

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

Parameters:

  • (defaults to: )

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

  • (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

  • (defaults to: )

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

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

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

  • (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


93
94
95
96
97
98
99
100
101
102
103
104
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
# File 'lib/imagekitio/client.rb', line 93

def initialize(
  private_key: ENV["IMAGEKIT_PRIVATE_KEY"],
  password: ENV.fetch("OPTIONAL_IMAGEKIT_IGNORES_THIS", "do_not_set"),
  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

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

   = 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)

Returns:



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

def accounts
  @accounts
end

#assetsImagekitio::Resources::Assets (readonly)

Returns:



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

def assets
  @assets
end

#betaImagekitio::Resources::Beta (readonly)

Returns:



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

def beta
  @beta
end

#cacheImagekitio::Resources::Cache (readonly)

Returns:



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

def cache
  @cache
end

#custom_metadata_fieldsImagekitio::Resources::CustomMetadataFields (readonly)

Returns:



29
30
31
# File 'lib/imagekitio/client.rb', line 29

def 
  
end

#filesImagekitio::Resources::Files (readonly)

Returns:



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

def files
  @files
end

#foldersImagekitio::Resources::Folders (readonly)

Returns:



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

def folders
  @folders
end

#helperImagekitio::Helper (readonly)

Returns:



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

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:



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:



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

def private_key
  @private_key
end

#saved_extensionsImagekitio::Resources::SavedExtensions (readonly)

Returns:



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

def saved_extensions
  @saved_extensions
end

#webhooksImagekitio::Resources::Webhooks (readonly)

Returns:



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

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:

API:

  • private



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

def base_url_overridden? = @base_url_overridden