class Botvac::Robot::Hmac

Public Class Methods

new(app, options = {}) click to toggle source
Calls superclass method
# File lib/botvac/robot.rb, line 60
def initialize(app, options = {})
  super(app)
  @digest = OpenSSL::Digest.new('sha256')
  @serial = options[:serial].downcase
  @secret = options[:secret]
end

Public Instance Methods

call(env) click to toggle source
# File lib/botvac/robot.rb, line 67
def call(env)
  "#{Time.now.gmtime.strftime("%a, %d %h %Y %H:%M:%S")} GMT".tap do |date|
    hmac   = OpenSSL::HMAC.hexdigest(@digest, @secret, [@serial, date, env['body']].join("\n"))
    env[:request_headers]['Date']= date
    env[:request_headers]['Authorization']= "NEATOAPP #{hmac}"
  end

  @app.call(env)
end