Class: Mailtrap::InboundThreadsAPI
- Inherits:
-
Object
- Object
- Mailtrap::InboundThreadsAPI
- Includes:
- BaseAPI
- Defined in:
- lib/mailtrap/inbound_threads_api.rb
Instance Attribute Summary
Attributes included from BaseAPI
Instance Method Summary collapse
-
#delete(inbox_id, thread_id) ⇒ Object
Deletes a thread.
-
#get(inbox_id, thread_id) ⇒ InboundThread
Fetches a single thread with its messages embedded (oldest first).
-
#initialize(client = Mailtrap::Client.new) ⇒ InboundThreadsAPI
constructor
A new instance of InboundThreadsAPI.
-
#list(inbox_id, last_id: nil) ⇒ InboundThreadsListResponse
Lists threads in an inbox (cursor-paginated).
Methods included from BaseAPI
Constructor Details
#initialize(client = Mailtrap::Client.new) ⇒ InboundThreadsAPI
Returns a new instance of InboundThreadsAPI.
16 17 18 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 16 def initialize(client = Mailtrap::Client.new) @client = client end |
Instance Method Details
#delete(inbox_id, thread_id) ⇒ Object
Deletes a thread
50 51 52 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 50 def delete(inbox_id, thread_id) client.delete("#{threads_path(inbox_id)}/#{thread_id}") end |
#get(inbox_id, thread_id) ⇒ InboundThread
Fetches a single thread with its messages embedded (oldest first)
41 42 43 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 41 def get(inbox_id, thread_id) build_thread(client.get("#{threads_path(inbox_id)}/#{thread_id}")) end |
#list(inbox_id, last_id: nil) ⇒ InboundThreadsListResponse
Lists threads in an inbox (cursor-paginated)
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 25 def list(inbox_id, last_id: nil) query_params = last_id ? { last_id: } : {} response = client.get(threads_path(inbox_id), query_params) InboundThreadsListResponse.new( data: Array(response[:data]).map { |item| build_thread(item) }, total_count: response[:total_count], last_id: response[:last_id] ) end |