Class: CFoundry::V2::Client
- Inherits:
-
Object
- Object
- CFoundry::V2::Client
- Extended by:
- Forwardable
- Includes:
- LoginHelpers, ClientMethods
- Defined in:
- lib/cfoundry/v2/client.rb
Overview
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.
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Internal BaseClient instance.
-
#current_organization ⇒ Object
- Organization
-
Currently targeted organization.
-
#current_space ⇒ Object
- Space
-
Currently targeted space.
Instance Method Summary collapse
-
#current_user ⇒ Object
The currently authenticated user.
-
#initialize(target, token = nil) ⇒ Client
constructor
Create a new Client for interfacing with the given target.
-
#logged_in? ⇒ Boolean
Is an authentication token set on the client?.
- #login(credentials) ⇒ Object
-
#logout ⇒ Object
Clear client token.
- #make_service_instance(json) ⇒ Object
- #query_target(klass) ⇒ Object
- #register(email, password, options = {}) ⇒ Object
- #service_instances(opts = {}) ⇒ Object
- #service_instances_from(path, *args) ⇒ Object
- #stream_url(url, &blk) ⇒ Object
- #version ⇒ Object
Methods included from LoginHelpers
Constructor Details
Instance Attribute Details
#base ⇒ Object (readonly)
Internal BaseClient instance. Normally won’t be touching this.
13 14 15 |
# File 'lib/cfoundry/v2/client.rb', line 13 def base @base end |
#current_organization ⇒ Object
- Organization
-
Currently targeted organization.
16 17 18 |
# File 'lib/cfoundry/v2/client.rb', line 16 def current_organization @current_organization end |
#current_space ⇒ Object
- Space
-
Currently targeted space.
19 20 21 |
# File 'lib/cfoundry/v2/client.rb', line 19 def current_space @current_space end |
Instance Method Details
#current_user ⇒ Object
The currently authenticated user.
36 37 38 39 40 41 42 43 44 45 |
# 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? ⇒ Boolean
Is an authentication token set on the client?
67 68 69 |
# File 'lib/cfoundry/v2/client.rb', line 67 def logged_in? !!@base.token end |
#login(credentials) ⇒ Object
47 48 49 50 51 |
# File 'lib/cfoundry/v2/client.rb', line 47 def login(credentials) @current_organization = nil @current_space = nil super end |
#logout ⇒ Object
Clear client token. No requests are made for this.
62 63 64 |
# File 'lib/cfoundry/v2/client.rb', line 62 def logout @base.token = nil end |
#make_service_instance(json) ⇒ Object
96 97 98 99 100 101 102 |
# 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) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# 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 = {}) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/cfoundry/v2/client.rb', line 53 def register(email, password, = {}) uaa_user = @base.uaa.add_user(email, password, ) cc_user = user cc_user.guid = uaa_user[:id] cc_user.create! cc_user end |
#service_instances(opts = {}) ⇒ Object
85 86 87 88 |
# File 'lib/cfoundry/v2/client.rb', line 85 def service_instances(opts={}) opts[:user_provided] = true super(opts) end |
#service_instances_from(path, *args) ⇒ Object
90 91 92 93 94 |
# 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) ⇒ Object
81 82 83 |
# File 'lib/cfoundry/v2/client.rb', line 81 def stream_url(url, &blk) @base.stream_url(url, &blk) end |
#version ⇒ Object
31 32 33 |
# File 'lib/cfoundry/v2/client.rb', line 31 def version 2 end |