Class: Mailgun::Events
- Inherits:
-
Object
- Object
- Mailgun::Events
- Includes:
- Enumerable
- Defined in:
- lib/mailgun/events/events.rb
Overview
A Mailgun::Events object makes it really simple to consume
Mailgun's events from the Events endpoint.
This is not yet comprehensive.
Examples
See the Github documentation for full examples.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Public: Allows iterating through all events and performs automatic paging.
-
#get(params = nil) ⇒ Object
Public: Issues a simple get against the client.
-
#initialize(client, domain) ⇒ Events
constructor
Public: event initializer.
-
#next(params = nil) ⇒ Object
Public: Using built in paging, obtains the next set of data.
-
#previous(params = nil) ⇒ Object
Public: Using built in paging, obtains the previous set of data.
Constructor Details
#initialize(client, domain) ⇒ Events
Public: event initializer
client - an instance of Mailgun::Client domain - the domain to build queries
20 21 22 23 24 25 |
# File 'lib/mailgun/events/events.rb', line 20 def initialize(client, domain) @client = client @domain = domain @paging_next = nil @paging_previous = nil end |
Instance Method Details
#each(&block) ⇒ Object
Public: Allows iterating through all events and performs automatic paging.
&block - Block to execute on items.
61 62 63 64 65 66 67 68 |
# File 'lib/mailgun/events/events.rb', line 61 def each(&block) items = self.next.to_h['items'] until items.empty? items.each(&block) items = self.next.to_h['items'] end end |
#get(params = nil) ⇒ Object
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.
32 33 34 |
# File 'lib/mailgun/events/events.rb', line 32 def get(params = nil) self.next(params) end |
#next(params = nil) ⇒ Object
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.
43 44 45 |
# File 'lib/mailgun/events/events.rb', line 43 def next(params = nil) get_events(params, @paging_next) end |
#previous(params = nil) ⇒ Object
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.
54 55 56 |
# File 'lib/mailgun/events/events.rb', line 54 def previous(params = nil) get_events(params, @paging_previous) end |