Class: OoAuth::Nonce
- Inherits:
-
Object
- Object
- OoAuth::Nonce
- Defined in:
- lib/oo_auth/nonce.rb,
lib/oo_auth/nonce/redis_store.rb,
lib/oo_auth/nonce/abstract_store.rb
Defined Under Namespace
Classes: AbstractStore, RedisStore
Constant Summary collapse
- MAX_LENGTH =
255
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value, timestamp) ⇒ Nonce
constructor
A new instance of Nonce.
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(value, timestamp) ⇒ Nonce
Returns a new instance of Nonce.
17 18 19 |
# File 'lib/oo_auth/nonce.rb', line 17 def initialize(value, ) @value, @timestamp = value, .to_i end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/oo_auth/nonce.rb', line 5 def errors @errors end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/oo_auth/nonce.rb', line 5 def @timestamp end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/oo_auth/nonce.rb', line 5 def value @value end |
Class Method Details
.generate ⇒ Object
12 13 14 |
# File 'lib/oo_auth/nonce.rb', line 12 def generate new(OoAuth.generate_nonce, Time.now.utc.to_i) end |
.remember(value, timestamp) ⇒ Object
8 9 10 |
# File 'lib/oo_auth/nonce.rb', line 8 def remember(value, ) new(value, ).save end |
Instance Method Details
#save ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oo_auth/nonce.rb', line 29 def save return false unless valid? if store.respond_to?(:call) store.call(self) elsif store.respond_to?(:remember) store.remember(self) else fail ConfigurationError, 'nonce store not callable' end end |
#valid? ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/oo_auth/nonce.rb', line 21 def valid? @errors = [] @errors << 'nonce value cannot be blank' if value.to_s == '' @errors << 'nonce value too big' if value.size > MAX_LENGTH @errors << 'illegal nonce timestamp' if <= 0 @errors.empty? end |