Class: FeishuNotifier::Client

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

Constant Summary collapse

TOKEN_PATH =
"/open-apis/auth/v3/tenant_access_token/internal".freeze
MESSAGE_PATH =
"/open-apis/im/v1/messages".freeze

Instance Method Summary collapse

Constructor Details

#initialize(config:, http: Net::HTTP) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/feishu_notifier/client.rb', line 10

def initialize(config:, http: Net::HTTP)
  @config = config
  @http = http
end

Instance Method Details

#send_card(card, user_id: @config.user_id) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/feishu_notifier/client.rb', line 23

def send_card(card, user_id: @config.user_id)
  send_message(
    user_id: user_id,
    msg_type: "interactive",
    content: card
  )
end

#send_text(text, user_id: @config.user_id) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/feishu_notifier/client.rb', line 15

def send_text(text, user_id: @config.user_id)
  send_message(
    user_id: user_id,
    msg_type: "text",
    content: { text: text }
  )
end

#tenant_access_tokenObject

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/feishu_notifier/client.rb', line 31

def tenant_access_token
  response = post_json(
    TOKEN_PATH,
    {
      app_id: @config.app_id,
      app_secret: @config.app_secret
    }
  )

  token = response["tenant_access_token"].to_s
  raise ApiError, "Feishu token response did not include tenant_access_token" if token.empty?

  token
end