diff --git a/README.md b/README.md index c3586ce..1c2d53a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ end begin 1 / 0 rescue ZeroDivisionError => e - Telebugs.notify(error: e) + Telebugs.report(e) end sleep 2 diff --git a/lib/telebugs.rb b/lib/telebugs.rb index cd5b6b4..4bd2f2d 100644 --- a/lib/telebugs.rb +++ b/lib/telebugs.rb @@ -7,7 +7,7 @@ require_relative "telebugs/version" require_relative "telebugs/config" require_relative "telebugs/promise" -require_relative "telebugs/notifier" +require_relative "telebugs/reporter" require_relative "telebugs/sender" require_relative "telebugs/wrapped_error" require_relative "telebugs/report" @@ -30,8 +30,8 @@ def configure yield Config.instance end - def notify(error:) - Notifier.instance.notify(error) + def report(error) + Reporter.instance.report(error) end end end diff --git a/lib/telebugs/config.rb b/lib/telebugs/config.rb index 792c380..c7515f0 100644 --- a/lib/telebugs/config.rb +++ b/lib/telebugs/config.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module Telebugs - # Represents the Telebugs config. A config contains all the options that you - # can use to configure a +Telebugs::Notifier+ instance. class Config ERROR_API_URL = "https://api.telebugs.com/2024-03-28/errors" diff --git a/lib/telebugs/notifier.rb b/lib/telebugs/reporter.rb similarity index 82% rename from lib/telebugs/notifier.rb rename to lib/telebugs/reporter.rb index f605530..a41cd2d 100644 --- a/lib/telebugs/notifier.rb +++ b/lib/telebugs/reporter.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Telebugs - # Notifier is reponsible for sending reports to Telebugs. - class Notifier + # Reporter is reponsible for sending reports to Telebugs. + class Reporter class << self attr_writer :instance @@ -16,7 +16,7 @@ def initialize @middleware = Config.instance.middleware end - def notify(error) + def report(error) Telebugs::Promise.new(error) do report = Report.new(error) diff --git a/test/test_notifier.rb b/test/test_reporter.rb similarity index 70% rename from test/test_notifier.rb rename to test/test_reporter.rb index b0d4962..605aede 100644 --- a/test/test_notifier.rb +++ b/test/test_reporter.rb @@ -8,34 +8,34 @@ def call(report) end end -class TestNotifier < Minitest::Test +class TestReporter < Minitest::Test def teardown WebMock.reset! Telebugs::Config.instance.reset end - def test_notify_returns_a_promise_that_resolves_to_a_hash + def test_report_returns_a_promise_that_resolves_to_a_hash stub = stub_request(:post, Telebugs::Config.instance.api_url) .to_return(status: 201, body: {id: "123"}.to_json) - p = Telebugs::Notifier.new.notify(StandardError.new) + p = Telebugs::Reporter.new.report(StandardError.new) assert_equal({"id" => "123"}, p.value) assert_requested stub end - def test_notify_returns_a_promise_that_rejects_on_http_error + def test_reporter_returns_a_promise_that_rejects_on_http_error stub = stub_request(:post, Telebugs::Config.instance.api_url) .to_return(status: 500) - p = Telebugs::Notifier.new.notify(StandardError.new) + p = Telebugs::Reporter.new.report(StandardError.new) assert_nil p.value assert_instance_of(Telebugs::HTTPError, p.reason) assert_requested stub end - def test_notify_does_not_send_ignored_errors + def test_reporter_does_not_send_ignored_errors stub = stub_request(:post, Telebugs::Config.instance.api_url) .to_return(status: 201, body: {id: "123"}.to_json) @@ -43,7 +43,7 @@ def test_notify_does_not_send_ignored_errors c.middleware.use TestIgnoreMiddleware.new end - p = Telebugs::Notifier.new.notify(StandardError.new) + p = Telebugs::Reporter.new.report(StandardError.new) p.wait refute_requested stub diff --git a/test/test_telebugs.rb b/test/test_telebugs.rb index 9585329..58e2234 100644 --- a/test/test_telebugs.rb +++ b/test/test_telebugs.rb @@ -22,20 +22,20 @@ def test_configure_configures_project_key assert_equal key, Telebugs::Config.instance.api_key end - def test_notify_returns_a_fullfilled_promise_when_request_succeeds + def test_report_returns_a_fullfilled_promise_when_request_succeeds stub_request(:post, Telebugs::Config.instance.api_url) .to_return(status: 201, body: {id: "123"}.to_json) - p = Telebugs.notify(error: StandardError.new) + p = Telebugs.report(StandardError.new) p.wait assert p.fulfilled? end - def test_notify_returns_a_rejected_promise_when_request_fails + def test_report_returns_a_rejected_promise_when_request_fails stub_request(:post, Telebugs::Config.instance.api_url).to_return(status: 500) - p = Telebugs.notify(error: StandardError.new) + p = Telebugs.report(StandardError.new) p.wait assert p.rejected?