Class: ActiveRecordApi::Request::Credentials
- Inherits:
-
Object
- Object
- ActiveRecordApi::Request::Credentials
- Includes:
- ActiveAttr::Model
- Defined in:
- lib/active_record_api/request/credentials.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #email ⇒ Object
- #headers ⇒ Object
- #host ⇒ Object
- #password ⇒ Object
- #token ⇒ Object
- #token_path ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#email ⇒ Object
22 23 24 |
# File 'lib/active_record_api/request/credentials.rb', line 22 def email @email ||= config(:email) end |
#headers ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/active_record_api/request/credentials.rb', line 30 def headers @headers ||= {}.tap do |headers| if token.present? headers['Authorization'] = "Bearer #{token}" else headers['InjectToken'] = 'true' end end end |
#host ⇒ Object
14 15 16 |
# File 'lib/active_record_api/request/credentials.rb', line 14 def host @host ||= config(:host) end |
#password ⇒ Object
26 27 28 |
# File 'lib/active_record_api/request/credentials.rb', line 26 def password @password ||= config(:password) end |
#token ⇒ Object
10 11 12 |
# File 'lib/active_record_api/request/credentials.rb', line 10 def token @token ||= config(:token) end |
#token_path ⇒ Object
18 19 20 |
# File 'lib/active_record_api/request/credentials.rb', line 18 def token_path @token_path ||= config(:token_path) end |
Instance Method Details
#config(name) ⇒ Object
48 49 50 |
# File 'lib/active_record_api/request/credentials.rb', line 48 def config(name) ENV["ACTIVE_RECORD_API_REQUEST_#{name.upcase}"] || credentials_config(name) end |
#credentials ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/active_record_api/request/credentials.rb', line 40 def credentials { email: email, password: password, grant_type: 'password' } end |
#credentials_config(name) ⇒ Object
52 53 54 55 |
# File 'lib/active_record_api/request/credentials.rb', line 52 def credentials_config(name) return unless defined? Rails Rails.application.try(:credentials).try(:active_record_api_request).try(:[], name) end |