class CFoundry::V2::Client
The primary API entrypoint. Wraps a BaseClient
to provide nicer return values. Initialize with the target and, optionally, an auth token. These are the only two internal states.
Attributes
base[R]
Internal BaseClient
instance. Normally won't be touching this.
current_organization[RW]
Organization
-
Currently targeted organization.
current_space[RW]
Space
-
Currently targeted space.
Public Class Methods
new(target, token = nil, options = {})
click to toggle source
Create a new Client
for interfacing with the given target.
A token may also be provided to skip the login step.
# File lib/cfoundry/v2/client.rb, line 27 def initialize(target, token = nil, options = {}) @base = Base.new(target, token, options) end
Public Instance Methods
current_user()
click to toggle source
The currently authenticated user.
# File lib/cfoundry/v2/client.rb, line 36 def current_user return unless token token_data = @base.token.token_data if guid = token_data[:user_id] user = user(guid) user.emails = [{ :value => token_data[:email] }] user end end
logged_in?()
click to toggle source
Is an authentication token set on the client?
# File lib/cfoundry/v2/client.rb, line 67 def logged_in? !!@base.token end
login(credentials)
click to toggle source
Calls superclass method
# File lib/cfoundry/v2/client.rb, line 47 def login(credentials) @current_organization = nil @current_space = nil super end
logout()
click to toggle source
Clear client token. No requests are made for this.
# File lib/cfoundry/v2/client.rb, line 62 def logout @base.token = nil end
make_service_instance(json)
click to toggle source
# File lib/cfoundry/v2/client.rb, line 96 def make_service_instance(json) klass = "CFoundry::V2::#{json[:entity][:type].camelize}".constantize klass.new( json[:metadata][:guid], self, json) end
query_target(klass)
click to toggle source
# File lib/cfoundry/v2/client.rb, line 71 def query_target(klass) if klass.scoped_space && space = current_space space elsif klass.scoped_organization && org = current_organization org else self end end
register(email, password, options = {})
click to toggle source
# File lib/cfoundry/v2/client.rb, line 53 def register(email, password, options = {}) uaa_user = @base.uaa.add_user(email, password, options) cc_user = user cc_user.guid = uaa_user[:id] cc_user.create! cc_user end
service_instances(opts={})
click to toggle source
Calls superclass method
# File lib/cfoundry/v2/client.rb, line 85 def service_instances(opts={}) opts[:user_provided] = true super(opts) end
service_instances_from(path, *args)
click to toggle source
Calls superclass method
# File lib/cfoundry/v2/client.rb, line 90 def service_instances_from(path, *args) opts = args.first || {} opts[:user_provided] = true super(path, opts, *args) end
stream_url(url, &blk)
click to toggle source
# File lib/cfoundry/v2/client.rb, line 81 def stream_url(url, &blk) @base.stream_url(url, &blk) end
version()
click to toggle source
# File lib/cfoundry/v2/client.rb, line 31 def version 2 end