Module: Setsuzoku::Service

Extended by:
Forwardable, T::Helpers, T::Sig
Included in:
WebService::Service
Defined in:
lib/setsuzoku/service.rb,
lib/setsuzoku/service/web_service.rb,
lib/setsuzoku/service/web_service/service.rb,
lib/setsuzoku/service/web_service/api_strategy.rb,
lib/setsuzoku/service/web_service/auth_strategy.rb,
lib/setsuzoku/service/web_service/api_strategies/rest_strategy.rb,
lib/setsuzoku/service/web_service/credentials/o_auth_credential.rb,
lib/setsuzoku/service/web_service/api_strategies/rest_api_request.rb,
lib/setsuzoku/service/web_service/auth_strategies/o_auth_strategy.rb,
lib/setsuzoku/service/web_service/credentials/basic_auth_credential.rb,
lib/setsuzoku/service/web_service/credentials/uses_credential_token.rb,
lib/setsuzoku/service/web_service/credentials/custom_auth_credential.rb,
lib/setsuzoku/service/web_service/auth_strategies/basic_auth_strategy.rb,
lib/setsuzoku/service/web_service/auth_strategies/custom_auth_strategy.rb,
lib/setsuzoku/service/web_service/auth_strategies/strategy_can_use_tokens.rb

Overview

Core service required for a web service plugin. It should be able to register all of its available api and auth strategies. It acts as the orchestration between a plugin, auth_strategy, and api_strategy.

Defined Under Namespace

Modules: ClassMethods, WebService

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_strategyObject

Returns the value of attribute api_strategy.



18
19
20
# File 'lib/setsuzoku/service.rb', line 18

def api_strategy
  @api_strategy
end

#auth_strategyObject

Returns the value of attribute auth_strategy.



17
18
19
# File 'lib/setsuzoku/service.rb', line 17

def auth_strategy
  @auth_strategy
end

#external_api_handlerObject

Returns the value of attribute external_api_handler.



19
20
21
# File 'lib/setsuzoku/service.rb', line 19

def external_api_handler
  @external_api_handler
end

#pluginObject

Returns the value of attribute plugin.



16
17
18
# File 'lib/setsuzoku/service.rb', line 16

def plugin
  @plugin
end

Class Method Details

.included(klass) ⇒ Object



23
24
25
# File 'lib/setsuzoku/service.rb', line 23

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#finalService

Initialize the plugin_service by setting its auth and api strategies.

Parameters:

  • auth_strategy (AuthStrategy)

    the auth_strategy for the service to use.

  • api_strategy (ApiStrategy)

    the api_strategy for the service to use.

Returns:

  • (Service)

    the new instance of service with its correct strategies.



46
47
48
49
50
51
52
# File 'lib/setsuzoku/service.rb', line 46

sig(:final) do
  params(
      plugin: T.untyped,
      strategies: T::Hash[Symbol, T.untyped],
      args: T.untyped
  ).returns(T.any(Setsuzoku::Service::WebService::Service, T.untyped))
end

#initialize(plugin:, strategies:, **args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/setsuzoku/service.rb', line 53

def initialize(plugin:, strategies:, **args)
  #TODO: here we need to assign credentials etc, I think.
  self.plugin = plugin
  self.external_api_handler = Setsuzoku.external_api_handler.new

  # iterate over all strategies this plugin's service uses and set their configuration
  strategies.each do |strategy, attrs|
    # get the strategy type from auth_strategy/api_strategy etc.
    type = T.must(strategy.to_s.split("_strategy").first).to_sym
    strat = attrs[:strategy]
    # associate the strategy with the service
    self.send("#{strategy}=", self.class.available_strategies[type][strat].new(service: self, credential: args[:credential], **attrs.except(:strategy)))
  end

  self
end