module Twilito
Constants
- VERSION
Public Class Methods
configuration()
click to toggle source
# File lib/twilito/configuration.rb, line 8 def self.configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/twilito/configuration.rb, line 4 def self.configure yield(configuration) end
reset_configuration!()
click to toggle source
# File lib/twilito/configuration.rb, line 12 def self.reset_configuration! @configuration = Configuration.new end
send_sms(**args)
click to toggle source
# File lib/twilito.rb, line 15 def send_sms(**args) response = send_sms!(**args) Result.success( response: response, sid: JSON.parse(response.read_body)['sid'] ) rescue SendError => e Result.failure(errors: [e.message], response: e.response) rescue JSON::ParserError Result.failure(errors: ['Unable to parse response'], response: response) end
send_sms!(**args)
click to toggle source
# File lib/twilito.rb, line 27 def send_sms!(**args) args = merge_configuration(args) send_response(args).tap do |response| raise SendError.new('Error from Twilio API', response) unless response.is_a? Net::HTTPSuccess end end
Private Class Methods
merge_configuration(args)
click to toggle source
# File lib/twilito.rb, line 37 def merge_configuration(args) configuration.to_h.merge(args).tap do |merged| missing_keys = merged.select { |_k, v| v.nil? }.keys raise ArgumentError, "Missing argument(s): #{missing_keys.join(', ')}" if missing_keys.any? end end