Class: CFoundry::V2::Base

Inherits:
BaseClient show all
Defined in:
lib/cfoundry/v2/base.rb

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#no_backtrace

Instance Method Summary collapse

Methods inherited from BaseClient

#request_path, #token_data

Constructor Details

#initialize(target = "https://api.cloudfoundry.com", token = nil) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
# File 'lib/cfoundry/v2/base.rb', line 13

def initialize(
    target = "https://api.cloudfoundry.com",
    token = nil)
  @target = target
  @token = token
end

Instance Attribute Details

#proxyObject

Returns the value of attribute proxy.



11
12
13
# File 'lib/cfoundry/v2/base.rb', line 11

def proxy
  @proxy
end

#targetObject

Returns the value of attribute target.



11
12
13
# File 'lib/cfoundry/v2/base.rb', line 11

def target
  @target
end

#tokenObject

Returns the value of attribute token.



11
12
13
# File 'lib/cfoundry/v2/base.rb', line 11

def token
  @token
end

#traceObject

Returns the value of attribute trace.



11
12
13
# File 'lib/cfoundry/v2/base.rb', line 11

def trace
  @trace
end

Instance Method Details

#files(guid, instance, *path) ⇒ Object Also known as: file



103
104
105
# File 'lib/cfoundry/v2/base.rb', line 103

def files(guid, instance, *path)
  get("v2", "apps", guid, "instances", instance, "files", *path)
end

#infoObject

Cloud metadata



44
45
46
# File 'lib/cfoundry/v2/base.rb', line 44

def info
  get("info", nil => :json)
end

#instances(guid) ⇒ Object



108
109
110
# File 'lib/cfoundry/v2/base.rb', line 108

def instances(guid)
  get("v2", "apps", guid, "instances", nil => :json)
end

#params_from(args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/cfoundry/v2/base.rb', line 117

def params_from(args)
  depth, query = args
  depth ||= 1

  params = { :"inline-relations-depth" => depth }

  if query
    params[:q] = "#{query.keys.first}:#{query.values.first}"
  end

  params
end

#resource_match(fingerprints) ⇒ Object



82
83
84
# File 'lib/cfoundry/v2/base.rb', line 82

def resource_match(fingerprints)
  put(fingerprints, "v2", "resource_match", :json => :json)
end

#stats(guid) ⇒ Object



112
113
114
# File 'lib/cfoundry/v2/base.rb', line 112

def stats(guid)
  get("v2", "apps", guid, "stats", nil => :json)
end

#uaaObject

The UAA used for this client.

‘false` if no UAA (legacy)



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cfoundry/v2/base.rb', line 30

def uaa
  return @uaa unless @uaa.nil?

  endpoint = info[:authorization_endpoint]
  return @uaa = false unless endpoint

  @uaa = CFoundry::UAAClient.new(endpoint)
  @uaa.trace = @trace
  @uaa.token = @token
  @uaa
end

#upload_app(guid, zipfile, resources = []) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cfoundry/v2/base.rb', line 86

def upload_app(guid, zipfile, resources = [])
  payload = {
    :resources => MultiJson.dump(resources),
    :multipart => true,
    :application =>
      if zipfile.is_a? File
        zipfile
      elsif zipfile.is_a? String
        File.new(zipfile, "rb")
      end
  }

  put(payload, "v2", "apps", guid, "bits")
rescue RestClient::ServerBrokeConnection
  retry
end