Class: ActiveWebhook::Delivery::BaseAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/active_webhook/delivery/base_adapter.rb

Direct Known Subclasses

FaradayAdapter, NetHTTPAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

attribute, attributes, #attributes, call, component_configuration, #component_configuration, configuration, #configuration, #initialize

Constructor Details

This class inherits a constructor from ActiveWebhook::Adapter

Instance Attribute Details

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/active_webhook/delivery/base_adapter.rb', line 7

def response
  @response
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_webhook/delivery/base_adapter.rb', line 15

def call
  ensure_error_log_requirement_is_met!

  wrap_with_log do
    self.response = deliver!

    case status_code
    when 200
      trace "Completed"
    when 410
      trace "Receieved HTTP response code [410] for"
      subscription.destroy!
    else
      raise response.to_s
    end
  end
rescue StandardError => e
  subscription.error_logs.create!

  raise e # propogate error so queuing adapter has a chance to retry
end

#max_errors_per_hourObject



11
12
13
# File 'lib/active_webhook/delivery/base_adapter.rb', line 11

def max_errors_per_hour
  @max_errors_per_hour.nil? ? component_configuration.max_errors_per_hour : @max_errors_per_hour
end

#status_codeObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/active_webhook/delivery/base_adapter.rb', line 37

def status_code
  raise NotImplementedError, "#deliver! must be implemented."
end

#topicObject



41
42
43
# File 'lib/active_webhook/delivery/base_adapter.rb', line 41

def topic
  subscription.topic
end