Class: Client

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/stampery.rb

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

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



39
40
41
# File 'lib/stampery.rb', line 39

def hash data
  SHA3::Digest.hexdigest(:sha512, data).upcase
end

#stamp(data) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/stampery.rb', line 30

def stamp data
  puts "Stamping \n#{data}"
  begin
    @api_client.call 'stamp', data.upcase
  rescue Exception => e
    emit :error, e
  end
end

#startObject



23
24
25
26
27
28
# File 'lib/stampery.rb', line 23

def start
   @api_end_point
  if @auth
     @amqp_end_point
  end
end