Class: ISMS::HTTP

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/isms_http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#urlObject (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 query_message_status(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 send_message(recipient, msg, max_msgs=0)
  category = 1 # Corresponds to &cat=1 in API
  offset = 0
  max_msgs = 999 if max_msgs == 0
  message_stack = []
  while max_msgs > 0 and msg.length > offset
    msgpart = URI.escape(msg[offset, 160])
    offset += 160
    split_message = self.class.get("/sendmsg?user=#{@auth[:username]}&passwd=#{@auth[:password]}&cat=#{category}&to=#{recipient}&text=#{msgpart}")
    message_stack << split_message["id"]
  end
  message_stack
end