Sha256: 56ed2e42b613877da137401600496a9341c932f2b534549fe411ca40a5278c73

Contents?: true

Size: 979 Bytes

Versions: 10

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

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

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

    def add_from(from)
      @from = from
    end

    def add_to(to)
      @to << to
    end

    def add_text(text)
      @text = text
    end

    def add_personalization(personalization)
      @personalization << personalization
    end

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mailersend-ruby-2.0.1 lib/mailersend/sms/sms.rb
mailersend-ruby-2.0.0 lib/mailersend/sms/sms.rb
mailersend-ruby-1.6.0 lib/mailersend/sms/sms.rb
mailersend-ruby-1.5.2 lib/mailersend/sms/sms.rb
mailersend-ruby-1.5.1 lib/mailersend/sms/sms.rb
mailersend-ruby-1.5.0 lib/mailersend/sms/sms.rb
mailersend-ruby-1.4.0 lib/mailersend/sms/sms.rb
mailersend-ruby-1.3.2 lib/mailersend/sms/sms.rb
mailersend-ruby-1.3.1 lib/mailersend/sms/sms.rb
mailersend-ruby-1.3.0 lib/mailersend/sms/sms.rb