Class: MailerLog::Api::EmailsController

Inherits:
MailerLog::AdminController show all
Defined in:
app/controllers/mailer_log/api/emails_controller.rb

Constant Summary collapse

BASE_EMAIL_ATTRIBUTES =
i[
  id tracking_id message_id mailer_class mailer_action
  from_address to_addresses cc_addresses bcc_addresses
  subject domain status delivered_at opened_at clicked_at
  bounced_at created_at updated_at
].freeze
BODY_ATTRIBUTES =
i[html_body text_body headers call_stack git_revision].freeze
EVENT_ATTRIBUTES =
i[
  id event_type occurred_at recipient ip_address user_agent
  device_type client_name client_os country region city url raw_payload
].freeze

Instance Method Summary collapse

Instance Method Details

#index ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/mailer_log/api/emails_controller.rb', line 20

def index
  emails = apply_filters(MailerLog::Email.order(created_at: :desc))
    .page(params[:page])
    .per(params[:per] || 25)

  render json: {
    emails: emails.map { |e| email_json(e) },
    total_count: emails.total_count,
    total_pages: emails.total_pages,
    current_page: emails.current_page
  }
end

#show ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/mailer_log/api/emails_controller.rb', line 33

def show
  email = MailerLog::Email.find(params[:id])

  render json: {
    email: email_json(email, include_body: true, include_events: true),
    config: {
      show_delivery_events: MailerLog.configuration.show_delivery_events?,
      github_repo: MailerLog.configuration.github_repo
    }
  }
end