Module: CommandTower::Services::Account::Pushover::CtSupport

Defined in:
app/services/command_tower/services/account/pushover/ct_support.rb

Overview

Shared CT Endpoints helpers for Account Pushover capability services.

Class Method Summary collapse

Class Method Details

.active_endpoint(user) ⇒ Object



11
12
13
14
15
16
17
# File 'app/services/command_tower/services/account/pushover/ct_support.rb', line 11

def active_endpoint(user)
  views = CommandTower::Messaging::Endpoints.list(
    owner_user_id: user.id,
    channel_key: "pushover"
  )
  views.find { |view| view.lifecycle_state.to_s == "active" }
end

.map_ct_exception!(error) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/command_tower/services/account/pushover/ct_support.rb', line 19

def map_ct_exception!(error)
  case error
  when CommandTower::Messaging::Endpoints::VerificationFailedError
    map_verification_failed!(error)
  when CommandTower::Messaging::Endpoints::ConflictError
    CommandTower::Errors::Account::PushoverAlreadyConfiguredError.new
  when CommandTower::Messaging::Endpoints::NotFoundError
    CommandTower::Errors::Account::PushoverNotConfiguredError.new
  when CommandTower::Messaging::Endpoints::ValidationError
    if error.message.to_s.include?("disabled")
      CommandTower::Errors::Account::PushoverCapabilityUnavailableError.new
    else
      CommandTower::Errors::ValidationError.new(details: { base: "Invalid Pushover credentials" })
    end
  else
    CommandTower::Errors::InternalError.new
  end
end

.map_verification_failed!(error) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/services/command_tower/services/account/pushover/ct_support.rb', line 38

def map_verification_failed!(error)
  case error.error_code
  when :invalid_user
    CommandTower::Errors::Account::PushoverVerificationFailedError.new(
      code: "pushover_invalid_user",
      message: "Pushover user key is invalid"
    )
  when :invalid_token
    CommandTower::Errors::Account::PushoverVerificationFailedError.new(
      code: "pushover_invalid_token",
      message: "Pushover application token is invalid"
    )
  when :invalid_credentials
    CommandTower::Errors::Account::PushoverVerificationFailedError.new(
      code: "pushover_invalid_credentials",
      message: "Pushover credentials were rejected"
    )
  when :timeout
    CommandTower::Errors::Account::PushoverVerificationFailedError.new(
      code: "pushover_provider_timeout",
      message: "Pushover provider timed out"
    )
  when :provider_unavailable
    CommandTower::Errors::Account::PushoverProviderUnavailableError.new
  else
    CommandTower::Errors::Account::PushoverVerificationFailedError.new
  end
end