Class: Google::Hangout::Webhook::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/google/hangout/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Message

Returns a new instance of Message.



17
18
19
20
21
# File 'lib/google/hangout/webhook.rb', line 17

def initialize(config_path)
  self.config_path = config_path
  self.settings = YAML.load_file(config_path)
  self.pre_message = ''
end

Instance Attribute Details

#config_pathObject

Returns the value of attribute config_path.



15
16
17
# File 'lib/google/hangout/webhook.rb', line 15

def config_path
  @config_path
end

#pre_messageObject

Returns the value of attribute pre_message.



15
16
17
# File 'lib/google/hangout/webhook.rb', line 15

def pre_message
  @pre_message
end

#responseObject

Returns the value of attribute response.



15
16
17
# File 'lib/google/hangout/webhook.rb', line 15

def response
  @response
end

#settingsObject

Returns the value of attribute settings.



15
16
17
# File 'lib/google/hangout/webhook.rb', line 15

def settings
  @settings
end

Instance Method Details

#broadcast(channel, message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/google/hangout/webhook.rb', line 27

def broadcast(channel, message)
  raise "Channel name #{channel.to_s} not found" if settings['channels'][channel.to_s].nil?
  raise "Channel url is missing" if settings['channels'][channel.to_s]['url'].nil?

  self.response = RestClient.post(
    settings['channels'][channel.to_s]['url'],
    { text: [pre_message, message].join }.to_json,
    { content_type: :json, accept: :json }
  )
rescue StandardError => e
  error = "Google Hangout Error: #{e.message}"
  puts error
  raise error
end

#reloadObject



23
24
25
# File 'lib/google/hangout/webhook.rb', line 23

def reload
  self.settings = YAML.load_file(config_path)
end