Class: OpenID::Store::CouchDB::Nonce
- Inherits:
-
Object
- Object
- OpenID::Store::CouchDB::Nonce
- Defined in:
- lib/openid/store/couchdb/nonce.rb
Constant Summary collapse
- DESIGN_DOCUMENT =
{ 'version' => 1, 'language' => 'javascript', 'views' => {} }
Class Method Summary collapse
- .create(server_url, timestamp, salt) ⇒ Object
- .create_design_document ⇒ Object
- .json_create(attributes) ⇒ Object
Instance Method Summary collapse
-
#initialize(server_url, timestamp, salt, couchdb_rev = nil) ⇒ Nonce
constructor
A new instance of Nonce.
- #name ⇒ Object
- #save ⇒ Object
- #to_json(*args) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(server_url, timestamp, salt, couchdb_rev = nil) ⇒ Nonce
Returns a new instance of Nonce.
22 23 24 25 26 27 28 |
# File 'lib/openid/store/couchdb/nonce.rb', line 22 def initialize(server_url, , salt, couchdb_rev = nil) @server_url = server_url @timestamp = Time.at(.to_i) @salt = salt @couchdb_rev = nil @couchdb = Chef::CouchDB.new end |
Class Method Details
.create(server_url, timestamp, salt) ⇒ Object
17 18 19 |
# File 'lib/openid/store/couchdb/nonce.rb', line 17 def create(server_url, , salt) new(server_url, , salt).save end |
.create_design_document ⇒ Object
13 14 15 |
# File 'lib/openid/store/couchdb/nonce.rb', line 13 def create_design_document Chef::CouchDB.new.create_design_document('nonces', DESIGN_DOCUMENT) end |
.json_create(attributes) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/openid/store/couchdb/nonce.rb', line 51 def self.json_create(attributes) server_url = attributes['server_url'] = attributes['timestamp'] salt = attributes['salt'] couchdb_rev = attributes['_rev'] new(server_url, , salt, couchdb_rev) end |
Instance Method Details
#name ⇒ Object
30 31 32 |
# File 'lib/openid/store/couchdb/nonce.rb', line 30 def name [@timestamp.utc.strftime(OpenID::Nonce::TIME_FMT), Base64.encode64(@server_url).chomp, Base64.encode64(@salt).chomp].join('-') end |
#save ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/openid/store/couchdb/nonce.rb', line 34 def save return false unless valid? begin results = @couchdb.store('nonce', name, self) rescue Net::HTTPServerException false else @couchdb_rev = results['rev'] true end end |
#to_json(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/openid/store/couchdb/nonce.rb', line 60 def to_json(*args) result = { 'json_class' => self.class.name, 'chef_type' => 'nonce', 'server_url' => @server_url, 'timestamp' => @timestamp.to_i, 'salt' => @salt, } result['_rev'] = @couchdb_rev if @couchdb_rev result.to_json(*args) end |
#valid? ⇒ Boolean
47 48 49 |
# File 'lib/openid/store/couchdb/nonce.rb', line 47 def valid? OpenID::Nonce.(name) end |