Class: ClientAuth
- Inherits:
-
Object
- Object
- ClientAuth
- Defined in:
- lib/client_auth.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api_key, secret_key) ⇒ ClientAuth
constructor
A new instance of ClientAuth.
- #outgoing(message, callback) ⇒ Object
Constructor Details
#initialize(api_key, secret_key) ⇒ ClientAuth
Returns a new instance of ClientAuth.
3 4 5 |
# File 'lib/client_auth.rb', line 3 def initialize api_key, secret_key @headers = self.class.build_headers api_key, secret_key end |
Class Method Details
.build_headers(api_key, secret_key) ⇒ Object
26 27 28 29 30 |
# File 'lib/client_auth.rb', line 26 def self.build_headers api_key, secret_key time = Time.now.utc.to_i hash = Digest::SHA1.hexdigest("#{api_key}#{secret_key}#{time}").downcase { 'api_key' => api_key, 'hash' => hash, 'time' => time.to_s } end |
Instance Method Details
#outgoing(message, callback) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/client_auth.rb', line 7 def outgoing(, callback) # Again, leave non-subscribe messages alone if ['channel'] != '/meta/subscribe' return callback.call() end # Add ext field if it's not present ['ext'] ||= {} # Set the tokens ['ext']['api_key'] = @headers['api_key'] ['ext']['hash'] = @headers['hash'] ['ext']['time'] = @headers['time'] # Carry on and send the message to the server callback.call() end |