Class: Mailtrap::InboundThreadsAPI

Inherits:
Object
  • Object
show all
Includes:
BaseAPI
Defined in:
lib/mailtrap/inbound_threads_api.rb

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included

Constructor Details

#initialize(client = Mailtrap::Client.new) ⇒ InboundThreadsAPI

Returns a new instance of InboundThreadsAPI.

Parameters:

  • client (Mailtrap::Client) (defaults to: Mailtrap::Client.new) —

    The client instance



18
19
20
# File 'lib/mailtrap/inbound_threads_api.rb', line 18

def initialize(client = Mailtrap::Client.new)
  @client = client
end

Instance Method Details

#delete(inbox_id, thread_id) ⇒ Object

Deletes a thread

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • thread_id (String) —

    The thread ID

Returns:

  • nil

Raises:



53
54
55
# File 'lib/mailtrap/inbound_threads_api.rb', line 53

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)

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • thread_id (String) —

    The thread ID

Returns:

Raises:



44
45
46
# File 'lib/mailtrap/inbound_threads_api.rb', line 44

def get(inbox_id, thread_id)
  build_thread(client.get("#{threads_path(inbox_id)}/#{thread_id}"))
end

#list(inbox_id, last_id: nil, search: nil) ⇒ InboundThreadsListResponse

Lists threads in an inbox (cursor-paginated)

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • last_id (String, nil) (defaults to: nil) —

    Cursor from the previous response's last_id for the next page

  • search (String, nil) (defaults to: nil) —

    Search query

Returns:

Raises:



28
29
30
31
32
33
34
35
36
37
# File 'lib/mailtrap/inbound_threads_api.rb', line 28

def list(inbox_id, last_id: nil, search: nil)
  query_params = { last_id:, search: }.compact
  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