module SmsRouter
Constants
- VERSION
Attributes
configuration[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
# File lib/sms_router.rb, line 9 def self.configure(&block) self.configuration ||= Configuration.new yield(configuration) end
encyrpt_message(message)
click to toggle source
# File lib/sms_router.rb, line 23 def self.encyrpt_message(message) # declaration app_key = self.configuration.app_key app_code = self.configuration.app_code # encyption msg_and_key = message + app_key md5_digest = Digest::MD5.new md5_digest = md5_digest.update(msg_and_key).to_s encypted_msg = "#{message}|#{md5_digest.chars.first(3).join}#{md5_digest.chars.last(3).join}" # return encypted_msg end
validate_message(message)
click to toggle source
# File lib/sms_router.rb, line 38 def self.validate_message(message) # get the configurations app_key = self.configuration.app_key app_code = self.configuration.app_code # get the original message and recvd key recvd_msg = message.split("|") orgnl_msg = recvd_msg.first recvd_key = recvd_msg.last # combine the orgininal msg & app_key msg_and_key = orgnl_msg + app_key md5_message = Digest::MD5.new md5_message = md5_message.update(msg_and_key).to_s # append the first & lat 3 char of the md5 hash genrtd_key = md5_message.chars.first(3).join + md5_message.chars.last(3).join # return the result by combining the recvd key to generated key recvd_key == genrtd_key end