Sha256: 05da2cdb2c7696505336354996c60e49f11dacc56ff6d479555d2b7ca9f637fe

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

module OpenMarket
  module SMS
    module Requests

      class SendMessage
        attr_accessor :from, :to, :text

        ALPHANUMERIC_TYPE_OF_NUMBER = 5

        def initialize(from, to, text)
          @from = from
          @to = to
          @text = text
        end

        def body
          {
            mobileTerminate: {}
              .merge(message)
              .merge(source)
              .merge(destination)
          }
        end

        def url
          "#{SMS::Client::BASE_URL}/mt"
        end

        def method
          :post
        end

        private

        def message
          {
            message: {
              content: @text,
              type: 'text'
            }
          }
        end

        def destination
          { destination: { address: @to } }
        end

        def source
          { source: { ton: ALPHANUMERIC_TYPE_OF_NUMBER, address: @from } }
        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sms_broker-1.0.7 lib/open_market/sms/requests/send_message.rb