Module: X::Objects::Lookups::DirectMessages

Included in:
API
Defined in:
x-objects/lib/x/objects/lookups/direct_messages.rb

Overview

Look up direct messages, and the conversations they belong to, mixed into a client through API

Internal to x-objects: X::Objects::API includes it, and its methods are public API of the client that includes API, but the module is only how they are grouped, and some of them need the methods of another, so include API rather than this module alone.

Instance Method Summary collapse

Instance Method Details

#direct_messages(**params) ⇒ Cursor Also known as: dms

The most recent direct message events across every conversation

Examples:

Print the most recent direct messages

client.direct_messages.first(10).each { |message| puts message.text }

Parameters:

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the events



49
50
51
# File 'x-objects/lib/x/objects/lookups/direct_messages.rb', line 49

def direct_messages(**params)
  DirectMessage.all(client: self, **params)
end

#direct_messages_in(conversation, **params) ⇒ Cursor Also known as: dms_in

The direct message events of a conversation, one-to-one or group

Examples:

Print the conversation a message belongs to

client.direct_messages_in(message).each { |event| puts event.text }

Parameters:

  • conversation (DirectMessage, String, Integer) —

    a message of the conversation, or the conversation's identifier

  • params (Hash) —

    query parameters merged over the default parameters, such as event_types

Returns:

  • (Cursor) —

    a cursor over the events

Raises:

  • (ArgumentError) —

    if the conversation identifier is not one



74
75
76
# File 'x-objects/lib/x/objects/lookups/direct_messages.rb', line 74

def direct_messages_in(conversation, **params)
  DirectMessage.in(conversation, client: self, **params)
end

#direct_messages_with(user, **params) ⇒ Cursor Also known as: dms_with

The direct message events in the one-to-one conversation with a user

Examples:

Print the conversation with a user

client.direct_messages_with(user).each { |message| puts message.text }

Parameters:

  • user (User, String, Integer) —

    the other participant or their identifier

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

  • (Cursor) —

    a cursor over the events



61
62
63
# File 'x-objects/lib/x/objects/lookups/direct_messages.rb', line 61

def direct_messages_with(user, **params)
  DirectMessage.with(user, client: self, **params)
end

#find_direct_message(id, **params) {|problem| ... } ⇒ DirectMessage? Also known as: find_dm

Look up a direct message event by identifier

Examples:

Look up a direct message

client.find_direct_message(1234567890).text

Parameters:

  • id (String, Integer, DirectMessage) —

    the identifier

  • params (Hash) —

    query parameters merged over the default parameters

Yield Parameters:

  • problem (Problem) —

    each problem the API reported, such as a resource that was not found

Returns:

  • (DirectMessage, nil) —

    the event or nil if the event was not found



25
26
27
# File 'x-objects/lib/x/objects/lookups/direct_messages.rb', line 25

def find_direct_message(id, **params, &)
  DirectMessage.find(id, client: self, **params, &)
end

#find_direct_message!(id, **params) ⇒ DirectMessage Also known as: find_dm!

Look up a direct message event by identifier, which must exist

Examples:

Look up a direct message

client.find_direct_message!(1234567890).text

Parameters:

  • id (String, Integer, DirectMessage) —

    the identifier

  • params (Hash) —

    query parameters merged over the default parameters

Returns:

Raises:



38
39
40
# File 'x-objects/lib/x/objects/lookups/direct_messages.rb', line 38

def find_direct_message!(id, **params)
  DirectMessage.find!(id, client: self, **params)
end