lib/otp/totp.rb in otp-0.0.2 vs lib/otp/totp.rb in otp-0.0.3
- old
+ new
@@ -2,16 +2,30 @@
module OTP
class TOTP < OTP::Base
attr_accessor :period, :time
+ DEFAULT_PERIOD = 30
+
def initialize(*args)
super
- self.period = 30
+ self.period = DEFAULT_PERIOD
self.time = nil
end
def moving_factor
return (time || Time.now).to_i / period
+ end
+
+ def type_specific_uri_params
+ params = {}
+ params["period"] = period if period != DEFAULT_PERIOD
+ return params
+ end
+
+ def extract_type_specific_uri_params(query)
+ if value = query["period"]
+ self.period = value.to_i
+ end
end
end
end