Class: Mailtrap::MarketingStatsAPI

Inherits:
Object
  • Object
show all
Includes:
BaseAPI, StatsQueryParams
Defined in:
lib/mailtrap/marketing_stats_api.rb

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included

Constructor Details

#initialize(client = Mailtrap::Client.new) ⇒ MarketingStatsAPI

Returns a new instance of MarketingStatsAPI.

Parameters:

  • client (Mailtrap::Client) (defaults to: Mailtrap::Client.new) —

    The client instance



13
14
15
# File 'lib/mailtrap/marketing_stats_api.rb', line 13

def initialize(client = Mailtrap::Client.new)
  @client = client
end

Instance Method Details

#get(start_date:, end_date:, sending_domain_ids: nil, sources: nil, email_service_providers: nil) ⇒ MarketingStats

Get aggregated Email Marketing stats: campaigns and automations together, the same numbers as Email Marketing > Stats Overview in the app. Email API/SMTP traffic is reported by StatsAPI.

Parameters:

  • start_date (String, Date, Time) —

    Start of the period, inclusive (required)

  • end_date (String, Date, Time) —

    End of the period, inclusive (required)

  • sending_domain_ids (Array<Integer>) (defaults to: nil) —

    Filter by domain IDs

  • sources (Array<String>) (defaults to: nil) —

    Filter by source: campaigns or automations; omit it, or pass both, to include campaigns and automations together

  • email_service_providers (Array<String>) (defaults to: nil) —

    Filter by recipient email service providers

Returns:

Raises:



28
29
30
31
32
33
34
35
# File 'lib/mailtrap/marketing_stats_api.rb', line 28

def get(start_date:, end_date:, sending_domain_ids: nil, sources: nil, email_service_providers: nil)
  query_params = build_query_params(
    start_date, end_date,
    { sending_domain_ids:, sources:, email_service_providers: }
  )
  response = client.get(base_path, query_params)
  build_entity(response[:data], MarketingStats)
end