Class: Txtlocal::Message
- Inherits:
-
Object
- Object
- Txtlocal::Message
- Defined in:
- lib/txtlocal/message.rb
Constant Summary collapse
- API_ENDPOINT =
URI.parse("https://www.txtlocal.com/sendsmspost.php")
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#from ⇒ Object
Returns the value of attribute from.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #add_recipient(recipient) ⇒ Object
-
#initialize(message = nil, recipients = nil, options = nil) ⇒ Message
constructor
A new instance of Message.
- #options=(options) ⇒ Object
- #send! ⇒ Object
Constructor Details
#initialize(message = nil, recipients = nil, options = nil) ⇒ Message
Returns a new instance of Message.
14 15 16 17 18 |
# File 'lib/txtlocal/message.rb', line 14 def initialize(=nil, recipients=nil, =nil) self.body = if self.recipients = recipients if recipients self. = if end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/txtlocal/message.rb', line 8 def body @body end |
#from ⇒ Object
Returns the value of attribute from.
10 11 12 |
# File 'lib/txtlocal/message.rb', line 10 def from @from end |
#recipients ⇒ Object
Returns the value of attribute recipients.
9 10 11 |
# File 'lib/txtlocal/message.rb', line 9 def recipients @recipients end |
#response ⇒ Object
Returns the value of attribute response.
12 13 14 |
# File 'lib/txtlocal/message.rb', line 12 def response @response end |
Instance Method Details
#add_recipient(recipient) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/txtlocal/message.rb', line 33 def add_recipient(recipient) recipient = recipient.gsub(/\s/, '') recipient = case recipient when /^447\d{9}$/ recipient when /^(?:\+447|07)(\d{9})$/ "447#{$1}" else return end recipients << recipient end |
#options=(options) ⇒ Object
58 59 60 |
# File 'lib/txtlocal/message.rb', line 58 def () self.from = [:from] if .has_key?(:from) end |
#send! ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/txtlocal/message.rb', line 74 def send! http = Net::HTTP.new(API_ENDPOINT.host, API_ENDPOINT.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(API_ENDPOINT.path) req.set_form_data(:json => 1, :test => Txtlocal.config.testing? ? 1 : 0, :from => from, :message => body, :selectednums => recipients.join(","), :uname => Txtlocal.config.username, :pword => Txtlocal.config.password) result = http.start { |http| http.request(req) } self.response = result end |