Module: Telegrama

Defined in:
lib/telegrama.rb,
lib/telegrama/error.rb,
lib/telegrama/client.rb,
lib/telegrama/version.rb,
lib/telegrama/formatter.rb,
lib/telegrama/configuration.rb,
lib/telegrama/send_message_job.rb

Defined Under Namespace

Modules: Formatter Classes: Client, Configuration, Error, SendMessageJob

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.configurationObject

Returns the configuration object.



20
21
22
# File 'lib/telegrama.rb', line 20

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



24
25
26
27
# File 'lib/telegrama.rb', line 24

def configure
  yield(configuration)
  configuration.validate!
end

.log_error(message) ⇒ Object

Helper method for logging errors



42
43
44
45
46
47
48
# File 'lib/telegrama.rb', line 42

def log_error(message)
  if defined?(Rails)
    Rails.logger.error("[Telegrama] #{message}")
  else
    warn("[Telegrama] #{message}")
  end
end

.send_message(message, options = {}) ⇒ Object

Sends a message using the configured settings. Before sending, we validate the configuration. This way, if nothing’s been set up, we get a descriptive error instead of a low-level one.



32
33
34
35
36
37
38
39
# File 'lib/telegrama.rb', line 32

def send_message(message, options = {})
  configuration.validate!
  if configuration.deliver_message_async
    SendMessageJob.set(queue: configuration.deliver_message_queue).perform_later(message, options)
  else
    Client.new.send_message(message, options)
  end
end