Class: NetGSM::SMS
- Inherits:
-
Object
- Object
- NetGSM::SMS
- Defined in:
- lib/netgsm_sms/sms.rb
Class Method Summary collapse
- .parse_response(body) ⇒ Object
-
.send_mass_sms(message_array = [], opts = {}) ⇒ Object
message_array format [[phone_number, ‘sms message body’]].
- .send_request(body) ⇒ Object
- .send_sms(recipient, message_text, opts = {}) ⇒ Object
Instance Method Summary collapse
- #check_balance ⇒ Object
-
#initialize(auth_options = {}) ⇒ SMS
constructor
A new instance of SMS.
- #sms_status ⇒ Object
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(={}) = 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( = [], opts={}) = opts.only(:from, :start_date, :stop_date, :turkish) .merge!(:start_date => NetGSM::DATE.now) unless [:start_date] .merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless [:stop_date] body = NetGSM::XmlBody.send_mass_sms_body(, ) 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, , opts={}) = opts.only(:from, :start_date, :stop_date, :turkish) .merge!(:start_date => NetGSM::DATE.now) unless [:start_date] .merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless [:stop_date] body = NetGSM::XmlBody.send_sms_body(recipient, , ) response = send_request(body) result = parse_response(response) return {code: result[0], sms_id: result[1]} end |
Instance Method Details
#check_balance ⇒ Object
34 35 36 |
# File 'lib/netgsm_sms/sms.rb', line 34 def check_balance 'OK Balance' end |
#sms_status ⇒ Object
30 31 32 |
# File 'lib/netgsm_sms/sms.rb', line 30 def sms_status 'OK status' end |