Sha256: 3aad177e2a8589c964f85bba7b00a57390f368cfa94ce84f86312cd7c2882787

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 Bytes

Contents

# frozen_string_literal: true

module Mailersend
  # Send an SMS through MailerSend API
  class SMS
    attr_accessor :client,
                  :from,
                  :to,
                  :text

    def initialize(client = Mailersend::Client.new)
      @client = client
      @from = {}
      @to = []
      @text = {}
    end

    def add_from(from)
      @from = from
    end

    def add_to(to)
      @to << to
    end

    def add_text(text)
      @text = text
    end

    def send
      message = {
        'from' => @from,
        'to' => @to,
        'text' => @text
      }

      client.http.post("#{API_URL}/sms", json: message.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mailersend-ruby-1.2.0 lib/mailersend/sms/sms.rb