Sha256: 02c17bd26dbc75b93104783997eadeb9d612dfa3b70c26876a6ddb3fc7632c88
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true require "savon" module Decidim module ActionDelegator class SendSmsJobException < StandardError; end class SendSmsJob < ApplicationJob queue_as :default SMSVIRTUAL_WSDL_URL = "https://websms.masmovil.com/api_php/smsvirtual.wsdl" def perform(sender, mobile_phone_number, message) @sender = sender @mobile_phone_number = mobile_phone_number @message = message send_sms! raise SendSmsJobException, response unless success? end private attr_reader :sender, :mobile_phone_number, :message, :response def send_sms! @response = client.call(:send_sms, message: { user: ENV["SMS_USER"], pass: ENV["SMS_PASS"], src: sender, dst: mobile_phone_number, msg: message }) end def success? parsed_response[:code] == "200" end def client @client ||= ::Savon.client(wsdl: SMSVIRTUAL_WSDL_URL) end def parsed_response return @parsed_response if @parsed_response doc = Nokogiri::XML response.body[:send_sms_response][:result] @parsed_response = { code: doc.xpath("//codigo").text, description: doc.xpath("//descripcion").text } @parsed_response end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-action_delegator-0.8.1 | app/jobs/decidim/action_delegator/send_sms_job.rb |