class Magic
Magic
Class to access resources
Constants
- BACKOFF
- RETRIES
- TIMEOUT
Attributes
http_client[R]
attribute reader for magic http client
secret_key[R]
attribute reader for magic api secret key
Public Class Methods
new(api_secret_key: nil, retries: nil, timeout: nil, backoff: nil)
click to toggle source
The constructor allows you to specify your own API secret key and HTTP request strategy when your application interacting with the Magic
API.
It will automatically configure required arguments using the following environment variables
MAGIC_API_SECRET_KEY MAGIC_API_RETRIES MAGIC_API_TIMEOUT MAGIC_API_BACKOFF
Arguments:
api_secret_key: Your API Secret Key retrieved from the Magic Dashboard. retries: Total number of retries to allow. timeout: A period of time the request is going to wait for a response. backoff: A backoff factor to apply between retry attempts.
Returns:
A Magic object that provides access to all the supported resources.
Examples:
Magic.new Magic.new api_secret_key: "SECRET_KEY>" Magic.new api_secret_key: "SECRET_KEY>", retries: 2, timeout: 2, backoff: 0.2
# File lib/magic-admin.rb, line 71 def initialize(api_secret_key: nil, retries: nil, timeout: nil, backoff: nil) secret_key!(api_secret_key) http_client!(retries, timeout, backoff) end
Public Instance Methods
token()
click to toggle source
Description:
Method provides you Token object for various utility methods of Token.
Returns:
A Token object that provides access to all the supported resources.
# File lib/magic-admin.rb, line 99 def token MagicAdmin::Resource::Token.new end
user()
click to toggle source
Description:
Method provides you User object for interacting with the Magic API.
Returns:
A User object that provides access to all the supported resources.
# File lib/magic-admin.rb, line 87 def user MagicAdmin::Resource::User.new(self) end
Private Instance Methods
configure_backoff(backoff)
click to toggle source
# File lib/magic-admin.rb, line 124 def configure_backoff(backoff) backoff || ENV["MAGIC_API_BACKOFF"] || BACKOFF end
configure_retries(retries)
click to toggle source
# File lib/magic-admin.rb, line 116 def configure_retries(retries) retries || ENV["MAGIC_API_RETRIES"] || RETRIES end
configure_timeout(timeout)
click to toggle source
# File lib/magic-admin.rb, line 120 def configure_timeout(timeout) timeout || ENV["MAGIC_API_TIMEOUT"] || TIMEOUT end
http_client!(retries, timeout, backoff)
click to toggle source
# File lib/magic-admin.rb, line 128 def http_client!(retries, timeout, backoff) @http_client = MagicAdmin::Http::Client .new(MagicAdmin::Config.api_base, configure_retries(retries), configure_timeout(timeout), configure_backoff(backoff)) end
secret_key!(api_secret_key)
click to toggle source
# File lib/magic-admin.rb, line 109 def secret_key!(api_secret_key) @secret_key = api_secret_key || ENV["MAGIC_API_SECRET_KEY"] message = "Magic api secret key was not found." raise MagicAdmin::MagicError, message unless secret_key? end
secret_key?()
click to toggle source
# File lib/magic-admin.rb, line 105 def secret_key? !(secret_key.nil? || secret_key.empty?) end