module GroupMe::Messages
Public Instance Methods
create_message(group_id, text, attachments = [])
click to toggle source
Create a message for a group
@return [Hashie::Mash] Hash representing the message @see dev.groupme.com/docs/v3#messages_create @param group_id [String, Integer] Id of the group @param text [String] Text of the message @param attachments [Array<Hash>] Array of attachments
# 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)
click to toggle source
List messages for a group
@return [Array<Hashie::Mash>] Array of hashes representing the messages @see dev.groupme.com/docs/v3#messages_index @param group_id [String, Integer] Id of the group @param options [Hash] options hash that will be passed to the groupme call @param fetch_all [Boolean] if true, fetches all messages for the group
# 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)
click to toggle source
Get number of messages for a group
@return [Integer] Number of messages @param group_id [String, Integer] Id of the group
# File lib/groupme/messages.rb, line 42 def messages_count(group_id) get("/groups/#{group_id}/messages")['count'] end
Also aliased as: message_count
Private Instance Methods
get_all_messages(group_id)
click to toggle source
# File lib/groupme/messages.rb, line 49 def get_all_messages(group_id) messages = [] last_id = '' loop do selection = get_messages(group_id, :before_id => last_id) break if selection.empty? last_id = selection.last.id messages << selection end messages end
get_messages(group_id, options = {})
click to toggle source
# File lib/groupme/messages.rb, line 63 def get_messages(group_id, options = {}) results = get("/groups/#{group_id}/messages", options) results.is_a?(Faraday::Response) ? [] : results.messages end