Class: Strongmind::CommonNavFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/strongmind/common_nav_fetcher.rb

Overview

This class is responsible for fetching the common navbar data from SM Central

Defined Under Namespace

Classes: TokenNotFoundError, UserNotFoundError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ CommonNavFetcher

Returns a new instance of CommonNavFetcher.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/strongmind/common_nav_fetcher.rb', line 16

def initialize(user)
  raise Strongmind::Exceptions::UserNotFoundError, 'User not found' unless user.present?
  raise ArgumentError, 'Identity base URL not found at IDENTITY_BASE_URL in environment' unless ENV['IDENTITY_BASE_URL'].present?
  raise ArgumentError, 'Identity client ID not found at IDENTITY_CLIENT_ID in environment' unless ENV['IDENTITY_CLIENT_ID'].present?
  raise ArgumentError, 'Identity client secret not found at IDENTITY_CLIENT_SECRET in environment' unless ENV['IDENTITY_CLIENT_SECRET'].present?

  @user = user
  @auth_client = PlatformSdk::Identity::AuthClient.new(
    ENV.fetch('IDENTITY_BASE_URL'), ENV.fetch('IDENTITY_CLIENT_ID'), ENV.fetch('IDENTITY_CLIENT_SECRET')
  )
end

Instance Attribute Details

#auth_clientObject (readonly)

Returns the value of attribute auth_client.



8
9
10
# File 'lib/strongmind/common_nav_fetcher.rb', line 8

def auth_client
  @auth_client
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/strongmind/common_nav_fetcher.rb', line 8

def user
  @user
end

Instance Method Details

#retrieve(nav_items, nav_options) ⇒ Object



28
29
30
31
# File 'lib/strongmind/common_nav_fetcher.rb', line 28

def retrieve(nav_items, nav_options)
  response = fetch_navbar_data(nav_items, nav_options)
  parse_navbar(response)
end