Class: Magic

Inherits:
Object
  • Object
show all
Defined in:
lib/magic-admin.rb

Overview

Magic Class to access resources

Constant Summary collapse

RETRIES =
3
TIMEOUT =
5
BACKOFF =
0.02

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_secret_key: nil, retries: nil, timeout: nil, backoff: nil) ⇒ Magic

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


71
72
73
74
75
76
77
# 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

Instance Attribute Details

#http_clientObject (readonly)

attribute reader for magic http client



38
39
40
# File 'lib/magic-admin.rb', line 38

def http_client
  @http_client
end

#secret_keyObject (readonly)

attribute reader for magic api secret key



35
36
37
# File 'lib/magic-admin.rb', line 35

def secret_key
  @secret_key
end

Instance Method Details

#tokenObject

Description:

Method provides you Token object
for various utility methods of Token.

Returns:

A Token object that provides access to
all the supported resources.


99
100
101
# File 'lib/magic-admin.rb', line 99

def token
  MagicAdmin::Resource::Token.new
end

#userObject

Description:

Method provides you User object
for interacting with the Magic API.

Returns:

A User object that provides access to
all the supported resources.


87
88
89
# File 'lib/magic-admin.rb', line 87

def user
  MagicAdmin::Resource::User.new(self)
end