Class: EurekaBot::Tg::Webhook

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/eureka_bot/tg/webhook.rb

Defined Under Namespace

Classes: TokenVerificationFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, resolver_class:) ⇒ Webhook

Returns a new instance of Webhook.



9
10
11
12
# File 'lib/eureka_bot/tg/webhook.rb', line 9

def initialize(params:, resolver_class:)
  @params         = params
  @resolver_class = resolver_class
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/eureka_bot/tg/webhook.rb', line 7

def params
  @params
end

#resolver_classObject (readonly)

Returns the value of attribute resolver_class.



7
8
9
# File 'lib/eureka_bot/tg/webhook.rb', line 7

def resolver_class
  @resolver_class
end

Instance Method Details

#check_token(valid_token, token_path: [:token]) ⇒ Object



20
21
22
23
# File 'lib/eureka_bot/tg/webhook.rb', line 20

def check_token(valid_token, token_path: [:token])
  token = params.dig(*token_path)
  token.to_s == valid_token.to_s
end

#check_token!(valid_token, token_path: [:token]) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/eureka_bot/tg/webhook.rb', line 25

def check_token!(valid_token, token_path: [:token])
  check_token(valid_token, token_path: token_path) || (raise TokenVerificationFailed.new({
                                                                                             expected_token: valid_token,
                                                                                             token_path:     token_path,
                                                                                             params:         params
                                                                                         }.to_json))
end

#processObject



14
15
16
17
18
# File 'lib/eureka_bot/tg/webhook.rb', line 14

def process
  instrument 'eureka-bot.tg.webhook', params: params do
    EurekaBot::Job::Input.perform_later(resolver_class.to_s, params)
  end
end