Class: Mailtrap::EmailLogsAPI
- Inherits:
-
Object
- Object
- Mailtrap::EmailLogsAPI
- Includes:
- BaseAPI
- Defined in:
- lib/mailtrap/email_logs_api.rb
Instance Attribute Summary
Attributes included from BaseAPI
Instance Method Summary collapse
-
#get(sending_message_id) ⇒ EmailLogMessage
Fetches a single email log message by ID.
-
#list(filters: nil, search_after: nil) ⇒ EmailLogsListResponse
Lists email logs with optional filters and cursor-based pagination.
-
#list_each(filters: nil) {|EmailLogMessage| ... } ⇒ Enumerator<EmailLogMessage>
Iterates over all email log messages matching the filters, automatically fetching each page.
Methods included from BaseAPI
Instance Method Details
#get(sending_message_id) ⇒ EmailLogMessage
Fetches a single email log message by ID.
63 64 65 |
# File 'lib/mailtrap/email_logs_api.rb', line 63 def get() base_get() end |
#list(filters: nil, search_after: nil) ⇒ EmailLogsListResponse
Lists email logs with optional filters and cursor-based pagination.
27 28 29 30 31 32 33 |
# File 'lib/mailtrap/email_logs_api.rb', line 27 def list(filters: nil, search_after: nil) query_params = build_list_query_params(filters:, search_after:) response = client.get(base_path, query_params) build_list_response(response) end |
#list_each(filters: nil) {|EmailLogMessage| ... } ⇒ Enumerator<EmailLogMessage>
Iterates over all email log messages matching the filters, automatically fetching each page. Use this when you want to process every message without manually handling next_page_cursor.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mailtrap/email_logs_api.rb', line 42 def list_each(filters: nil, &block) first_page = nil fetch_first_page = -> { first_page ||= list(filters: filters) } enum = Enumerator.new(-> { fetch_first_page.call.total_count }) do |yielder| response = fetch_first_page.call loop do response..each { || yielder << } break if response.next_page_cursor.nil? response = list(filters: filters, search_after: response.next_page_cursor) end end block ? enum.each(&block) : enum end |