Sha256: 957bf879a88a4a418e19b7944608fe754d036f8f5d0a306f5a7ab275f07a7df3

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module SmsBroker
  module Client
    class Twilio < Base
      def initialize(options)
        client = ::Twilio::REST::Client.new(
          options[:account_sid],
          options[:auth_token]
        )

        super :Twilio, client, options
      end

      def send_message(message)
        response = client.messages.create \
          body: message[:text],
          from: message[:from],
          to: serialize_to_number(message[:to])

        return Response::TwilioSuccess.new(response) \
          if success_response?(response)

        Response::TwilioError.new(response)
      rescue ::Twilio::REST::RequestError => exception
        Response::TwilioError.new(exception)
      end

      def send_voice_message(_message)
        message = 'twillio voice message integration is not implemented'
        exception = \
          Exceptions::NotImplemented.new(message)

        raise exception
      end

      private

      def success_response?(response)
        !%w(undelivered failed).include?(response.status)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sms_broker-1.0.8 lib/sms_broker/client/twilio.rb
sms_broker-1.0.7 lib/sms_broker/client/twilio.rb
sms_broker-1.0.5 lib/sms_broker/client/twilio.rb
sms_broker-1.0.4 lib/sms_broker/client/twilio.rb
sms_broker-1.0.3 lib/sms_broker/client/twilio.rb