Class: BerkeleyLibrary::Location::WorldCat::OCLCAuth
- Inherits:
-
Object
- Object
- BerkeleyLibrary::Location::WorldCat::OCLCAuth
- Includes:
- Singleton
- Defined in:
- lib/berkeley_library/location/world_cat/oclc_auth.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#access_token ⇒ Object
Before every request check if the token is expired (OCLC tokens expire after 20 minutes).
- #fetch_token ⇒ Object
-
#initialize ⇒ OCLCAuth
constructor
A new instance of OCLCAuth.
- #oclc_token_url ⇒ Object
Constructor Details
#initialize ⇒ OCLCAuth
Returns a new instance of OCLCAuth.
12 13 14 15 16 17 |
# File 'lib/berkeley_library/location/world_cat/oclc_auth.rb', line 12 def initialize # Sorry Rubocop - needs to be ||= because we're dealing with a singleton # rubocop:disable Lint/DisjunctiveAssignmentInConstructor @token ||= fetch_token # rubocop:enable Lint/DisjunctiveAssignmentInConstructor: end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/berkeley_library/location/world_cat/oclc_auth.rb', line 10 def token @token end |
Instance Method Details
#access_token ⇒ Object
Before every request check if the token is expired (OCLC tokens expire after 20 minutes)
29 30 31 32 |
# File 'lib/berkeley_library/location/world_cat/oclc_auth.rb', line 29 def access_token @token = fetch_token if token_expired? @token[:access_token] end |
#fetch_token ⇒ Object
19 20 21 22 |
# File 'lib/berkeley_library/location/world_cat/oclc_auth.rb', line 19 def fetch_token response = http_request(oclc_token_url) JSON.parse(response.body, symbolize_names: true) end |
#oclc_token_url ⇒ Object
24 25 26 |
# File 'lib/berkeley_library/location/world_cat/oclc_auth.rb', line 24 def oclc_token_url URI.parse("#{Config.token_uri}?#{URI.encode_www_form(token_params)}") end |