Class: ISMS::HTTP
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, user, password) ⇒ HTTP
constructor
A new instance of HTTP.
- #query_message_status(id) ⇒ Object
-
#send_message(recipient, msg, max_msgs = 0) ⇒ Object
recipient: Number/alias for the person you want to text msg: Full text message to send max_msgs: Maximum number of messages to send if message is too long.
Constructor Details
#initialize(url, user, password) ⇒ HTTP
Returns a new instance of HTTP.
14 15 16 17 18 |
# File 'lib/isms_http.rb', line 14 def initialize(url, user, password) @auth = { :username => user, :password => password } @url = url self.class.base_uri(@url) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/isms_http.rb', line 9 def url @url end |
Instance Method Details
#query_message_status(id) ⇒ Object
39 40 41 |
# File 'lib/isms_http.rb', line 39 def (id) response = self.class.get("/querymsg?user=#{@auth[:username]}&passwd=#{@auth[:password]}&apimsgid=#{id}") end |
#send_message(recipient, msg, max_msgs = 0) ⇒ Object
recipient: Number/alias for the person you want to text msg: Full text message to send max_msgs: Maximum number of messages to send if message is too long. Defaults to 0 messages (which means, split it up into as many messages as it takes).
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/isms_http.rb', line 25 def (recipient, msg, max_msgs=0) category = 1 # Corresponds to &cat=1 in API offset = 0 max_msgs = 999 if max_msgs == 0 = [] while max_msgs > 0 and msg.length > offset msgpart = URI.escape(msg[offset, 160]) offset += 160 = self.class.get("/sendmsg?user=#{@auth[:username]}&passwd=#{@auth[:password]}&cat=#{category}&to=#{recipient}&text=#{msgpart}") << ["id"] end end |