Class: Kato::Room

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

Instance Method Summary collapse

Constructor Details

#initialize(room_id, options = {}) ⇒ Room

Returns a new instance of Room.



10
11
12
13
14
15
16
17
18
19
# File 'lib/kato.rb', line 10

def initialize(room_id, options = {})
  default_options = {
    :api_url => 'https://api.kato.im',
    :integration => 'simple'
  }
  options = default_options.merge options
  url = options[:api_url] + '/rooms/' + room_id + '/' + options[:integration]
  url = options[:full_url] if options[:full_url]
  self.class.base_uri url
end

Instance Method Details

#post(from, message, options = {}) ⇒ Object



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

def post(from, message, options = {})
  body = {
    :from => from,
    :text => message
  }.merge options
  response = self.class.post('',
    :headers => { 'Content-Type' => 'application/json' },
    :body => body.to_json )
  case response.code
  when 200,204
    true
  else
    raise "#{response.message} (#{response.code})"
  end
end