Class: BooticClient::Strategies::Strategy

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

Direct Known Subclasses

BasicAuth, Bearer, 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.

Raises:

  • (ArgumentError)

9
10
11
12
13
# File 'lib/bootic_client/strategies/strategy.rb', line 9

def initialize(config, client_opts = {}, &on_new_token)
  @config, @options, @on_new_token = config, client_opts, (on_new_token || Proc.new{})
  raise ArgumentError, 'must include a Configuration object' unless config
  validate!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.


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

def options
  @options
end

Instance Method Details

#from_hash(hash, wrapper_class = Entity) ⇒ Object


19
20
21
# File 'lib/bootic_client/strategies/strategy.rb', line 19

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

#from_url(url) ⇒ Object


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

def from_url(url)
  request_and_wrap :get, url
end

#inspectObject


35
36
37
# File 'lib/bootic_client/strategies/strategy.rb', line 35

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

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


27
28
29
30
31
32
33
# File 'lib/bootic_client/strategies/strategy.rb', line 27

def request_and_wrap(request_method, href, payload = {})
  pre_flight
  retryable do
    resp = client.send(request_method, href, payload, request_headers)
    config.response_handlers.resolve(resp, self)
  end
end

#rootObject


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

def root
  request_and_wrap :get, config.api_root
end