class Mailgun::Tags

Uses Mailgun
A Mailgun::Tags object is a simple CRUD interface to Mailgun Tags.

def get_countries_aggregated_stats(domain, tag)

Returns [Hash] of countries of origin for a given domain

tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Get a list of countries of origin for a given domain for different event types.
def get_countries_aggregated_stats(domain, tag)
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.get("#{domain}/tags/#{tag}/stats/aggregates/countries").to_h
end

def get_devices_aggregated_stats(domain, tag)

Returns [Hash] of devices for a given domain

tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Get a list of devices for a given domain that have triggered event types.
def get_devices_aggregated_stats(domain, tag)
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.get("#{domain}/tags/#{tag}/stats/aggregates/devices").to_h
end

def get_providers_aggregated_stats(domain, tag)

Returns [Hash] of email providers for a given domain

tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Get a list of email providers for a given domain for different event types
def get_providers_aggregated_stats(domain, tag)
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.get("#{domain}/tags/#{tag}/stats/aggregates/providers").to_h
end

def get_tag(domain, tag)

Returns [Hash] Information on the requested tag.

tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Get tag information
def get_tag(domain, tag)
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.get("#{domain}/tags/#{tag}").to_h!
end

def get_tag_stats(domain, tag, options = {})

Returns [Hash] of tag stats info

duration - [String] Period of time with resolution encoded. If provided, overwrites the start date and resolution.
resolution - [String] Can be either hour, day or month. Default: day
end - [String] The ending date. Should be in RFC 2822 or unix epoch time in seconds. Default: current time.
start - [String] The starting time. Should be in RFC 282 or unix epoch format. Default: 7 days from the current time.
event - [String] The type of the event. Required. (ex. accepted, delivered, failed, opened)
options - [Hash] of
tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Get statistics for a given tag
def get_tag_stats(domain, tag, options = {})
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.get("#{domain}/tags/#{tag}/stats", options).to_h
end

def get_tags(domain, options = {})

Returns [Array] A list of tags (hash)

limit - [Integer] Number of entries to return. Default: 100.
options - [Hash] of
domain - [String] Domain name where tag is stored

Public: Get Tags
def get_tags(domain, options = {})
  fail(ParameterError, 'No domain given to store template on', caller) unless domain
  @client.get("#{domain}/tags", options).to_h['items']
end

def initialize(client = Mailgun::Client.new)

Defaults to Mailgun::Client
Public: creates a new Mailgun::Tags instance.
def initialize(client = Mailgun::Client.new)
  @client = client
end

def remove(domain, tag)

Returns [Boolean] if successful or not

tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

NOTE: Deletes the tag. Note: The statistics for the tag are not destroyed.
Public: Delete Tag
def remove(domain, tag)
  fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
  fail(ParameterError, 'No template name given to find on provided domain', caller) unless tag
  @client.delete("#{domain}/tags/#{tag}").to_h['message'] == 'Tag deleted'
end

def update(domain, tag, options = {})

Returns [Boolean] if successful or not

description - [String] Updated description of the tag
options - [Hash] of
tag - [String] Tag name to lookup for
domain - [String] Domain name where tag is stored

Public: Updates a given tag with the information provided
def update(domain, tag, options = {})
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  fail(ParameterError, 'No tag name given to find on provided domain', caller) unless tag
  @client.put("#{domain}/tags/#{tag}", options).to_h['message'] == 'Tag updated'
end