Class: EpochApi::Client
Instance Method Summary collapse
-
#initialize(token, options = {}) ⇒ Client
constructor
A new instance of Client.
- #message(room_id, from, message, options = {color: 'yellow', notify: false}) ⇒ Object
Constructor Details
#initialize(token, options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 |
# File 'lib/epoch_api.rb', line 16 def initialize token, ={} @token = token self end |
Instance Method Details
#message(room_id, from, message, options = {color: 'yellow', notify: false}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/epoch_api.rb', line 21 def room_id, from, , = {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: , color: [:color], notify: [: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 |