Sha256: d6bd3f721af77050f664dd1ab5f5dd6551ca4fe691b9c7338b16adb6c22b8031

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Smess
  class Sms

    attr_accessor :to, :message, :originator, :output, :results, :callback_params

    def initialize(*args)
      opts = args.first || {}
      @to = opts.fetch(:to, nil)
      @message = opts.fetch(:message, "")
      @originator = opts.fetch(:originator, nil)
      @output = opts.fetch(:output, :auto).to_sym
      @callback_params = opts.fetch(:callback_params, nil)
    end

    def deliver
      out = Smess.named_output_instance(output)
      out.sms = self
      self.results = {sent_with: output}.merge(out.deliver)
    end

    def verify(using: 'sms')
      out = Smess.named_output_instance(output)
      out.sms = self
      self.results = {sent_with: output}.merge(out.verify(using: using))
    end

    def check(code)
      out = Smess.named_output_instance(output)
      out.sms = self
      self.results = {sent_with: output}.merge(out.check(code))
    end

    def delivered?
      results[:response_code] == "0"
    end

    def send_feedback(to, message_sid)
      out = Smess.named_output_instance(output)
      @to = to
      out.sms = self
      out.send_feedback(message_sid)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smess-3.3.0 lib/smess/sms.rb
smess-3.2.0 lib/smess/sms.rb