module MobileTextAlerts::Utils
Public Class Methods
parse_number(phone_number)
click to toggle source
Removes any non-digits from the phone_number string @param [String] phone_number @return [String]
# File lib/mobile_text_alerts/utils.rb, line 9 def parse_number(phone_number) phone_number.delete('^0-9') end
parse_response(http_response)
click to toggle source
# File lib/mobile_text_alerts/utils.rb, line 29 def parse_response(http_response) response = http_response.parsed_response response.kind_of?(Hash) ? response : JSON.parse(response) end
raise_error_on(response)
click to toggle source
Raises an exception if the response is an error response Otherwise, it returns the response hash @param [Hash] response
# File lib/mobile_text_alerts/utils.rb, line 16 def raise_error_on(response) if response.is_a?(Hash) && response['error'] raise Error.new(response['error']) elsif response.is_a?(Hash) && response['failed_numbers'] message = response['failed_numbers'] # may be an array? message = message.is_a?(String) ? message : message.join(', ') raise Error.new(message) else response end end
send_request!(uri)
click to toggle source
# File lib/mobile_text_alerts/utils.rb, line 34 def send_request!(uri) response = HTTParty.get(uri) response = Utils.parse_response(response) Utils.raise_error_on(response) response end