Class: MotionOcean::API::Authorization
- Inherits:
-
Object
- Object
- MotionOcean::API::Authorization
- Defined in:
- lib/motion_ocean/api/authorization.rb
Class Method Summary collapse
- .build(options = {}) ⇒ Object
- .http_basic_header(username, password) ⇒ Object
- .token_header(token, token_name) ⇒ Object
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( = {}) username, password = .values_at :username, :password token = .fetch(:token, nil) token_name = .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 |