Class: TRMNLP::Poller
- Inherits:
-
Object
- Object
- TRMNLP::Poller
- Defined in:
- lib/trmnlp/poller.rb
Instance Method Summary collapse
-
#initialize(config:, paths:, oauth_session:, reporter: Reporter.new) ⇒ Poller
constructor
A new instance of Poller.
- #poll_data ⇒ Object
- #put_webhook(payload) ⇒ Object
Constructor Details
#initialize(config:, paths:, oauth_session:, reporter: Reporter.new) ⇒ Poller
Returns a new instance of Poller.
11 12 13 14 15 16 |
# File 'lib/trmnlp/poller.rb', line 11 def initialize(config:, paths:, oauth_session:, reporter: Reporter.new) @config = config @paths = paths @oauth_session = oauth_session @reporter = reporter end |
Instance Method Details
#poll_data ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trmnlp/poller.rb', line 18 def poll_data return unless config.plugin.polling? raise InvalidConfig, 'config must specify polling_url or polling_urls' if config.plugin.polling_urls.empty? data = aggregate_responses write_user_data(data) data # NOTE: trmnlp is a dev tool — a flaky upstream API should surface a warning # and keep the preview server alive, not crash the user's session. We # deliberately swallow here and return {} so the renderer keeps rendering. rescue StandardError => e reporter.info(reporter.yellow("warning: #{e.}")) {} end |
#put_webhook(payload) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/trmnlp/poller.rb', line 33 def put_webhook(payload) write_user_data(wrap_array(JSON.parse(payload))) # NOTE: Same rationale as #poll_data — a bad webhook payload shouldn't take # down the dev server. Report a warning and keep serving. rescue StandardError => e reporter.info(reporter.yellow("webhook warning: #{e.}")) end |