Class: NISTRandomnessBeacon::Client

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

Instance Method Summary collapse

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

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/nist_randomness_beacon/client.rb', line 10

def timestamp
  @timestamp
end

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

#currentObject

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

#lastObject

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

#nextObject

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

#previousObject

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_chainObject

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