Sha256: 6400ca00eef771e244d04fa6bd76720c61c3c81ce3ab5701640e29f8d68880ab

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'active_support/time'

module Cellular
  class SMS

    attr_accessor :recipient, :sender, :message, :price, :country_code
    attr_accessor :recipients
    def initialize(options = {})
      @backend = Cellular.config.backend

      @recipients = options[:recipients]
      @recipient = options[:recipient]
      @sender = options[:sender] || Cellular.config.sender
      @message = options[:message]
      @price = options[:price] || Cellular.config.price
      @country_code = options[:country_code] || Cellular.config.country_code

      @delivered = false
    end

    def deliver
      @delivery_status, @delivery_message = @backend.deliver options
      @delivered = true
    end

    def deliver_async(delivery_options = {})
      Cellular::Jobs::AsyncMessenger.set(delivery_options).perform_later(options)
    end
    alias_method :deliver_later, :deliver_async

    def save(options = {})
      raise NotImplementedError
    end

    def receive(options = {})
      raise NotImplementedError
    end

    def delivered?
      @delivered
    end

    private

    def options
      {
        recipients: @recipients,
        recipient: @recipient,
        sender: @sender,
        message: @message,
        price: @price,
        country_code: @country_code
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cellular-2.0.0 lib/cellular/models/sms.rb