Class: BooticClient::Strategies::Strategy

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

Direct Known Subclasses

Authorized, ClientCredentials

Instance Method Summary collapse

Constructor Details

#initialize(config, client_opts = {}, &on_new_token) ⇒ 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

#get(href, query = {}) ⇒ Object



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

def get(href, query = {})
  begin
    client.get_and_wrap(href, Entity, query)
  rescue TokenError => e
    new_token = get_token
    client.options[:access_token] = new_token
    on_new_token.call new_token
    client.get_and_wrap(href, Entity, query)
  end
end

#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

#root ⇒ Object



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

def root
  get config.api_root
end