Module: BWAPI::Authentication
- Included in:
- Client
- Defined in:
- lib/bwapi/authentication.rb
Overview
Authentication module helper methods
Instance Method Summary collapse
-
#api_client? ⇒ Boolean
Check if user is a brandwatch-api-client type.
-
#application_client? ⇒ Boolean
Check if user is a brandwatch-application-client type.
-
#authenticated? ⇒ Boolean
Check if user is authenicated.
-
#netrc_credentials(netrc = false) ⇒ Object
Set username and password via netrc.
Instance Method Details
#api_client? ⇒ Boolean
Check if user is a brandwatch-api-client type
25 26 27 |
# File 'lib/bwapi/authentication.rb', line 25 def api_client? client_id == 'brandwatch-api-client' ? true : false end |
#application_client? ⇒ Boolean
Check if user is a brandwatch-application-client type
18 19 20 |
# File 'lib/bwapi/authentication.rb', line 18 def application_client? client_id == 'brandwatch-application-client' ? true : false end |
#authenticated? ⇒ Boolean
Check if user is authenicated
11 12 13 |
# File 'lib/bwapi/authentication.rb', line 11 def authenticated? access_token ? true : false end |
#netrc_credentials(netrc = false) ⇒ Object
Set username and password via netrc
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bwapi/authentication.rb', line 32 def netrc_credentials(netrc = false) return unless netrc require 'netrc' file = Netrc.read netrc_file # Get credentials using host netrc_host = URI.parse(api_endpoint).host creds = file[netrc_host] fail 'You are missing your .netrc file or the host provided has no credentials!'.red.underline if creds.nil? self.username = creds.shift self.password = creds.shift rescue LoadError raise 'Please install netrc gem for .netrc support'.red.underline end |