Skip to content

Commit

Permalink
Using options hash in send_message method
Browse files Browse the repository at this point in the history
  • Loading branch information
mortro committed Nov 21, 2011
1 parent 3b5cbf1 commit 1e5974d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/mobilove/text.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ def initialize(key, route, from)
@key, @route, @from = key, route, from @key, @route, @from = key, route, from
end end


# concat: if true multiple messages will be concatenated if the text has more than 160 chars (70 unicode) def send_message(to, message, options={})
def send_message(to, message, debug_mode = false, concat = false) url = send_url(to, message, options)
url = send_url(to, message, debug_mode, concat)
response = RestClient.get(url) response = RestClient.get(url)
respond(response) respond(response)
end end


private private


def send_url(to, message, debug_mode, concat) # :debug_mode => true // Message will not be sent
# :concat => true // Message will be sent as concatenated texts if it has more than 160 chars (70 unicode)
def send_url(to, message, options={})
options[:debug_mode] ||= false
options[:concat] ||= false
if is_gsm0338_encoded? message if is_gsm0338_encoded? message
"http://gw.mobilant.net/?key=#{@key}&to=#{to}&message=#{URI.escape(message)}&route=#{@route}&from=#{URI.escape(@from)}&debug=#{debug_mode ? '1' : '0'}&charset=utf-8&concat=#{concat ? '1' : '0'}" "http://gw.mobilant.net/?key=#{@key}&to=#{to}&message=#{URI.escape(message)}&route=#{@route}&from=#{URI.escape(@from)}&debug=#{options[:debug_mode] ? '1' : '0'}&charset=utf-8&concat=#{options[:concat] ? '1' : '0'}"
else else
"http://gw.mobilant.net/?key=#{@key}&to=#{to}&message=#{string_to_hexadecimal_code_points(message)}&route=#{@route}&from=#{URI.escape(@from)}&debug=#{debug_mode ? '1' : '0'}&messagetype=unicode&concat=#{concat ? '1' : '0'}" "http://gw.mobilant.net/?key=#{@key}&to=#{to}&message=#{string_to_hexadecimal_code_points(message)}&route=#{@route}&from=#{URI.escape(@from)}&debug=#{options[:debug_mode] ? '1' : '0'}&messagetype=unicode&concat=#{options[:concat] ? '1' : '0'}"
end end
end end


Expand Down

0 comments on commit 1e5974d

Please sign in to comment.