Module: BWAPI::Authentication

Included in:
Client
Defined in:
lib/bwapi/authentication.rb

Instance Method Summary collapse

Instance Method Details

#api_client?Boolean

Check if user is a brandwatch-api-client type



23
24
25
# File 'lib/bwapi/authentication.rb', line 23

def api_client?
  client_id == 'brandwatch-api-client' ? true : false
end

#application_client?Boolean

Check if user is a brandwatch-application-client type



16
17
18
# File 'lib/bwapi/authentication.rb', line 16

def application_client?
  client_id == 'brandwatch-application-client' ? true : false
end

#authenticated?Boolean

Check if user is authenicated



9
10
11
# File 'lib/bwapi/authentication.rb', line 9

def authenticated?
  !!access_token
end

#netrc_credentials(netrc = false) ⇒ Object

Set username and password via netrc



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bwapi/authentication.rb', line 30

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]
  raise '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