Skip to content

Deprecations - Warn on Domains#get_domain_stats and use one warning format - #405

Merged
alex-leb merged 2 commits into
masterfrom
domains-deprecate-get-domain-stats
Oct 20, 2026
Merged

alex-leb merged 2 commits into
masterfrom
domains-deprecate-get-domain-stats

Conversation

@alex-leb

Copy link
Copy Markdown
Contributor

Adds the missing deprecation warning to Domains#get_domain_stats, and moves every deprecation warning in the gem to one format that names the replacement and points at the caller's code.

Missing warning

Mailgun's API docs deprecate three APIs the gem calls. get_domain_stats was the only wrapper that didn't warn.

Gem method Endpoint Deprecated in favor of Warned before
Domains#get_domain_stats GET /v3/{domain}/stats/total Metrics API (Metrics#account_metrics) No
Tags#get_tags and the other Tags methods GET /v3/{domain}/tags Tags API (AnalyticsTags) Yes
Events#get, #next, #previous GET /v3/{domain}/events Logs API (Logs#account_logs) Yes

One warning format

The new Mailgun::Deprecation.warn prints:

app/jobs/report.rb:12: warning: DEPRECATION: "Mailgun::Tags#get_tag" is deprecated (Mailgun deprecated the Tags API) and will be removed in mailgun-ruby 1.5. Please use "Mailgun::AnalyticsTags#list" instead.
  • The location is the first caller outside the gem. It skips the gem's own frames, including the ApiVersionChecker wrappers, so it points at the line to change.
  • The reason only appears where Mailgun deprecated the API, and the removal clause only where a removal is planned.
  • It's used by Domains#get_domain_stats, Events, all 8 Tags methods, the 7 Webhooks aliases and the 7 MessageBuilder setters. The two plain warn calls left (the yes/no value hint and the API version check) aren't deprecations.

Message changes

  • Tags: each method now names its replacement (AnalyticsTags#list, #update, #remove or Metrics#account_metrics) and says it will be removed in 1.5, as the existing TODO: remove in v 1.5 plans. Before, all 8 printed the same line with no replacement.
  • Webhooks aliases: "will be deprecated in future versions of Mailgun" is now "is deprecated and will be removed in a future version of mailgun-ruby". The aliases are already deprecated, and only the gem's old method names are going away, not the endpoints.
  • MessageBuilder setters: same wording as the Webhooks aliases.
  • The warning text changes, so anything matching the old strings needs updating.

Docs

  • docs/Snippets.md used the deprecated set_from_address, set_subject, set_text_body and set_message_id; it now uses from, subject, body_text and message_id.
  • docs/Events.md names Logs#account_logs as the replacement.

Testing

  • New specs for the helper (message format, and the caller location through gem frames and the API version wrappers) and for all 8 Tags warnings, which had no specs.
  • The MessageBuilder deprecation specs check the printed warning instead of stubbing warn; the Webhooks and Domains specs match the new wording.
  • Full suite, run without credentials: 438 examples, 0 failures; line coverage 96.58%; RuboCop clean.

Mailgun's API docs mark GET /v3/{domain}/stats/total as deprecated in
favor of the Metrics API, but Domains#get_domain_stats called it without
a warning. Tags#get_tags and Events already warn for their deprecated
APIs.

- Warn on every get_domain_stats call and point to
  Mailgun::Metrics#account_metrics
- Note the deprecation in the method comment
- Add a spec for the warning
The gem printed deprecation warnings in four formats, and some were
unclear. All 8 Tags methods printed the same line without naming a
replacement or the planned removal in 1.5. The Webhooks aliases said they
"will be deprecated in future versions of Mailgun", although they are
deprecated now and only the gem's old method names are going away.

- Add Mailgun::Deprecation.warn, which prints
  DEPRECATION: "<old>" is deprecated [(<reason>)] [and will be removed
  in <version>]. Please use "<new>" instead.
  prefixed with the first caller outside the gem, so the warning points
  at the code to change rather than at the gem's internals
- Use it for Domains#get_domain_stats, Events, all Tags methods, the
  Webhooks aliases and the MessageBuilder setters
- Name each Tags method's replacement and the removal in mailgun-ruby 1.5
- Replace the deprecated MessageBuilder setters in docs/Snippets.md and
  name Logs#account_logs in docs/Events.md
- Add specs for the helper and the Tags warnings; the MessageBuilder
  specs now check the printed warning instead of stubbing warn
@alex-leb
alex-leb merged commit d0a2445 into master Oct 20, 2026
8 checks passed
@alex-leb alex-leb self-assigned this Oct 20, 2026
@alex-leb
alex-leb deleted the domains-deprecate-get-domain-stats branch October 20, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant