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.



17
18
19
20
# File 'lib/epoch_api.rb', line 17

def initialize token, options={}
  @token = token
			self
end

Instance Method Details

#_response(response) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/epoch_api.rb', line 48

def _response response
	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

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

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/epoch_api.rb', line 22

def message room_token, 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",
    query: { auth_token: @token },
    body: {
      from:    from,
      message: message,
      color:   options[:color],
      notify:  options[:notify] ? 1 : 0 }

  _response response
end

#topic(new_topic, options = {from: 'API'}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/epoch_api.rb', line 37

def topic new_topic, options = {from: 'API'}

  response = self.class.put "/#{room_id}/topic",
    query: { auth_token: @token },
    body: {
      from: options[:from],
      topic: new_topic}

  _response response
end