class Mailgun::Events

A Mailgun::Events object makes it really simple to consume Mailgun's events from the Events endpoint.

See the Github documentation for full examples.

Public Class Methods

new(client, domain) click to toggle source
# File lib/mailgun/events/events.rb, line 15
def initialize(client, domain)
  @client = client
  @domain = domain
  @paging_next = nil
  @paging_previous = nil
end

Public Instance Methods

get(params=nil) click to toggle source

Issues a simple get against the client.

@param [Hash] params A hash of query options and/or filters. @return [Mailgun::Response] Mailgun Response object.

# File lib/mailgun/events/events.rb, line 27
def get(params=nil)
  _get(params)
end
next() click to toggle source

Using built in paging, obtains the next set of data.

@return [Mailgun::Response] Mailgun Response object.

# File lib/mailgun/events/events.rb, line 35
def next()
  _get(nil, @paging_next)
end
previous() click to toggle source

Using built in paging, obtains the previous set of data.

@return [Mailgun::Response] Mailgun Response object.

# File lib/mailgun/events/events.rb, line 43
def previous()
  _get(nil, @paging_previous)
end

Private Instance Methods

_get(params=nil, paging=nil) click to toggle source
# File lib/mailgun/events/events.rb, line 49
def _get(params=nil, paging=nil)
  response = @client.get(construct_url(paging), params)
  extract_paging(response)
  response
end
construct_url(paging=nil) click to toggle source
# File lib/mailgun/events/events.rb, line 64
def construct_url(paging=nil)
  if paging
    "#{@domain}/events/#{paging}"
  else
    "#{@domain}/events"
  end
end
extract_paging(response) click to toggle source
# File lib/mailgun/events/events.rb, line 55
def extract_paging(response)
  paging_next = response.to_h["paging"]["next"]
  paging_previous = response.to_h["paging"]["previous"]

  # This is pretty hackish. But the URL will never change in API v2.
  @paging_next = paging_next.split("/")[6]
  @paging_previous = paging_previous.split("/")[6]
end