Class: TuraTEL::SMS
- Inherits:
-
Object
- Object
- TuraTEL::SMS
- Defined in:
- lib/turatel_sms/sms.rb
Class Method Summary collapse
- .check_sms(msg_id) ⇒ Object
- .parse_response(body) ⇒ Object
- .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.
45 46 47 |
# File 'lib/turatel_sms/sms.rb', line 45 def initialize(={}) @auth_options = end |
Class Method Details
.check_sms(msg_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/turatel_sms/sms.rb', line 26 def self.check_sms(msg_id) body = TuraTEL::XmlBody.check_sms_body(msg_id) puts body if TuraTEL.configuration.debug response = send_request(body) result = parse_response(response) "result = #{result}" end |
.parse_response(body) ⇒ Object
68 69 70 |
# File 'lib/turatel_sms/sms.rb', line 68 def self.parse_response(body) body.split(" ") end |
.send_request(body) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/turatel_sms/sms.rb', line 49 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('/xml/process.aspx', header) request.body = body #puts "Request #{@header} #{request.body} " response = Net::HTTP.new(TuraTEL.configuration.host, TuraTEL.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
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/turatel_sms/sms.rb', line 4 def self.send_sms(recipient, , opts={}) = opts.only(:from, :start_date, :stop_date, :turkish) .merge!(:start_date => TuraTEL::DATE.now) unless [:start_date] .merge!(:stop_date => TuraTEL::DATE.n_hour_from_now(21)) unless [:stop_date] .merge!(:concat => 1) unless [:concat] if (.chars.to_a.uniq & ['İ','Ğ','Ş','ı','ğ','ş']).empty? type = "1" else type = "2" end .merge!(:type => type) body = TuraTEL::XmlBody.send_sms_body(recipient, , ) puts body if TuraTEL.configuration.debug response = send_request(body) result = parse_response(response) "result = #{result}" end |
Instance Method Details
#check_balance ⇒ Object
41 42 43 |
# File 'lib/turatel_sms/sms.rb', line 41 def check_balance 'OK Balance' end |
#sms_status ⇒ Object
37 38 39 |
# File 'lib/turatel_sms/sms.rb', line 37 def sms_status 'OK status' end |