Class: CFoundry::Client
- Inherits:
-
Object
- Object
- CFoundry::Client
- Defined in:
- lib/cfoundry/client.rb
Overview
The primary API entrypoint. Wraps RESTClient 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
-
#rest ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#app(name) ⇒ Object
Construct an App object.
-
#apps ⇒ Object
Retreive all of the current user’s applications.
-
#info ⇒ Object
Retrieve target metadata.
-
#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(email, password) ⇒ Object
Authenticate with the target.
-
#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.
-
#service(name) ⇒ Object
Construct a Service object.
-
#services ⇒ Object
Retrieve all of the current user’s services.
-
#system_runtimes ⇒ Object
Retrieve available runtimes.
-
#system_services ⇒ Object
Retrieve available services.
-
#target ⇒ Object
The current target URL of the client.
-
#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.
-
#user(email) ⇒ Object
Construct a User object.
-
#users ⇒ Object
Retrieve user list.
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.
17 18 19 |
# File 'lib/cfoundry/client.rb', line 17 def initialize(target = "http://api.cloudfoundry.com", token = nil) @rest = RESTClient.new(*args) end |
Instance Attribute Details
#rest ⇒ Object (readonly)
:nodoc:
12 13 14 |
# File 'lib/cfoundry/client.rb', line 12 def rest @rest end |
Instance Method Details
#app(name) ⇒ Object
Construct an App object. The return value is lazy, and no requests are made from this method alone.
This should be used for both app creation (after calling App#create!) and retrieval.
133 134 135 |
# File 'lib/cfoundry/client.rb', line 133 def app(name) CFoundry::App.new(name, self) end |
#apps ⇒ Object
Retreive all of the current user’s applications.
122 123 124 125 126 |
# File 'lib/cfoundry/client.rb', line 122 def apps @rest.apps.collect do |json| CFoundry::App.new(json["name"], self, json) end end |
#info ⇒ Object
Retrieve target metadata.
50 51 52 |
# File 'lib/cfoundry/client.rb', line 50 def info @rest.info end |
#logged_in? ⇒ Boolean
Is an authentication token set on the client?
116 117 118 |
# File 'lib/cfoundry/client.rb', line 116 def logged_in? !!@rest.token end |
#login(email, password) ⇒ Object
Authenticate with the target. Sets the client token.
105 106 107 108 |
# File 'lib/cfoundry/client.rb', line 105 def login(email, password) @rest.token = @rest.create_token({ :password => password }, email)["token"] end |
#logout ⇒ Object
Clear client token. No requests are made for this.
111 112 113 |
# File 'lib/cfoundry/client.rb', line 111 def logout @rest.token = nil end |
#proxy ⇒ Object
Current proxy user. Usually nil.
27 28 29 |
# File 'lib/cfoundry/client.rb', line 27 def proxy @rest.proxy end |
#proxy=(email) ⇒ Object
Set the proxy user for the client. Must be authorized as an administrator for this to have any effect.
33 34 35 |
# File 'lib/cfoundry/client.rb', line 33 def proxy=(email) @rest.proxy = email end |
#register(email, password) ⇒ Object
Create a user on the target and return a User object representing them.
99 100 101 102 |
# File 'lib/cfoundry/client.rb', line 99 def register(email, password) @rest.create_user(:email => email, :password => password) user(email) end |
#service(name) ⇒ Object
Construct a Service object. The return value is lazy, and no requests are made from this method alone.
This should be used for both service creation (after calling Service#create!) and retrieval.
150 151 152 |
# File 'lib/cfoundry/client.rb', line 150 def service(name) CFoundry::Service.new(name, self) end |
#services ⇒ Object
Retrieve all of the current user’s services.
139 140 141 142 143 |
# File 'lib/cfoundry/client.rb', line 139 def services @rest.services.collect do |json| CFoundry::Service.new(json["name"], self, json) end end |
#system_runtimes ⇒ Object
Retrieve available runtimes.
73 74 75 |
# File 'lib/cfoundry/client.rb', line 73 def system_runtimes @rest.system_runtimes end |
#system_services ⇒ Object
Retrieve available services. Returned as a Hash from vendor => metadata.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cfoundry/client.rb', line 55 def system_services services = {} @rest.system_services.each do |type, vendors| vendors.each do |vendor, versions| services[vendor] = { :type => type, :versions => versions.keys, :description => versions.values[0]["description"], :vendor => vendor } end end services end |
#target ⇒ Object
The current target URL of the client.
22 23 24 |
# File 'lib/cfoundry/client.rb', line 22 def target @rest.target end |
#trace ⇒ Object
Is the client tracing API requests?
38 39 40 |
# File 'lib/cfoundry/client.rb', line 38 def trace @rest.trace end |
#trace=(bool) ⇒ Object
Set the tracing flag; if true, API requests and responses will be printed out.
44 45 46 |
# File 'lib/cfoundry/client.rb', line 44 def trace=(bool) @rest.trace = bool end |
#user(email) ⇒ Object
Construct a User object. The return value is lazy, and no requests are made from this alone.
This should be used for both user creation (after calling User#create!) and retrieval.
94 95 96 |
# File 'lib/cfoundry/client.rb', line 94 def user(email) CFoundry::User.new(email, self) end |