Class: NISTRandomnessBeacon::Client
- Inherits:
-
Object
- Object
- NISTRandomnessBeacon::Client
- Includes:
- HTTParty
- Defined in:
- lib/nist_randomness_beacon/client.rb
Overview
Client to the NIST Randomness Beacon API
Constant Summary collapse
- DEFAULT_URI =
'https://beacon.nist.gov/beacon/1.0/pulse'.freeze
Instance Attribute Summary collapse
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#current ⇒ Object
Returns the Current Record (or next closest AFTER the timestamp) https://<server name>/<context>/beacon/1.0/pulse/<timestamp>.
-
#initialize(time = nil, uri = DEFAULT_URI) ⇒ Client
constructor
A new instance of Client.
-
#last ⇒ Object
Returns the Last Record https://<server name>/<context>/beacon/1.0/pulse/last.
-
#next ⇒ Object
Returns the Next Record https://<server name>/<context>/beacon/1.0/pulse/next/<timestamp>.
-
#previous ⇒ Object
Returns the Previous Record https://<server name>/<context>/beacon/1.0/pulse/previous/<timestamp>.
-
#start_chain ⇒ Object
Returns the Start Chain Record https://<server name>/<context>/beacon/1.0/pulse/start-chain/<timestamp>.
Constructor Details
#initialize(time = nil, uri = DEFAULT_URI) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/nist_randomness_beacon/client.rb', line 12 def initialize(time=nil, uri=DEFAULT_URI) @timestamp = (time || Time.now).to_i @uri = uri end |
Instance Attribute Details
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
10 11 12 |
# File 'lib/nist_randomness_beacon/client.rb', line 10 def @timestamp end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/nist_randomness_beacon/client.rb', line 10 def uri @uri end |
Instance Method Details
#current ⇒ Object
Returns the Current Record (or next closest AFTER the timestamp) https://<server name>/<context>/beacon/1.0/pulse/<timestamp>
20 21 22 23 |
# File 'lib/nist_randomness_beacon/client.rb', line 20 def current response = self.class.get("#@uri/#@timestamp") create_new_record(response) end |
#last ⇒ Object
Returns the Last Record https://<server name>/<context>/beacon/1.0/pulse/last
44 45 46 47 |
# File 'lib/nist_randomness_beacon/client.rb', line 44 def last response = self.class.get("#@uri/last") create_new_record(response) end |
#next ⇒ Object
Returns the Next Record
https://<server name>/<context>/beacon/1.0/pulse/next/<timestamp>
36 37 38 39 |
# File 'lib/nist_randomness_beacon/client.rb', line 36 def next response = self.class.get("#@uri/next/#@timestamp") create_new_record(response) end |
#previous ⇒ Object
Returns the Previous Record https://<server name>/<context>/beacon/1.0/pulse/previous/<timestamp>
28 29 30 31 |
# File 'lib/nist_randomness_beacon/client.rb', line 28 def previous response = self.class.get("#@uri/previous/#@timestamp") create_new_record(response) end |
#start_chain ⇒ Object
Returns the Start Chain Record https://<server name>/<context>/beacon/1.0/pulse/start-chain/<timestamp>
52 53 54 55 |
# File 'lib/nist_randomness_beacon/client.rb', line 52 def start_chain response = self.class.get("#@uri/start-chain/#@timestamp") create_new_record(response) end |