Class: OoAuth::Nonce

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, timestamp)
  @value, @timestamp = value, timestamp.to_i
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/oo_auth/nonce.rb', line 5

def errors
  @errors
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



5
6
7
# File 'lib/oo_auth/nonce.rb', line 5

def timestamp
  @timestamp
end

#valueObject (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

.generateObject



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, timestamp)
  new(value, timestamp).save
end

Instance Method Details

#saveObject



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

Returns:

  • (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 timestamp <= 0
  @errors.empty?
end