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

Inbound is scoped to the token's account, so no account_id is required.

Parameters:

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

    The client instance



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

Parameters:

  • inbox_id (Integer)

    The inbox ID

  • thread_id (String)

    The thread ID

Returns:

  • nil

Raises:



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)

Parameters:

  • inbox_id (Integer)

    The inbox ID

  • thread_id (String)

    The thread ID

Returns:

Raises:



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)

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

Returns:

Raises:



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