Class: BooticClient::Strategies::Strategy
- Inherits:
-
Object
- Object
- BooticClient::Strategies::Strategy
show all
- Defined in:
- lib/bootic_client/strategies/strategy.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config, client_opts = {}, &on_new_token) ⇒ Strategy
Returns a new instance of Strategy.
7
8
9
10
11
12
13
|
# 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{})
raise "MUST include client_id" unless config.client_id
raise "MUST include client_secret" unless config.client_secret
raise "MUST include api_root" unless config.api_root
validate! @options
end
|
Instance Method Details
#inspect ⇒ Object
30
31
32
|
# File 'lib/bootic_client/strategies/strategy.rb', line 30
def inspect
%(#<#{self.class.name} cid: #{config.client_id} root: #{config.api_root} auth: #{config.auth_host}>)
end
|
#request_and_wrap(request_method, href, wrapper_class, payload = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/bootic_client/strategies/strategy.rb', line 19
def request_and_wrap(request_method, href, wrapper_class, payload = {})
begin
wrapper_class.new client.send(request_method, href, payload).body, self
rescue TokenError => e
new_token = get_token
client.options[:access_token] = new_token
on_new_token.call new_token
wrapper_class.new client.send(request_method, href, payload).body, self
end
end
|
#root ⇒ Object
15
16
17
|
# File 'lib/bootic_client/strategies/strategy.rb', line 15
def root
request_and_wrap :get, config.api_root, Entity
end
|