Class: Polar::Authentication::OATAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/polar/authentication.rb

Overview

Organization Access Token authentication

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ OATAuth

Returns a new instance of OATAuth.



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

def initialize(access_token)
  @access_token = access_token
  validate_token!
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



7
8
9
# File 'lib/polar/authentication.rb', line 7

def access_token
  @access_token
end

Instance Method Details

#headersObject



14
15
16
17
18
19
20
# File 'lib/polar/authentication.rb', line 14

def headers
  {
    'Authorization' => "Bearer #{access_token}",
    'Content-Type' => 'application/json',
    'Accept' => 'application/json'
  }
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/polar/authentication.rb', line 22

def valid?
  !access_token.nil? && !access_token.empty? && access_token.start_with?('polar_oat_')
end