Class: JFoundry::V2::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#baseObject (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_organizationObject

Organization

Currently targeted organization.



15
16
17
# File 'lib/jfoundry/v2/client.rb', line 15

def current_organization
  @current_organization
end

#current_spaceObject

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_userObject

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)
     = @base.
    if  && .key?(:user)
        user.emails = [{ :value => [: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

#versionObject



31
32
33
# File 'lib/jfoundry/v2/client.rb', line 31

def version
  2
end