Class: BooticClient::Strategies::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_client/strategies/strategy.rb

Direct Known Subclasses

BasicAuth, Oauth2Strategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, client_opts = {}, &on_new_token) ⇒ Strategy

Returns a new instance of Strategy.



7
8
9
10
# File 'lib/bootic_client/strategies/strategy.rb', line 7

def initialize(config, client_opts = {}, &on_new_token)
  @config, @options, @on_new_token = config, client_opts, (on_new_token || Proc.new{})
  validate!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/bootic_client/strategies/strategy.rb', line 5

def options
  @options
end

Instance Method Details

#from_hash(hash, wrapper_class = Entity) ⇒ Object



16
17
18
# File 'lib/bootic_client/strategies/strategy.rb', line 16

def from_hash(hash, wrapper_class = Entity)
  wrapper_class.new hash, self
end

#inspectObject



27
28
29
# File 'lib/bootic_client/strategies/strategy.rb', line 27

def inspect
  %(#<#{self.class.name} root: #{config.api_root}>)
end

#request_and_wrap(request_method, href, wrapper_class, payload = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/bootic_client/strategies/strategy.rb', line 20

def request_and_wrap(request_method, href, wrapper_class, payload = {})
  pre_flight
  retryable do
    wrapper_class.new client.send(request_method, href, payload, request_headers).body, self
  end
end

#rootObject



12
13
14
# File 'lib/bootic_client/strategies/strategy.rb', line 12

def root
  request_and_wrap :get, config.api_root, Entity
end