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
-
.configuration ⇒ Object
Returns the configuration object.
- .configure {|configuration| ... } ⇒ Object
-
.log_error(message) ⇒ Object
Helper method for logging errors.
-
.send_message(message, options = {}) ⇒ Object
Sends a message using the configured settings.
Class Method Details
.configuration ⇒ Object
Returns the configuration object.
20 21 22 |
# File 'lib/telegrama.rb', line 20 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
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() if defined?(Rails) Rails.logger.error("[Telegrama] #{}") else warn("[Telegrama] #{}") 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 (, = {}) configuration.validate! if configuration. SendMessageJob.set(queue: configuration.).perform_later(, ) else Client.new.(, ) end end |