Class: NetGSM::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/netgsm_sms/sms.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_options = {}) ⇒ SMS

Returns a new instance of SMS.



38
39
40
# File 'lib/netgsm_sms/sms.rb', line 38

def initialize(auth_options={})
  @auth_options = auth_options
end

Class Method Details

.parse_response(body) ⇒ Object



61
62
63
# File 'lib/netgsm_sms/sms.rb', line 61

def self.parse_response(body)
  body.split(" ")
end

.send_mass_sms(message_array = [], opts = {}) ⇒ Object

message_array format [[phone_number, ‘sms message body’]]



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/netgsm_sms/sms.rb', line 17

def self.send_mass_sms(message_array = [], opts={})
  valid_options = opts.only(:from, :start_date, :stop_date, :turkish)
  valid_options.merge!(:start_date => NetGSM::DATE.now) unless valid_options[:start_date]
  valid_options.merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]

  body = NetGSM::XmlBody.send_mass_sms_body(message_array, valid_options)

  response = send_request(body)

  result = parse_response(response)
  return {code: result[0], sms_id: result[1]}
end

.send_request(body) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/netgsm_sms/sms.rb', line 42

def self.send_request(body)
    header = { 
      "Content-Type" => "text/xml; charset=utf-8", 
      "Content-Length" => body.bytesize.to_s, 
      "Accept" => "*/*" 
    }

    request = Net::HTTP::Post.new('/xmlbulkhttppost.asp', header)
    request.body = body
    #puts  "Request #{@header} #{request.body} "
    response = Net::HTTP.new(NetGSM.configuration.host, NetGSM.configuration.port).start {|http| http.request(request) }
    #puts "Response #{response.code} #{response.message}: #{response.body}"

    # parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
    # parser.parse(response.body)

    return response.body
end

.send_sms(recipient, message_text, opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/netgsm_sms/sms.rb', line 3

def self.send_sms(recipient, message_text, opts={})
  valid_options = opts.only(:from, :start_date, :stop_date, :turkish)
  valid_options.merge!(:start_date => NetGSM::DATE.now) unless valid_options[:start_date]
  valid_options.merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]

  body = NetGSM::XmlBody.send_sms_body(recipient, message_text, valid_options)

  response = send_request(body)

  result = parse_response(response)
  return {code: result[0], sms_id: result[1]}
end

Instance Method Details

#check_balanceObject



34
35
36
# File 'lib/netgsm_sms/sms.rb', line 34

def check_balance
  'OK Balance'
end

#sms_statusObject



30
31
32
# File 'lib/netgsm_sms/sms.rb', line 30

def sms_status
  'OK status'
end