Class: EpochApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/epoch_api.rb

Instance Method Summary collapse

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, options={}
  @token = token
			self
end

Instance Method Details

#message(room_id, from, message, options = {color: 'yellow', notify: false}) ⇒ Object

Raises:



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 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