Module: MessagingGateway
- Defined in:
- lib/messaging_gateway.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .create_notification(recipient, body, format, url) ⇒ Object
- .output_config ⇒ Object
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/messaging_gateway.rb', line 10 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
20 21 22 23 |
# File 'lib/messaging_gateway.rb', line 20 def configure self.configuration ||= Configuration.new yield(configuration) end |
.create_notification(recipient, body, format, url) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/messaging_gateway.rb', line 36 def self.create_notification(recipient, body, format, url) if MessagingGateway.configuration.token.nil? || MessagingGateway.configuration.token == "" raise "Il manque le token !" elsif @server_name.nil? || @server_name == "" raise "Il manque le nom de serveur !" elsif @environment.nil? || @environment == "" raise "Il manque l'environnement !" end begin response = HTTParty.post("http://#{MessagingGateway.configuration.server_url}#{MessagingGateway.configuration.server_path}", body: { token: MessagingGateway.configuration.token, recipient: recipient, body: body, format: format, url: url } ) rescue Exception => e puts "Following error happened #{e.message}\n\nBacktrace:\n#{e.backtrace.join('\n')}" return false end return true end |
.output_config ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/messaging_gateway.rb', line 12 def output_config puts "Token: #{MessagingGateway.configuration.token}" puts "Server url #{MessagingGateway.configuration.server_url}" puts "Server path #{MessagingGateway.configuration.server_path}" return true end |