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
19 20 21 22 23 24 |
# File 'lib/mailgun/events/events.rb', line 19 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.
60 61 62 63 64 65 66 67 |
# File 'lib/mailgun/events/events.rb', line 60 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.
31 32 33 |
# File 'lib/mailgun/events/events.rb', line 31 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.
42 43 44 |
# File 'lib/mailgun/events/events.rb', line 42 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.
53 54 55 |
# File 'lib/mailgun/events/events.rb', line 53 def previous(params = {}) get_events(params, @paging_previous) end |