Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.5.0
- 2.4.0
- 2.3.0
- 2.6.2
- 2.5.5
- 2.4.5
script: bundle exec rspec spec
36 changes: 24 additions & 12 deletions lib/nist_randomness_beacon/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

module NISTRandomnessBeacon
# Client to the NIST Randomness Beacon API
# Certificate
# https://beacon.nist.gov/beacon/2.0/certificate/<certificateIdentifier>
#
class Client
DEFAULT_URI = 'https://beacon.nist.gov/beacon/1.0/pulse'.freeze
DEFAULT_URI = 'https://beacon.nist.gov/beacon/2.0'.freeze

include HTTParty
attr_reader :timestamp, :uri
Expand All @@ -15,42 +18,51 @@ def initialize(time=nil, uri=DEFAULT_URI)
end

# Returns the Current Record (or next closest AFTER the timestamp)
# https://<server name>/<context>/beacon/1.0/pulse/<timestamp>
# https://<default uri>/pulse/time/<timestamp>
#
def current
response = self.class.get("#@uri/#@timestamp")
response = self.class.get("#@uri/pulse/time/#@timestamp")
create_new_record(response)
end

# Returns the Previous Record
# https://<server name>/<context>/beacon/1.0/pulse/previous/<timestamp>
# https://<default uri>/pulse/time/previous/<timestamp>
#
def previous
response = self.class.get("#@uri/previous/#@timestamp")
response = self.class.get("#@uri/pulse/time/previous/#@timestamp")
create_new_record(response)
end

# Returns the Next Record
# https://<server name>/<context>/beacon/1.0/pulse/next/<timestamp>
# https://<default uri>/pulse/time/next/<timestamp>
#
def next
response = self.class.get("#@uri/next/#@timestamp")
response = self.class.get("#@uri/pulse/time/next/#@timestamp")
create_new_record(response)
end

# Returns the Last Record
# https://<server name>/<context>/beacon/1.0/pulse/last
# https://<default uri>/pulse/last
# https://<default uri>/beacon/2.0/chain/last/pulse/last
#
def last
response = self.class.get("#@uri/last")
response = self.class.get("#@uri/pulse/last")
create_new_record(response)
end

# Returns the Start Chain Record
# https://<server name>/<context>/beacon/1.0/pulse/start-chain/<timestamp>
# https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1
#
def start_chain
response = self.class.get("#@uri/start-chain/#@timestamp")
def start_chain()
response = self.class.get("#@uri/chain/1/pulse/1")
create_new_record(response)
end

# Returns a Specific Pulse in a Specific Chain
# required arguments: a chain_index and a pulse_index both integers
#
def pulse_in_chain(chain_index:1, pulse_index:1)
response = self.class.get("#@uri/chain/#{chain_index}/pulse/#{pulse_index}")
create_new_record(response)
end

Expand Down
15 changes: 8 additions & 7 deletions nist_randomness_beacon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.required_ruby_version = ['>= 2.3.0', '<= 2.5.0']
spec.required_ruby_version = ['>= 2.4.0']

spec.add_development_dependency 'bundler', '~> 1.12'
spec.add_development_dependency 'rake', '~> 12'
spec.add_development_dependency 'awesome_print', '~> 1.7'
spec.add_development_dependency 'yard', '~> 0.9.12'
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'rspec', '~> 3.8'
spec.add_development_dependency 'vcr', '~> 4.0'
spec.add_development_dependency 'webmock', '~> 3.3'
spec.add_development_dependency 'simplecov', '~> 0.12'
spec.add_development_dependency 'timecop', '~> 0.8'
spec.add_development_dependency 'webmock', '~> 3.5'
spec.add_development_dependency 'simplecov', '~> 0.16'
spec.add_development_dependency 'timecop', '~> 0.9'
spec.add_development_dependency 'irb'

spec.add_dependency 'httparty', '~> 0.15'
spec.add_dependency 'json', '~> 2.1'
spec.add_dependency 'httparty', '~> 0.16'
spec.add_dependency 'json', '~> 2.2'
end
65 changes: 65 additions & 0 deletions spec/cassettes/current_beacon_v2.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/cassettes/last_beacon_v2.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/cassettes/next_beacon_v2.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions spec/cassettes/previous_beacon_v2.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading