Class: Client
Constant Summary collapse
- @@api_end_points =
{ 'prod' => ['api.stampery.com', 4000], 'beta' => ['api-beta.stampery.com', 4000] }
- @@amqp_end_points =
{ 'prod' => ['young-squirrel.rmq.cloudamqp.com', 5672, 'consumer', '9FBln3UxOgwgLZtYvResNXE7', 'ukgmnhoi'], 'beta' => ['young-squirrel.rmq.cloudamqp.com', 5672, 'consumer', '9FBln3UxOgwgLZtYvResNXE7', 'beta'] }
Instance Method Summary collapse
- #hash(data) ⇒ Object
-
#initialize(secret, branch = 'prod') ⇒ Client
constructor
A new instance of Client.
- #prove(hash, proof) ⇒ Object
- #stamp(data) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(secret, branch = 'prod') ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 |
# File 'lib/stampery.rb', line 16 def initialize(secret, branch = 'prod') @client_secret = secret @client_id = Digest::MD5.hexdigest(secret)[0, 15] @api_end_point = @@api_end_points[branch] || @@api_end_points['prod'] @amqp_end_point = @@amqp_end_points[branch] || @@amqp_end_points['prod'] end |
Instance Method Details
#hash(data) ⇒ Object
37 38 39 |
# File 'lib/stampery.rb', line 37 def hash(data) SHA3::Digest.hexdigest(:sha512, data).upcase end |
#prove(hash, proof) ⇒ Object
41 42 43 |
# File 'lib/stampery.rb', line 41 def prove(hash, proof) validate hash, proof['siblings'], proof['root'] end |
#stamp(data) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/stampery.rb', line 28 def stamp(data) puts "Stamping \n#{data}" begin @api_client.call 'stamp', data.upcase rescue Exception => e emit :error, e end end |
#start ⇒ Object
23 24 25 26 |
# File 'lib/stampery.rb', line 23 def start api_login @api_end_point amqp_login @amqp_end_point if @auth end |