Class: Mailgun::Tags

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(client = Mailgun::Client.new) ⇒ Tags

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



9
10
11
# File 'lib/mailgun/tags/tags.rb', line 9

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

Instance Method Details

#get_countries_aggregated_stats(domain, tag) ⇒ Object

Public: Get a list of countries of origin for a given domain for different event types.

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

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

Raises:



101
102
103
104
105
106
107
# File 'lib/mailgun/tags/tags.rb', line 101

def get_countries_aggregated_stats(domain, tag)
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag

  @client.get("#{domain}/tags/#{tag}/stats/aggregates/countries").to_h
end

#get_devices_aggregated_stats(domain, tag) ⇒ Object

Public: Get a list of devices for a given domain that have triggered event types.

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

Returns [Hash] of devices for a given domain

Raises:



129
130
131
132
133
134
135
# File 'lib/mailgun/tags/tags.rb', line 129

def get_devices_aggregated_stats(domain, tag)
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag

  @client.get("#{domain}/tags/#{tag}/stats/aggregates/devices").to_h
end

#get_providers_aggregated_stats(domain, tag) ⇒ Object

Public: Get a list of email providers for a given domain for different event types

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

Returns [Hash] of email providers for a given domain

Raises:



115
116
117
118
119
120
121
# File 'lib/mailgun/tags/tags.rb', line 115

def get_providers_aggregated_stats(domain, tag)
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag

  @client.get("#{domain}/tags/#{tag}/stats/aggregates/providers").to_h
end

#get_tag(domain, tag) ⇒ Object

Public: Get tag information

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

Returns [Hash] Information on the requested tag.

Raises:



36
37
38
39
40
41
42
# File 'lib/mailgun/tags/tags.rb', line 36

def get_tag(domain, tag)
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag

  @client.get("#{domain}/tags/#{tag}").to_h!
end

#get_tag_stats(domain, tag, options = {}) ⇒ Object

Public: Get statistics for a given tag

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

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

Returns [Hash] of tag stats info

Raises:



72
73
74
75
76
77
78
# File 'lib/mailgun/tags/tags.rb', line 72

def get_tag_stats(domain, tag, options = {})
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(ParameterError, 'No tag name given to find on provided domain', caller) unless tag

  @client.get("#{domain}/tags/#{tag}/stats", options).to_h
end

#get_tags(domain, options = {}) ⇒ Object

Public: Get Tags

domain - [String] Domain name where tag is stored options - [Hash] of

limit  - [Integer] Number of entries to return. Default: 100.

Returns [Array] A list of tags (hash)

Raises:



23
24
25
26
27
28
# File 'lib/mailgun/tags/tags.rb', line 23

def get_tags(domain, options = {})
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to store template on', caller) unless domain

  @client.get("#{domain}/tags", options).to_h['items']
end

#remove(domain, tag) ⇒ Object

Public: Delete Tag NOTE: Deletes the tag. Note: The statistics for the tag are not destroyed.

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

Returns [Boolean] if successful or not

Raises:



87
88
89
90
91
92
93
# File 'lib/mailgun/tags/tags.rb', line 87

def remove(domain, tag)
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
  raise(ParameterError, 'No template name given to find on provided domain', caller) unless tag

  @client.delete("#{domain}/tags/#{tag}").to_h['message'] == 'Tag deleted'
end

#update(domain, tag, options = {}) ⇒ Object

Public: Updates a given tag with the information provided

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

description - [String] Updated description of the tag

Returns [Boolean] if successful or not

Raises:



52
53
54
55
56
57
58
# File 'lib/mailgun/tags/tags.rb', line 52

def update(domain, tag, options = {})
  warn('This API is deprecated in favor of our new analytics Tags API')
  raise(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  raise(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