Class: Newshound::Exceptions::Bugsink
- Defined in:
- lib/newshound/exceptions/bugsink.rb
Class Method Summary collapse
Instance Method Summary collapse
- #format_for_banner(issue) ⇒ Object
- #format_for_report(issue, number) ⇒ Object
-
#initialize(config = {}) ⇒ Bugsink
constructor
A new instance of Bugsink.
- #recent(time_range:, limit:) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Bugsink
Returns a new instance of Bugsink.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/newshound/exceptions/bugsink.rb', line 15 def initialize(config = {}) super config = config.transform_keys(&:to_sym) missing = self.class.required_keys.select { |key| config[key].nil? } if missing.any? raise ArgumentError, "Bugsink requires #{missing.map { |k| ":#{k}" }.join(", ")} in exception_source_config" end @url = config[:url] @token = config[:token] @project_id = config[:project_id] end |
Class Method Details
.required_keys ⇒ Object
11 12 13 |
# File 'lib/newshound/exceptions/bugsink.rb', line 11 def self.required_keys %i[url token project_id].freeze end |
Instance Method Details
#format_for_banner(issue) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/newshound/exceptions/bugsink.rb', line 47 def (issue) { id: issue["id"], title: issue["calculated_type"] || "Unknown", message: (issue["calculated_value"] || "").truncate(100), location: issue["transaction"] || "", time: Time.parse(issue["last_seen"]).strftime("%I:%M %p") } end |
#format_for_report(issue, number) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/newshound/exceptions/bugsink.rb', line 39 def format_for_report(issue, number) <<~TEXT *#{number}. #{issue["calculated_type"] || "Unknown"}* • *Time:* #{Time.parse(issue["last_seen"]).strftime("%I:%M %p")} • *Message:* `#{(issue["calculated_value"] || "").truncate(100)}` TEXT end |
#recent(time_range:, limit:) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/newshound/exceptions/bugsink.rb', line 30 def recent(time_range:, limit:) issues = fetch_issues cutoff = Time.now.utc - time_range issues .select { |i| Time.parse(i["last_seen"]) >= cutoff } .first(limit) end |