Class: Mailgun::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun/metrics/metrics.rb

Overview

A Mailgun::Metrics object is a simple interface to Mailgun Metrics. Uses Mailgun

Instance Method Summary collapse

Constructor Details

#initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1')) ⇒ Metrics

Public: creates a new Mailgun::Metrics instance. Defaults to Mailgun::Client



7
8
9
# File 'lib/mailgun/metrics/metrics.rb', line 7

def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v1'))
  @client = client
end

Instance Method Details

#account_metrics(options = {}) ⇒ Object

Public: Post query to get account metrics

options - [Hash] of

start - [String] A start date (default: 7 days before current time). Must be in RFC 2822 format.
end - [String] An end date (default: current time). Must be in RFC 2822 format.
resolution - [String] A resolution in the format of 'day' 'hour' 'month'. Default is day.
duration - [String] A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.
dimensions - [Array] Attributes of the metric data such as 'subaccount'.
metrics - [Array] Name of the metrics to receive the stats for such as 'processed_count'
filter - [Object]
    AND: - [Array] of objects
        attribute - [String]
        comparator - [String]
        values - [Array] of objects
            label - [String]
            value - [String]
include_subaccounts - [Boolean] Include stats from all subaccounts.
include_aggregates - [Boolean] Include top-level aggregate metrics.

Returns [Hash] Metrics



31
32
33
# File 'lib/mailgun/metrics/metrics.rb', line 31

def (options={})
  @client.post('analytics/metrics', options.to_json, { "Content-Type" => "application/json" }).to_h!
end

#account_usage_metrics(options = {}) ⇒ Object

Public: Post query to get account usage metrics

options - [Hash] of

start - [String] A start date (default: 7 days before current time). Must be in RFC 2822 format.
end - [String] An end date (default: current time). Must be in RFC 2822 format.
resolution - [String] A resolution in the format of 'day' 'hour' 'month'. Default is day.
duration - [String] A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.
dimensions - [Array] Attributes of the metric data such as 'subaccount'.
metrics - [Array] Name of the metrics to receive the stats for such as 'processed_count'
filter - [Object]
    AND: - [Array] of objects
        attribute - [String]
        comparator - [String]
        values - [Array] of objects
            label - [String]
            value - [String]
include_subaccounts - [Boolean] Include stats from all subaccounts.
include_aggregates - [Boolean] Include top-level aggregate metrics.

Returns [Hash] Metrics



55
56
57
# File 'lib/mailgun/metrics/metrics.rb', line 55

def (options={})
  @client.post('analytics/usage/metrics', options.to_json, { "Content-Type" => "application/json" }).to_h!
end