lib/cfoundry/v1/client.rb in cfoundry-0.4.21 vs lib/cfoundry/v1/client.rb in cfoundry-0.5.0
- old
+ new
@@ -1,21 +1,27 @@
+require File.expand_path("../../concerns/login_helpers", __FILE__)
+
module CFoundry::V1
# 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.
class Client
- include ClientMethods
+ include ClientMethods, CFoundry::LoginHelpers
attr_reader :base
# Create a new Client for interfacing with the given target.
#
# A token may also be provided to skip the login step.
def initialize(target = "http://api.cloudfoundry.com", token = nil)
@base = Base.new(target, token)
end
+ def version
+ 1
+ end
+
# The current target URL of the client.
def target
@base.target
end
@@ -158,38 +164,9 @@
# Create a user on the target and return a User object representing them.
def register(email, password)
@base.create_user(:email => email, :password => password)
user(email)
- end
-
- # Login prompts
- def login_prompts
- if @base.uaa
- @base.uaa.prompts
- else
- { :username => ["text", "Email"],
- :password => ["password", "Password"]
- }
- end
- end
-
- # Authenticate with the target. Sets the client token.
- #
- # Credentials is a hash, typically containing :username and :password
- # keys.
- #
- # The values in the hash should mirror the prompts given by
- # `login_prompts`.
- def login(credentials)
- @base.token =
- if @base.uaa
- @base.uaa.authorize(credentials)
- else
- @base.create_token(
- { :password => credentials[:password] },
- credentials[:username])[:token]
- end
end
# Clear client token. No requests are made for this.
def logout
@base.token = nil