Last active
August 29, 2015 14:07
-
-
Save sha1sum/6f9c9e1ada9598c6fe45 to your computer and use it in GitHub Desktop.
Ruby Class for Posting GroupMe Messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GroupMe | |
include HTTParty | |
base_uri 'https://api.groupme.com/v3' | |
format :json | |
def initialize(access_token) | |
@access_token = access_token | |
end | |
def doPost(path, body, query = nil) | |
query_hash = { token: @access_token } | |
query_hash = query_hash.merge query if query | |
self.class.post path, { body: body, query: query_hash, headers: { 'Content-Type' => 'application/json', | |
'Accept' => 'application/json'} } | |
end | |
def send_message(group_id, message_text) | |
group_me_message = { | |
message: { | |
source_guid: SecureRandom.uuid, | |
text: message_text | |
} | |
# attachments: { | |
# type: attachment_type, | |
# url: attachment_url, | |
# } | |
}.to_json | |
doPost "/groups/#{group_id}/messages", group_me_message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment