Sha256: 5e939ddf53810bee13618f3e9f77d0ea44f36928ba090fd4711fde4e6beda143

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'uri'
require 'httpi'
require 'json'

module Smess
  class LinkMobility < HttpBase

    def deliver
      request.auth.basic(username, password)
      request.url = url
      request.headers["Content-Type"] = "application/json"
      request.body = body

      http_post request
    end

    attr_accessor :username, :password, :platform_id, :platform_partner_id, :gate_id
    def validate_config
      @username  = config.fetch(:username)
      @password  = config.fetch(:password)
      @platform_id  = config.fetch(:platform_id)
      @platform_partner_id  = config.fetch(:platform_partner_id)
      @gate_id  = config.fetch(:gate_id)
    end

    private

    def url
      config.fetch(:url)
    end

    def body
      {
        source: from,
        destination: "+#{sms.to}",
        userData: sms.message.strip_nongsm_chars,
        platformId: platform_id,
        platformPartnerId: platform_partner_id,
        dcs: "TEXT",
        useDeliveryReport: true,
        deliveryReportGates: [gate_id]
      }.to_json
    end

    def normal_result(response)
      response_json = JSON.parse(response.body)

      response_code = response_json["resultCode"]
      response_code = "0" if response_code == 1005

      message_id = response_json["messageId"]
      # Successful response
      {
        message_id: message_id,
        response_code: response_code.to_s,
        response: response_json,
        destination_address: sms.to,
        data: result_data
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smess-2.0.4 lib/smess/outputs/link_mobility.rb