Module: Pivit::Authentication

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

Instance Method Summary collapse

Instance Method Details

#authenticate(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pivit/authentication.rb', line 8

def authenticate(options)
  if !options[:username].nil? && !options[:password].nil?
    self.username  = URI::encode(options[:username])
    self.password  = URI::encode(options[:password])
    self.api_token = get("tokens/active").token.guid
    build_endpoint
  elsif !options[:token].nil?
    self.api_token = options[:token]
    build_endpoint
  else
    raise "Your authentication credentials are invalid."
  end 
end

#authenticated?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/pivit/authentication.rb', line 4

def authenticated?
  !self.api_token.nil?
end