Class: CFoundry::V2::Client
- Inherits:
-
Object
- Object
- CFoundry::V2::Client
- 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.
-
#info ⇒ Object
Cloud metadata.
-
#initialize(target = "http://api.cloudfoundry.com", token = nil) ⇒ Client
constructor
Create a new Client for interfacing with the given target.
-
#log ⇒ Object
The current log.
-
#log=(mode) ⇒ Object
Set the logging mode.
-
#logged_in? ⇒ Boolean
Is an authentication token set on the client?.
- #login(username, password) ⇒ Object
-
#logout ⇒ Object
Clear client token.
-
#proxy ⇒ Object
Current proxy user.
-
#proxy=(email) ⇒ Object
Set the proxy user for the client.
- #query_target(klass) ⇒ Object
- #register(email, password) ⇒ Object
- #stream_url(url, &blk) ⇒ Object
-
#target ⇒ Object
The current target URL of the client.
-
#token ⇒ Object
Current authentication token.
-
#token=(token) ⇒ Object
Set the authentication token.
-
#trace ⇒ Object
Is the client tracing API requests?.
-
#trace=(bool) ⇒ Object
Set the tracing flag; if true, API requests and responses will be printed out.
- #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.
23 24 25 |
# File 'lib/cfoundry/v2/client.rb', line 23 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.
11 12 13 |
# File 'lib/cfoundry/v2/client.rb', line 11 def base @base end |
#current_organization ⇒ Object
- Organization
-
Currently targeted organization.
14 15 16 |
# File 'lib/cfoundry/v2/client.rb', line 14 def current_organization @current_organization end |
#current_space ⇒ Object
- Space
-
Currently targeted space.
17 18 19 |
# File 'lib/cfoundry/v2/client.rb', line 17 def current_space @current_space end |
Instance Method Details
#current_user ⇒ Object
The currently authenticated user.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cfoundry/v2/client.rb', line 84 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 |
#info ⇒ Object
Cloud metadata
96 97 98 |
# File 'lib/cfoundry/v2/client.rb', line 96 def info @base.info end |
#log ⇒ Object
The current log. See log=
.
69 70 71 |
# File 'lib/cfoundry/v2/client.rb', line 69 def log @base.log end |
#log=(mode) ⇒ Object
Set the logging mode. Mode can be one of:
String
-
Name of a file to log the last 10 requests to.
Array
-
Array to append with log data (a Hash).
IO
-
An IO object to write to.
false
-
No logging.
79 80 81 |
# File 'lib/cfoundry/v2/client.rb', line 79 def log=(mode) @base.log = mode end |
#logged_in? ⇒ Boolean
Is an authentication token set on the client?
120 121 122 |
# File 'lib/cfoundry/v2/client.rb', line 120 def logged_in? !!@base.token end |
#login(username, password) ⇒ Object
100 101 102 103 104 |
# File 'lib/cfoundry/v2/client.rb', line 100 def login(username, password) @current_organization = nil @current_space = nil super end |
#logout ⇒ Object
Clear client token. No requests are made for this.
115 116 117 |
# File 'lib/cfoundry/v2/client.rb', line 115 def logout @base.token = nil end |
#proxy ⇒ Object
Current proxy user. Usually nil.
47 48 49 |
# File 'lib/cfoundry/v2/client.rb', line 47 def proxy @base.proxy end |
#proxy=(email) ⇒ Object
Set the proxy user for the client. Must be authorized as an administrator for this to have any effect.
53 54 55 |
# File 'lib/cfoundry/v2/client.rb', line 53 def proxy=(email) @base.proxy = email end |
#query_target(klass) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/cfoundry/v2/client.rb', line 124 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
106 107 108 109 110 111 112 |
# File 'lib/cfoundry/v2/client.rb', line 106 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
134 135 136 |
# File 'lib/cfoundry/v2/client.rb', line 134 def stream_url(url, &blk) @base.stream_url(url, &blk) end |
#target ⇒ Object
The current target URL of the client.
32 33 34 |
# File 'lib/cfoundry/v2/client.rb', line 32 def target @base.target end |
#token ⇒ Object
Current authentication token.
37 38 39 |
# File 'lib/cfoundry/v2/client.rb', line 37 def token @base.token end |
#token=(token) ⇒ Object
Set the authentication token.
42 43 44 |
# File 'lib/cfoundry/v2/client.rb', line 42 def token=(token) @base.token = token end |
#trace ⇒ Object
Is the client tracing API requests?
58 59 60 |
# File 'lib/cfoundry/v2/client.rb', line 58 def trace @base.trace end |
#trace=(bool) ⇒ Object
Set the tracing flag; if true, API requests and responses will be printed out.
64 65 66 |
# File 'lib/cfoundry/v2/client.rb', line 64 def trace=(bool) @base.trace = bool end |
#version ⇒ Object
27 28 29 |
# File 'lib/cfoundry/v2/client.rb', line 27 def version 2 end |