Class: Teems::Runner

Inherits:
Object
  • Object
show all
Includes:
ApiFactories
Defined in:
lib/teems/runner.rb

Overview

Dependency injection container providing services to commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiFactories

#calendar_api, #channels_api, #chats_api, #files_api, #meetings_api, #messages_api, #users_api

Constructor Details

#initialize(output: Formatters::Output.new, config: Services::Configuration.new, token_store: Services::TokenStore.new, api_client: nil, cache_store: Services::CacheStore.new) ⇒ Runner

Returns a new instance of Runner.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/teems/runner.rb', line 21

def initialize(
  output: Formatters::Output.new,
  config: Services::Configuration.new,
  token_store: Services::TokenStore.new,
  api_client: nil,
  cache_store: Services::CacheStore.new
)
  api_client ||= Services::ApiClient.new(endpoints: config['endpoints'] || {})
  @output = output
  @config = config
  @token_store = token_store
  @services = { api_client: api_client, cache_store: cache_store }

  wire_up_warnings
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/teems/runner.rb', line 19

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



19
20
21
# File 'lib/teems/runner.rb', line 19

def output
  @output
end

#token_storeObject (readonly)

Returns the value of attribute token_store.



19
20
21
# File 'lib/teems/runner.rb', line 19

def token_store
  @token_store
end

Instance Method Details

#accountObject

Account helpers - always get fresh from token_store (important for token refresh)



41
42
43
# File 'lib/teems/runner.rb', line 41

def 
  @token_store. or raise ConfigError, 'No account configured. Run: teems auth login'
end

#api_clientObject



37
# File 'lib/teems/runner.rb', line 37

def api_client = @services[:api_client]

#cache_storeObject



38
# File 'lib/teems/runner.rb', line 38

def cache_store = @services[:cache_store]

#clear_api_cacheObject

Clear any cached API instances after token refresh



50
51
52
53
# File 'lib/teems/runner.rb', line 50

def clear_api_cache
  # API instances are not cached, but account is fetched fresh each time
  # This method exists for future extensibility
end

#configured?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/teems/runner.rb', line 45

def configured?
  @token_store.configured?
end

#message_formatterObject

Formatter helpers



56
57
58
# File 'lib/teems/runner.rb', line 56

def message_formatter
  Formatters::MessageFormatter.new(output: @output, cache_store: cache_store)
end

#refresh_tokensObject

Attempt to refresh the skype_token



76
77
78
# File 'lib/teems/runner.rb', line 76

def refresh_tokens
  token_refresher.refresh
end

#safari_js_runnerObject

Safari JS runner for SharePoint automation



61
62
63
# File 'lib/teems/runner.rb', line 61

def safari_js_runner
  Services::SafariJsRunner.new(output: @output)
end

#token_extractor(auth_mode: :default) ⇒ Object

Token extractor for Safari automation



66
67
68
# File 'lib/teems/runner.rb', line 66

def token_extractor(auth_mode: :default)
  Services::TokenExtractor.new(output: @output, auth_mode: auth_mode)
end

#token_refresherObject

Token refresher for automatic token refresh



71
72
73
# File 'lib/teems/runner.rb', line 71

def token_refresher
  Services::TokenRefresher.new(token_store: @token_store, output: @output)
end