Class: PagerTree::Integrations::Integration

Inherits:
Object
  • Object
show all
Extended by:
BooleanStoreAccessor
Defined in:
app/models/pager_tree/integrations/integration.rb

Constant Summary collapse

GENERIC_OPTIONS =
[
  {key: :title_template, type: :string, default: nil},
  {key: :title_template_enabled, type: :boolean, default: false},
  {key: :description_template, type: :string, default: nil},
  {key: :description_template_enabled, type: :boolean, default: false}
]

Instance Method Summary collapse

Methods included from BooleanStoreAccessor

boolean_store_accessor

Instance Method Details

#adapter_actionObject

Returns :create, :resolve, or :other



52
53
54
# File 'app/models/pager_tree/integrations/integration.rb', line 52

def adapter_action
  :other
end

#adapter_incoming_can_defer?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/pager_tree/integrations/integration.rb', line 47

def adapter_incoming_can_defer?
  true
end

#adapter_outgoing_interest?(event_name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/pager_tree/integrations/integration.rb', line 72

def adapter_outgoing_interest?(event_name)
  false
end

#adapter_process_createObject



56
57
# File 'app/models/pager_tree/integrations/integration.rb', line 56

def adapter_process_create
end

#adapter_process_otherObject



59
60
# File 'app/models/pager_tree/integrations/integration.rb', line 59

def adapter_process_other
end

#adapter_process_outgoingObject



76
77
# File 'app/models/pager_tree/integrations/integration.rb', line 76

def adapter_process_outgoing
end

#adapter_response_blockedObject



128
129
130
# File 'app/models/pager_tree/integrations/integration.rb', line 128

def adapter_response_blocked
  adapter_controller&.head(:forbidden)
end

#adapter_response_deferredObject



132
133
134
# File 'app/models/pager_tree/integrations/integration.rb', line 132

def adapter_response_deferred
  adapter_controller&.head(:ok)
end

#adapter_response_disabledObject



112
113
114
# File 'app/models/pager_tree/integrations/integration.rb', line 112

def adapter_response_disabled
  adapter_controller&.head(:method_not_allowed)
end

#adapter_response_inactive_subscriptionObject



116
117
118
# File 'app/models/pager_tree/integrations/integration.rb', line 116

def adapter_response_inactive_subscription
  adapter_controller&.head(:payment_required)
end

#adapter_response_incomingObject



136
137
138
# File 'app/models/pager_tree/integrations/integration.rb', line 136

def adapter_response_incoming
  adapter_controller&.head(:ok)
end

#adapter_response_maintenance_modeObject



124
125
126
# File 'app/models/pager_tree/integrations/integration.rb', line 124

def adapter_response_maintenance_mode
  adapter_controller&.head(:ok)
end

#adapter_response_rate_limitObject

END basic show functions



108
109
110
# File 'app/models/pager_tree/integrations/integration.rb', line 108

def adapter_response_rate_limit
  adapter_controller&.head(:too_many_requests)
end

#adapter_response_upgradeObject



120
121
122
# File 'app/models/pager_tree/integrations/integration.rb', line 120

def adapter_response_upgrade
  adapter_controller&.head(:payment_required)
end

#adapter_should_block_incoming?(request) ⇒ Boolean

a function to determine if we should block the incoming request (e.g. if the payload doesn’t match a signature)

Returns:

  • (Boolean)


38
39
40
# File 'app/models/pager_tree/integrations/integration.rb', line 38

def adapter_should_block_incoming?(request)
  false
end

#adapter_show_alerts?Boolean

START basic show functions

Returns:

  • (Boolean)


95
96
97
# File 'app/models/pager_tree/integrations/integration.rb', line 95

def adapter_show_alerts?
  adapter_supports_incoming?
end

#adapter_show_logs?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/pager_tree/integrations/integration.rb', line 99

def adapter_show_logs?
  true
end

#adapter_show_outgoing_webhook_delivery?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/models/pager_tree/integrations/integration.rb', line 103

def adapter_show_outgoing_webhook_delivery?
  false
end

#adapter_supports_cnames?Boolean

END template functions

Returns:

  • (Boolean)


90
91
92
# File 'app/models/pager_tree/integrations/integration.rb', line 90

def adapter_supports_cnames?
  false
end

#adapter_supports_description_template?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/pager_tree/integrations/integration.rb', line 85

def adapter_supports_description_template?
  true
end

#adapter_supports_incoming?Boolean

START basic incoming functions

Returns:

  • (Boolean)


33
34
35
# File 'app/models/pager_tree/integrations/integration.rb', line 33

def adapter_supports_incoming?
  false
end

#adapter_supports_outgoing?Boolean

START basic outgoing functions

Returns:

  • (Boolean)


68
69
70
# File 'app/models/pager_tree/integrations/integration.rb', line 68

def adapter_supports_outgoing?
  false
end

#adapter_supports_title_template?Boolean

START template functions

Returns:

  • (Boolean)


81
82
83
# File 'app/models/pager_tree/integrations/integration.rb', line 81

def adapter_supports_title_template?
  true
end

#adapter_thirdparty_idObject

A unique identifier for this integration/alert



43
44
45
# File 'app/models/pager_tree/integrations/integration.rb', line 43

def adapter_thirdparty_id
  ULID.generate
end

#adapter_will_route_alert?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/pager_tree/integrations/integration.rb', line 62

def adapter_will_route_alert?
  false
end

#cast_typesObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/models/pager_tree/integrations/integration.rb', line 140

def cast_types
  (self.class.const_get(:GENERIC_OPTIONS) + self.class.const_get(:OPTIONS)).each do |option|
    key = option[:key]
    value = send("option_#{key}")
    type = option[:type]

    value = ActiveModel::Type::Boolean.new.cast(value) if type == :boolean
    value = ActiveModel::Type::String.new.cast(value) if type == :string
    value = ActiveModel::Type::Integer.new.cast(value) if type == :integer

    value = option[:default] if value.nil? && option.has_key?(:default)

    send("option_#{key}=", value)
  end
end