Class: MotionOcean::API::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_ocean/api/authorization.rb

Class Method Summary collapse

Class Method Details

.build(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/motion_ocean/api/authorization.rb', line 5

def build(options = {})
  username, password = options.values_at :username, :password
  token = options.fetch(:token, nil)
  token_name = options.fetch(:token_name, "Token")
      
  if username && password
    http_basic_header(username, password)
  elsif token
    token_header(token, token_name)
  else
    nil
  end
end

.http_basic_header(username, password) ⇒ Object



19
20
21
22
# File 'lib/motion_ocean/api/authorization.rb', line 19

def http_basic_header(username, password)
  token_data = "#{username}:#{password}".dataUsingEncoding(NSUTF8StringEncoding)
  token_header(token_data.base64Encoding, "Basic")
end

.token_header(token, token_name) ⇒ Object



24
25
26
# File 'lib/motion_ocean/api/authorization.rb', line 24

def token_header(token, token_name)
  "#{token_name} #{token}"
end