Module: GroupMe::Messages

Included in:
Client
Defined in:
lib/groupme/messages.rb

Instance Method Summary collapse

Instance Method Details

#create_message(group_id, text, attachments = []) ⇒ Hashie::Mash

Create a message for a group

Parameters:

  • group_id (String, Integer)

    Id of the group

  • text (String)

    Text of the message

  • attachments (Array<Hash>) (defaults to: [])

    Array of attachments

Returns:

  • (Hashie::Mash)

    Hash representing the message

See Also:



12
13
14
15
16
17
18
19
20
21
# File 'lib/groupme/messages.rb', line 12

def create_message(group_id, text, attachments = [])
  data = {
    :message => {
      :source_guid => SecureRandom.uuid,
      :text => text
    }
  }
  data[:message][:attachments] = attachments if attachments.any?
  post("/groups/#{group_id}/messages", data).message
end

#messages(group_id, options = {}, fetch_all = false) ⇒ Array<Hashie::Mash>

List messages for a group

Parameters:

  • group_id (String, Integer)

    Id of the group

  • options (Hash) (defaults to: {})

    options hash that will be passed to the groupme call

  • fetch_all (Boolean) (defaults to: false)

    if true, fetches all messages for the group

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing the messages

See Also:



30
31
32
33
34
35
36
# File 'lib/groupme/messages.rb', line 30

def messages(group_id, options = {}, fetch_all = false)
  if fetch_all
    get_all_messages(group_id)
  else
    get_messages(group_id, options)
  end
end

#messages_count(group_id) ⇒ Integer Also known as: message_count

Get number of messages for a group

Parameters:

  • group_id (String, Integer)

    Id of the group

Returns:

  • (Integer)

    Number of messages



42
43
44
# File 'lib/groupme/messages.rb', line 42

def messages_count(group_id)
  get("/groups/#{group_id}/messages")['count']
end