lib/gateway/sms77.rb
# generate a simple random 4 digits pin
generate a simple random 4 digits pin
generate a simple random 4 digits pin
def send_pin(options)
        raise ParameterError, 'no params given' if options.nil?
        params = Parameters.new(options)
        raise ParameterError, 'parameter :text is missing' if params[:text].nil?
        response = Sms77Response.new
        (response.add_error(:empty_options) and (return response)) if params.nil?
        response.pin = rand.to_s[2..(DEFAULT_PIN_SIZE + 1)]
        params[:text] = params[:text].gsub('%PIN%', response.pin)
        code = post_request(params)
        return response if code == SUCCESS_CODE
        response.add_error(code)
        response
      end
def send_pin ( options ) raise ParameterError , 'no params given' if options . nil? params = Parameters . new ( options ) raise ParameterError , 'parameter :text is missing' if params [ :text ] . nil? response = Sms77Response . new ( response . add_error ( :empty_options ) and ( return response ) ) if params . nil? response . pin = rand . to_s [ 2 .. ( DEFAULT_PIN_SIZE + 1 ) ] params [ :text ] = params [ :text ] . gsub ( '%PIN%' , response . pin ) code = post_request ( params ) return response if code == SUCCESS_CODE response . add_error ( code ) response end
generate a simple random 4 digits pin
generate a simple random 4 digits pin
# we may use SecureRandom.hex(size) if you need a more secure pin
options