Class: CommandTower::Messaging::Endpoints::Pushover::Verify

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/endpoints/pushover/verify.rb

Overview

Single verification authority for Pushover endpoints. begin → decrypt → validate.json → test messages.json → mark_verified | mark_verification_failed

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_user_id:, endpoint_id:) ⇒ Verify

Returns a new instance of Verify.



14
15
16
17
# File 'app/services/command_tower/messaging/endpoints/pushover/verify.rb', line 14

def initialize(owner_user_id:, endpoint_id:)
  @owner_user_id = owner_user_id
  @endpoint_id = endpoint_id
end

Class Method Details

.call(owner_user_id:, endpoint_id:) ⇒ Object



10
11
12
# File 'app/services/command_tower/messaging/endpoints/pushover/verify.rb', line 10

def self.call(owner_user_id:, endpoint_id:)
  new(owner_user_id:, endpoint_id:).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/command_tower/messaging/endpoints/pushover/verify.rb', line 19

def call
  record = load_active_pushover!
  assert_adapter_enabled!

  begin_verification_lifecycle!(record)
  credentials = SecretReader.read_pushover_credentials!(
    owner_user_id: @owner_user_id,
    endpoint_id: @endpoint_id,
  )

  validate_result = Messaging::Pushover::Transport.validate_user!(
    user_key: credentials.fetch(:user_key),
    application_token: credentials.fetch(:application_token),
  )
  unless validate_result.success?
    raise_after_failed!(validate_result)
  end

  config = CommandTower.config.messaging.pushover
  test_result = Messaging::Pushover::Transport.send_test_notification!(
    user_key: credentials.fetch(:user_key),
    application_token: credentials.fetch(:application_token),
    title: config.test_title,
    message: config.test_message,
  )
  unless test_result.success?
    raise_after_failed!(test_result)
  end

  MarkVerified.call(owner_user_id: @owner_user_id, endpoint_id: @endpoint_id)
end