Class: Textlocal::Message
- Inherits:
-
Object
- Object
- Textlocal::Message
- Defined in:
- lib/textlocal/message.rb
Constant Summary collapse
- SMS_ENDPOINT =
URI.parse("https://api.textlocal.in/send/?")
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#numbers ⇒ Object
Returns the value of attribute numbers.
-
#response ⇒ Object
Returns the value of attribute response.
-
#sender ⇒ Object
Returns the value of attribute sender.
Instance Method Summary collapse
- #add_recipient(number) ⇒ Object
-
#initialize(message = nil, numbers = nil, options = nil) ⇒ Message
constructor
A new instance of Message.
- #options=(options) ⇒ Object
- #send! ⇒ Object
Constructor Details
#initialize(message = nil, numbers = nil, options = nil) ⇒ Message
Returns a new instance of Message.
17 18 19 20 21 |
# File 'lib/textlocal/message.rb', line 17 def initialize(=nil, numbers=nil, =nil) self. = if self.numbers = numbers if numbers self. = if end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
9 10 11 |
# File 'lib/textlocal/message.rb', line 9 def @message end |
#numbers ⇒ Object
Returns the value of attribute numbers.
10 11 12 |
# File 'lib/textlocal/message.rb', line 10 def numbers @numbers end |
#response ⇒ Object
Returns the value of attribute response.
13 14 15 |
# File 'lib/textlocal/message.rb', line 13 def response @response end |
#sender ⇒ Object
Returns the value of attribute sender.
11 12 13 |
# File 'lib/textlocal/message.rb', line 11 def sender @sender end |
Instance Method Details
#add_recipient(number) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/textlocal/message.rb', line 43 def add_recipient(number) number = number.gsub(/\s/, '') number = case number when /^91\d{10}$/ number when /^(?:\+91)(\d{10})$/ "91#{$1}" when /^(\d{10})$/ "91#{$1}" else return end @numbers << number end |
#options=(options) ⇒ Object
70 71 72 |
# File 'lib/textlocal/message.rb', line 70 def () self.sender = [:sender] if .has_key?(:sender) end |
#send! ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/textlocal/message.rb', line 85 def send! http = Net::HTTP.new(SMS_ENDPOINT.host, SMS_ENDPOINT.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(SMS_ENDPOINT.path) params = {'username'=> Textlocal.config.username, 'hash' => Textlocal.config.api_hash, 'numbers' => numbers.join(','), 'message' => self., 'test' => Textlocal.config.testing? ? true : false } params['sender'] = sender if sender req.set_form_data(params) result = http.start { |http| http.request(req) } self.response = result end |