class EpochApi::Client
Public Class Methods
new(token, options={})
click to toggle source
# File lib/epoch_api.rb, line 16 def initialize token, options={} @token = token self end
Public Instance Methods
message(room_id, from, message, options = {color: 'yellow', notify: false})
click to toggle source
# File lib/epoch_api.rb, line 21 def message room_id, from, message, options = {color: 'yellow', notify: false} err_msg = "Username #{from} is `#{from.length} characters long. Limit is 15'" raise UsernameTooLong, err_msg if from.length > 15 response = self.class.put "/#{room_id}/message", body: { from: from, message: message, color: options[:color], notify: options[:notify] ? 1 : 0 }, headers: { "Authorization" => "Token token=#{@token}"} case response.code when 200 then response.body when 404 then raise UnknownRoom , "Unknown room: `#{room_id}'" when 401 then raise Unauthorized , "Access denied to room `#{room_id}'" else; raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'" end end