Sha256: d7d51adbef3989164eff3bbf3909f59579de55807d8cb7030d96f580464db2d5

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

require 'uri'
require 'httpi'

module Smess
  class Smsglobal < HttpBase

    def deliver
      request.url = url
      request.body = params

      http_post request
    end

    attr_accessor :username, :password, :sender_id
    def validate_config
      @username = config.fetch(:username)
      @password = config.fetch(:password)
      @sender_id = config.fetch(:sender_id, Smess.config.default_sender_id)
    end

    private

    def url
      "https://www.smsglobal.com/http-api.php"
    end

    def params
      @params ||= {
        action: "sendsms",
        user: username,
        password: password,
        from: from,
        to: sms.to,
        text: sms.message.strip_nongsm_chars,
        maxsplit: "3"
      }
    end

    def normal_result(response)
      first_response = response.body.split(/\r\n/).first.split(";") rescue nil
      response_code = first_response.first.split(':').last.to_i rescue response.code.to_s
      message_id = first_response.last.split('SMSGlobalMsgID:').last rescue ""
      # Successful response
      {
        message_id: message_id,
        response_code: response_code.to_s,
        response: response.body,
        destination_address: sms.to,
        data: result_data
      }
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
smess-3.3.0 lib/smess/outputs/smsglobal.rb
smess-3.2.0 lib/smess/outputs/smsglobal.rb
smess-3.1.2 lib/smess/outputs/smsglobal.rb
smess-3.1.1 lib/smess/outputs/smsglobal.rb
smess-3.1.0 lib/smess/outputs/smsglobal.rb
smess-3.0.0 lib/smess/outputs/smsglobal.rb