Class: ActiveRecordStreams::Publishers::HttpStream
- Inherits:
-
Object
- Object
- ActiveRecordStreams::Publishers::HttpStream
- Defined in:
- lib/active_record_streams/publishers/http_stream.rb
Constant Summary collapse
- ANY_TABLE =
'*'- SUCCESSFUL_CODE_REGEX =
/\A2\d{2}\z/.freeze
- DEFAULT_CONTENT_TYPE =
'application/json'
Instance Method Summary collapse
-
#initialize(url:, headers: {}, table_name: ANY_TABLE, ignored_tables: [], error_handler: nil) ⇒ HttpStream
constructor
A new instance of HttpStream.
- #publish(table_name, message) ⇒ Object
Constructor Details
#initialize(url:, headers: {}, table_name: ANY_TABLE, ignored_tables: [], error_handler: nil) ⇒ HttpStream
Returns a new instance of HttpStream.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record_streams/publishers/http_stream.rb', line 19 def initialize( url:, headers: {}, table_name: ANY_TABLE, ignored_tables: [], error_handler: nil ) @url = url @headers = headers @table_name = table_name @ignored_tables = ignored_tables @error_handler = error_handler end |
Instance Method Details
#publish(table_name, message) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_record_streams/publishers/http_stream.rb', line 33 def publish(table_name, ) return unless (any_table? && allowed_table?(table_name)) || table_name == @table_name request.body = .json response = http.request(request) assert_response_code(response) rescue StandardError => e raise e unless @error_handler.is_a?(Proc) @error_handler.call(self, table_name, , e) end |