lib/mailgun/events/events.rb in mailgun-ruby-1.1.5 vs lib/mailgun/events/events.rb in mailgun-ruby-1.1.6
- old
+ new
@@ -9,10 +9,11 @@
#
# Examples
#
# See the Github documentation for full examples.
class Events
+ include Enumerable
# Public: event initializer
#
# client - an instance of Mailgun::Client
# domain - the domain to build queries
@@ -21,34 +22,50 @@
@domain = domain
@paging_next = nil
@paging_previous = nil
end
- # Public: Issues a simple get against the client.
+ # Public: Issues a simple get against the client. Alias of `next`.
#
# params - a Hash of query options and/or filters.
#
# Returns a Mailgun::Response object.
def get(params = nil)
- get_events(params)
+ self.next(params)
end
# Public: Using built in paging, obtains the next set of data.
# If an events request hasn't been sent previously, this will send one
# without parameters
#
+ # params - a Hash of query options and/or filters.
+ #
# Returns a Mailgun::Response object.
- def next
- get_events(nil, @paging_next)
+ def next(params = nil)
+ get_events(params, @paging_next)
end
# Public: Using built in paging, obtains the previous set of data.
# If an events request hasn't been sent previously, this will send one
# without parameters
#
+ # params - a Hash of query options and/or filters.
+ #
# Returns Mailgun::Response object.
- def previous
- get_events(nil, @paging_previous)
+ def previous(params = nil)
+ get_events(params, @paging_previous)
+ end
+
+ # Public: Allows iterating through all events and performs automatic paging.
+ #
+ # &block - Block to execute on items.
+ def each(&block)
+ items = self.next.to_h['items']
+
+ until items.empty?
+ items.each(&block)
+ items = self.next.to_h['items']
+ end
end
private
# Internal: Makes and processes the event request through the client