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 = {}) ⇒ Object
Public: Issues a simple get against the client.
-
#initialize(client, domain) ⇒ Events
constructor
Public: event initializer.
-
#next(params = {}) ⇒ Object
Public: Using built in paging, obtains the next set of data.
-
#previous(params = {}) ⇒ 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
18 19 20 21 22 23 |
# File 'lib/mailgun/events/events.rb', line 18 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.
59 60 61 62 63 64 65 66 |
# File 'lib/mailgun/events/events.rb', line 59 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 = {}) ⇒ 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.
30 31 32 |
# File 'lib/mailgun/events/events.rb', line 30 def get(params = {}) self.next(params) end |
#next(params = {}) ⇒ 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.
41 42 43 |
# File 'lib/mailgun/events/events.rb', line 41 def next(params = {}) get_events(params, @paging_next) end |
#previous(params = {}) ⇒ 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.
52 53 54 |
# File 'lib/mailgun/events/events.rb', line 52 def previous(params = {}) get_events(params, @paging_previous) end |