Class: Eniyismsapi::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/eniyismsapi/send.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ SMS

Returns a new instance of SMS.



8
9
10
11
# File 'lib/eniyismsapi/send.rb', line 8

def initialize username, password
  @username = username
  @password = password
end

Instance Method Details

#multi_send(params) ⇒ Object

multi = Eniyismsapi::SMS.new ‘544xxxxxxx’, ‘123456’ #First: Username, Second: Password

params = {
  coding: 'Default', # Can be Turkish, Default, UCS2
  originator: 'EMRE KURT',
  messages: [
    {number: '544xxxxxxx', message: 'Emre Ruby GEM Api Test'},
    {number: '542xxxxxxx', message: 'Samet Ruby GEM Api Test'}
  ]
}
@response = multi.multi_send params

Description: Multi Message => Multi Number (Birden fazla farklı mesajı birden fazla farklı kişiye göndermeye yarar.)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/eniyismsapi/send.rb', line 66

def multi_send params
  path = "SubmitMulti"
  params = {sendDateTime: Time.now.strftime("%d/%m/%Y %H:%M")}.merge(params)

  ns = {
    "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" ,
    "xmlns"=>'SmsApi'
  }

  multi_xml = Nokogiri::XML::Builder.new do |xml|
    xml.SubmitMulti(ns) {
      xml.Credential {
        xml.Password @password
        xml.Username @username
      }
      xml.DataCoding params[:coding]
      xml.Header {
        xml.From params[:originator]
        xml.ScheduledDeliveryTime params[:sendDateTime]
      }
      xml.Envelopes {
        params[:messages].each do |msg|
          xml.Envelope{
            xml.Message msg[:message]
            xml.To msg[:number]
          }
        end
      }
    }
  end
  r = REQUEST.new path, multi_xml.to_xml
  return r.request
end

#send(params) ⇒ Object

Usage: sms = Eniyismsapi::SMS.new(“5444059964”,“123456”)

sms.send({sender: "GLOBALMEDIA", message: "Lorem Ipsum ...",
         numbers: ["05xxxxxxxxx", "5xxxxxxxxx"]})

Description: Single Message to Multiple Recipients



17
18
19
20
21
22
23
24
25
26
27
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
# File 'lib/eniyismsapi/send.rb', line 17

def send params
  path = "Submit"
  params = {sendDateTime: Time.now.strftime("%d/%m/%Y %H:%M")}.merge(params)

  ns = {
    "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" ,
    "xmlns"=>'SmsApi'
  }

  ms = {
    'xmlns:d2p1' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
  }

  build_xml = Nokogiri::XML::Builder.new do |xml|
    xml.Submit(ns) {
      xml.Credential {
        xml.Username @username
        xml.Password @password
      }
      xml.DataCoding params[:coding]
      xml.Header{
        xml.From params[:originator]
        xml.ScheduledDeliveryTime params[:sendDateTime]
      }
      xml.Message params[:message]
      xml.To(ms){
        params[:numbers].each do |nmb|
          xml['d2p1'].string nmb
        end
      }
    }
  end
  r = REQUEST.new path, build_xml.to_xml
  return r.request
  # return build_xml.to_xml
end