Class: Smess::Mblox

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/smess/outputs/mblox.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(sms) ⇒ Mblox

Returns a new instance of Mblox.



8
9
10
11
# File 'lib/smess/outputs/mblox.rb', line 8

def initialize(sms)
  @sms = sms
  @results = []
end

Instance Method Details

#deliverObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/smess/outputs/mblox.rb', line 13

def deliver
  xml_params = {
    subscriber_number: sms.to,
    message: ""
  }

  parts.each_with_index do |part, i|
    xml_params[:message] = part
    xml_params[:udh]  = concatenation_udh(i+1, parts.length) if parts.length > 1
    results << send_one_sms(xml_params)
  end

  results.first
end

#hash_data_for(xml_params) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/smess/outputs/mblox.rb', line 28

def hash_data_for(xml_params)
  rand = (SecureRandom.random_number*100000000).to_i
  @message_id = rand

  xml_hash = {
    notification_request: {
      notification_header: {
        partner_name: ENV["SMESS_MBLOX_SURE_ROUTE_USER"],
        partner_password: ENV["SMESS_MBLOX_SURE_ROUTE_PASS"]
      },
      notification_list: {
        notification: {
          message: xml_params[:message],
          profile: ENV["SMESS_MBLOX_SURE_ROUTE_PROFILE_ID"],
          udh: xml_params.fetch(:udh,""),
          sender_i_d: from,
          # expire_date: "",
          # operator: "",
          # tariff: "",
          subscriber: {
            subscriber_number: xml_params[:subscriber_number],
            session_id: ""
          },
          # tags: '<Tag Name=”Number”>56</Tag><Tag Name=”City”>Paris</Tag>',
          # service_desc: "",
          # content_type: "",
          service_id: ENV["SMESS_MBLOX_SURE_ROUTE_SID"],
          attributes!: { sender_i_d: { "Type" => "Shortcode" } }
        },
        attributes!: { notification: { "SequenceNumber" => "1", "MessageType" => "SMS" } } # FlashSMS
      },
      attributes!: { notification_list: { "BatchID" => @message_id } }
    },
    attributes!: {  notification_request: { "Version" => "3.5" } }
  }
  xml_hash[:notification_request][:notification_list][:notification].delete :udh unless xml_params.key? :udh
  xml_hash
end