Class: CFoundry::V1::Client
- Inherits:
-
Object
- Object
- CFoundry::V1::Client
- Includes:
- LoginHelpers, ClientMethods
- Defined in:
- lib/cfoundry/v1/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
Returns the value of attribute base.
Instance Method Summary collapse
- #current_organization ⇒ Object
- #current_space ⇒ Object
-
#current_user ⇒ Object
The currently authenticated user.
- #framework(name) ⇒ Object
- #framework_by_name(name) ⇒ Object
-
#frameworks(options = {}) ⇒ Object
Retrieve available frameworks.
- #generate_plans(meta) ⇒ Object
-
#http_proxy ⇒ Object
Current http proxy URI.
-
#http_proxy=(uri) ⇒ Object
Set the http proxy URI.
-
#https_proxy ⇒ Object
Current https proxy URI.
-
#https_proxy=(uri) ⇒ Object
Set the https proxy URI.
-
#info ⇒ Object
Retrieve target metadata.
-
#initialize(target = "https://api.cloulu.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?.
-
#logout ⇒ Object
Clear client token.
-
#proxy ⇒ Object
Current proxy user.
-
#proxy=(email) ⇒ Object
Set the proxy user for the client.
-
#register(email, password) ⇒ Object
Create a user on the target and return a User object representing them.
- #runtime(name) ⇒ Object
- #runtime_by_name(name) ⇒ Object
-
#runtimes(options = {}) ⇒ Object
Retrieve available runtimes.
-
#services(options = {}) ⇒ Object
Retrieve available services.
-
#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 = "https://api.cloulu.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.
15 16 17 |
# File 'lib/cfoundry/v1/client.rb', line 15 def initialize(target = "https://api.cloulu.com", token = nil) @base = Base.new(target, token) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
10 11 12 |
# File 'lib/cfoundry/v1/client.rb', line 10 def base @base end |
Instance Method Details
#current_organization ⇒ Object
106 107 108 |
# File 'lib/cfoundry/v1/client.rb', line 106 def current_organization nil end |
#current_space ⇒ Object
102 103 104 |
# File 'lib/cfoundry/v1/client.rb', line 102 def current_space nil end |
#current_user ⇒ Object
The currently authenticated user.
96 97 98 99 100 |
# File 'lib/cfoundry/v1/client.rb', line 96 def current_user if user = info[:user] user(user) end end |
#framework(name) ⇒ Object
189 190 191 |
# File 'lib/cfoundry/v1/client.rb', line 189 def framework(name) Framework.new(name) end |
#framework_by_name(name) ⇒ Object
193 194 195 |
# File 'lib/cfoundry/v1/client.rb', line 193 def framework_by_name(name) frameworks.find { |f| f.name == name } end |
#frameworks(options = {}) ⇒ Object
Retrieve available frameworks.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/cfoundry/v1/client.rb', line 172 def frameworks( = {}) fs = info[:frameworks] return unless fs frameworks = [] fs.each do |name, | runtimes = [:runtimes].collect do |r| Runtime.new(r[:name], r[:description]) end frameworks << Framework.new(name.to_s, nil, runtimes, [:detection]) end frameworks end |
#generate_plans(meta) ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/cfoundry/v1/client.rb', line 140 def generate_plans() names = [:plans] descriptions = [:plan_descriptions] default_name = [:default_plan] names.map { |name| description = descriptions[name.to_sym] if descriptions is_default = name == default_name || names.length == 1 ServicePlan.new(name, description, is_default) } end |
#http_proxy ⇒ Object
Current http proxy URI. Usually nil.
50 51 52 |
# File 'lib/cfoundry/v1/client.rb', line 50 def http_proxy @base.http_proxy end |
#http_proxy=(uri) ⇒ Object
Set the http proxy URI.
55 56 57 |
# File 'lib/cfoundry/v1/client.rb', line 55 def http_proxy=(uri) @base.http_proxy = uri end |
#https_proxy ⇒ Object
Current https proxy URI. Usually nil.
60 61 62 |
# File 'lib/cfoundry/v1/client.rb', line 60 def https_proxy @base.https_proxy end |
#https_proxy=(uri) ⇒ Object
Set the https proxy URI.
65 66 67 |
# File 'lib/cfoundry/v1/client.rb', line 65 def https_proxy=(uri) @base.https_proxy = uri end |
#info ⇒ Object
Retrieve target metadata.
112 113 114 |
# File 'lib/cfoundry/v1/client.rb', line 112 def info @base.info end |
#log ⇒ Object
The current log. See log=
.
81 82 83 |
# File 'lib/cfoundry/v1/client.rb', line 81 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.
91 92 93 |
# File 'lib/cfoundry/v1/client.rb', line 91 def log=(mode) @base.log = mode end |
#logged_in? ⇒ Boolean
Is an authentication token set on the client?
209 210 211 |
# File 'lib/cfoundry/v1/client.rb', line 209 def logged_in? !!@base.token end |
#logout ⇒ Object
Clear client token. No requests are made for this.
204 205 206 |
# File 'lib/cfoundry/v1/client.rb', line 204 def logout @base.token = nil end |
#proxy ⇒ Object
Current proxy user. Usually nil.
39 40 41 |
# File 'lib/cfoundry/v1/client.rb', line 39 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.
45 46 47 |
# File 'lib/cfoundry/v1/client.rb', line 45 def proxy=(email) @base.proxy = email end |
#register(email, password) ⇒ Object
Create a user on the target and return a User object representing them.
198 199 200 201 |
# File 'lib/cfoundry/v1/client.rb', line 198 def register(email, password) @base.create_user(:email => email, :password => password) user(email) end |
#runtime(name) ⇒ Object
163 164 165 |
# File 'lib/cfoundry/v1/client.rb', line 163 def runtime(name) Runtime.new(name) end |
#runtime_by_name(name) ⇒ Object
167 168 169 |
# File 'lib/cfoundry/v1/client.rb', line 167 def runtime_by_name(name) runtimes.find { |r| r.name == name } end |
#runtimes(options = {}) ⇒ Object
Retrieve available runtimes.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cfoundry/v1/client.rb', line 152 def runtimes( = {}) runtimes = [] @base.system_runtimes.each do |name, | runtimes << Runtime.new(name.to_s, [:version], [:debug_modes]) end runtimes end |
#services(options = {}) ⇒ Object
Retrieve available services.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cfoundry/v1/client.rb', line 117 def services( = {}) services = [] @base.system_services.each do |type, vendors| vendors.each do |vendor, providers| providers.each do |provider, properties| properties.each do |_, | [:supported_versions].each do |ver| state = [:version_aliases].find { |k, v| v == ver } services << Service.new(vendor.to_s, ver.to_s, [:description], type.to_s, provider.to_s, state && state.first, generate_plans()) end end end end end services end |
#target ⇒ Object
The current target URL of the client.
24 25 26 |
# File 'lib/cfoundry/v1/client.rb', line 24 def target @base.target end |
#token ⇒ Object
Current authentication token.
29 30 31 |
# File 'lib/cfoundry/v1/client.rb', line 29 def token @base.token end |
#token=(token) ⇒ Object
Set the authentication token.
34 35 36 |
# File 'lib/cfoundry/v1/client.rb', line 34 def token=(token) @base.token = token end |
#trace ⇒ Object
Is the client tracing API requests?
70 71 72 |
# File 'lib/cfoundry/v1/client.rb', line 70 def trace @base.trace end |
#trace=(bool) ⇒ Object
Set the tracing flag; if true, API requests and responses will be printed out.
76 77 78 |
# File 'lib/cfoundry/v1/client.rb', line 76 def trace=(bool) @base.trace = bool end |
#version ⇒ Object
19 20 21 |
# File 'lib/cfoundry/v1/client.rb', line 19 def version 1 end |