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
Inbound is scoped to the token's account, so no account_id is required.
-
#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
Inbound is scoped to the token's account, so no account_id is required.
17 18 19 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 17 def initialize(client = Mailtrap::Client.new) @client = client end |
Instance Method Details
#delete(inbox_id, thread_id) ⇒ Object
Deletes a thread
51 52 53 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 51 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)
42 43 44 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 42 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)
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mailtrap/inbound_threads_api.rb', line 26 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 |