Class: CFoundry::BaseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/appfog-vmc-plugin/non_uaa.rb,
lib/appfog-vmc-plugin/cfoundry/baseclient.rb

Direct Known Subclasses

Client

Instance Method Summary collapse

Instance Method Details

#get(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/appfog-vmc-plugin/cfoundry/baseclient.rb', line 3

def get(*args)
  options = args.reduce({}) do |opts, arg|
    arg.is_a?(Hash) ? arg : opts
  end
  tries = options.has_key?(:retry) && options[:retry] == false ? 1 : 3
  delay = options.has_key?(:delay) ? options[:delay] : 10
  with_retry(tries, delay, [CFoundry::TargetRefused, CFoundry::BadResponse]) do
    request("GET", *args)
  end
end

#uaaObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/appfog-vmc-plugin/non_uaa.rb', line 11

def uaa
  return @uaa unless @uaa.nil?

  endpoint = info[:authorization_endpoint]

  return @uaa = false unless endpoint
  @uaa = CFoundry::UAAClient.new(endpoint)
  @uaa.trace = @trace
  @uaa.token = @token
  @uaa
end

#with_retry(tries, delay = 2, exceptions = []) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/appfog-vmc-plugin/cfoundry/baseclient.rb', line 14

def with_retry(tries, delay=2, exceptions=[])
  try_count = 0
  loop do
    begin
      try_count += 1
      return yield
    rescue Exception => e
      if try_count > tries || !exceptions.include?(e.class)
        raise e
      end
      sleep delay * try_count
    end
  end
end