Class: JFoundry::V2::Client
- Inherits:
-
Object
- Object
- JFoundry::V2::Client
- Extended by:
- Forwardable
- Includes:
- ClientMethods
- Defined in:
- lib/jfoundry/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, access_key, secret_key, version) ⇒ Client
constructor
Create a new Client for interfacing with the given target.
- #make_service_instance(json) ⇒ Object
- #query_target(klass) ⇒ Object
- #service_instances(opts = {}) ⇒ Object
- #service_instances_from(path, *args) ⇒ Object
- #stream_url(url, &blk) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(target, access_key, secret_key, version) ⇒ 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/jfoundry/v2/client.rb', line 27 def initialize(target, access_key, secret_key, version) @base = Base.new(target, access_key, secret_key, version) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Internal BaseClient instance. Normally won’t be touching this.
12 13 14 |
# File 'lib/jfoundry/v2/client.rb', line 12 def base @base end |
#current_organization ⇒ Object
- Organization
-
Currently targeted organization.
15 16 17 |
# File 'lib/jfoundry/v2/client.rb', line 15 def current_organization @current_organization end |
#current_space ⇒ Object
- Space
-
Currently targeted space.
18 19 20 |
# File 'lib/jfoundry/v2/client.rb', line 18 def current_space @current_space end |
Instance Method Details
#current_user ⇒ Object
The currently authenticated user.
36 37 38 39 40 41 42 43 |
# File 'lib/jfoundry/v2/client.rb', line 36 def current_user user = user(@base.access_key) user_info = @base.user_info if user_info && user_info.key?(:user) user.emails = [{ :value => user_info[:user]}] end user end |
#make_service_instance(json) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/jfoundry/v2/client.rb', line 70 def make_service_instance(json) klass = "JFoundry::V2::#{json[:entity][:type].camelize}".constantize klass.new( json[:metadata][:guid], self, json) end |
#query_target(klass) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/jfoundry/v2/client.rb', line 45 def query_target(klass) if klass.scoped_space && space = current_space space elsif klass.scoped_organization && org = current_organization org else self end end |
#service_instances(opts = {}) ⇒ Object
59 60 61 62 |
# File 'lib/jfoundry/v2/client.rb', line 59 def service_instances(opts={}) opts[:user_provided] = true super(opts) end |
#service_instances_from(path, *args) ⇒ Object
64 65 66 67 68 |
# File 'lib/jfoundry/v2/client.rb', line 64 def service_instances_from(path, *args) opts = args.first || {} opts[:user_provided] = true super(path, opts, *args) end |
#stream_url(url, &blk) ⇒ Object
55 56 57 |
# File 'lib/jfoundry/v2/client.rb', line 55 def stream_url(url, &blk) @base.stream_url(url, &blk) end |
#version ⇒ Object
31 32 33 |
# File 'lib/jfoundry/v2/client.rb', line 31 def version 2 end |