Class: FeishuNotifier::Config

Inherits:
Data
  • Object
show all
Defined in:
lib/feishu_notifier/config.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://open.feishu.cn".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id

Returns:

  • (Object)

    the current value of app_id



2
3
4
# File 'lib/feishu_notifier/config.rb', line 2

def app_id
  @app_id
end

#app_secretObject (readonly)

Returns the value of attribute app_secret

Returns:

  • (Object)

    the current value of app_secret



2
3
4
# File 'lib/feishu_notifier/config.rb', line 2

def app_secret
  @app_secret
end

#base_urlObject (readonly)

Returns the value of attribute base_url

Returns:

  • (Object)

    the current value of base_url



2
3
4
# File 'lib/feishu_notifier/config.rb', line 2

def base_url
  @base_url
end

#user_idObject (readonly)

Returns the value of attribute user_id

Returns:

  • (Object)

    the current value of user_id



2
3
4
# File 'lib/feishu_notifier/config.rb', line 2

def user_id
  @user_id
end

Class Method Details

.fetch_required(env, key) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/feishu_notifier/config.rb', line 14

def self.fetch_required(env, key)
  value = env[key].to_s.strip
  raise ArgumentError, "Missing required environment variable: #{key}" if value.empty?

  value
end

.from_env(env = ENV) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/feishu_notifier/config.rb', line 5

def self.from_env(env = ENV)
  new(
    app_id: fetch_required(env, "FEISHU_APP_ID"),
    app_secret: fetch_required(env, "FEISHU_APP_SECRET"),
    user_id: fetch_required(env, "FEISHU_USER_ID"),
    base_url: env.fetch("FEISHU_BASE_URL", DEFAULT_BASE_URL)
  )
end