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 = "http://api.cloudfoundry.com", 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.
- #query_target(klass) ⇒ Object
- #register(email, password) ⇒ Object
- #stream_url(url, &blk) ⇒ Object
- #version ⇒ Object
Methods included from LoginHelpers
Constructor Details
#initialize(target = "http://api.cloudfoundry.com", token = nil) ⇒ Client
Create a new Client for interfacing with the given target.
A token may also be provided to skip the login step.
27 28 29 |
# File 'lib/cfoundry/v2/client.rb', line 27 def initialize(target = "http://api.cloudfoundry.com", token = nil) @base = Base.new(target, token) end |
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 |
#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) ⇒ 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 |
#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 |