Class: StartmobileSms::Message
- Inherits:
-
Object
- Object
- StartmobileSms::Message
- Defined in:
- lib/startmobile_sms/message.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#out_number ⇒ Object
Returns the value of attribute out_number.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
- .check(id) ⇒ Object
-
.send(options) ⇒ Object
Class methods.
Instance Method Summary collapse
- #check(id = @id) ⇒ Object
- #check_content(id) ⇒ Object
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
- #make_post(body) ⇒ Object
- #send ⇒ Object
- #status ⇒ Object
- #xml_content ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 |
# File 'lib/startmobile_sms/message.rb', line 10 def initialize(={}) @phone = [:phone] @text = [:text] @out_number = [:out_number] || StartmobileSms.config.out_number end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/startmobile_sms/message.rb', line 8 def id @id end |
#out_number ⇒ Object
Returns the value of attribute out_number.
7 8 9 |
# File 'lib/startmobile_sms/message.rb', line 7 def out_number @out_number end |
#phone ⇒ Object
Returns the value of attribute phone.
7 8 9 |
# File 'lib/startmobile_sms/message.rb', line 7 def phone @phone end |
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/startmobile_sms/message.rb', line 7 def text @text end |
Class Method Details
.check(id) ⇒ Object
69 70 71 |
# File 'lib/startmobile_sms/message.rb', line 69 def self.check(id) new.check(id) end |
.send(options) ⇒ Object
Class methods
64 65 66 67 |
# File 'lib/startmobile_sms/message.rb', line 64 def self.send() cms = new() cms.send end |
Instance Method Details
#check(id = @id) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/startmobile_sms/message.rb', line 50 def check(id=@id) response = make_post(check_content(id)) return nil unless response doc = Nokogiri::XML(response) doc.at('.//state').content end |
#check_content(id) ⇒ Object
24 25 26 |
# File 'lib/startmobile_sms/message.rb', line 24 def check_content(id) "<?xml version='1.0' encoding='UTF-8'?><request id='#{id}'>status</request>" end |
#make_post(body) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/startmobile_sms/message.rb', line 28 def make_post(body) url = URI.parse(StartmobileSms.config.post_url) request = Net::HTTP::Post.new(url.path) request.basic_auth StartmobileSms.config.login, StartmobileSms.config.password request.body = body result = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) } case result when Net::HTTPSuccess, Net::HTTPRedirection then result.body else false end end |
#send ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/startmobile_sms/message.rb', line 42 def send response = make_post(xml_content) return nil unless response doc = Nokogiri::XML(response) @id = doc.at('.//id').content end |
#status ⇒ Object
58 59 60 |
# File 'lib/startmobile_sms/message.rb', line 58 def status @id.nil? ? 'You must send sms before check' : check end |
#xml_content ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/startmobile_sms/message.rb', line 16 def xml_content "<?xml version='1.0' encoding='UTF-8'?><message> <service id='single' source='#{@out_number}'/> <to>#{@phone}</to> <body content-type='text/plain'><![CDATA[#{@text}]]></body> </message>" end |