Class: CFoundry::V2::Base
- Inherits:
-
BaseClient
- Object
- BaseClient
- CFoundry::V2::Base
- Includes:
- BaseClientMethods
- Defined in:
- lib/cfoundry/v2/base.rb
Constant Summary
Constants inherited from BaseClient
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#log ⇒ Object
Returns the value of attribute log.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#target ⇒ Object
Returns the value of attribute target.
-
#token ⇒ Object
Returns the value of attribute token.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #all_pages(paginated) ⇒ Object
- #crashes(guid) ⇒ Object
- #files(guid, instance, *path) ⇒ Object (also: #file)
-
#info ⇒ Object
Cloud metadata.
-
#initialize(target = "https://api.cloudfoundry.com", token = nil) ⇒ Base
constructor
A new instance of Base.
- #instances(guid) ⇒ Object
- #resource_match(fingerprints) ⇒ Object
- #stats(guid) ⇒ Object
- #stream_file(guid, instance, *path) ⇒ Object
-
#uaa ⇒ Object
The UAA used for this client.
- #upload_app(guid, zipfile, resources = []) ⇒ Object
Methods inherited from BaseClient
#request, #request_path, #request_uri, #token_data
Constructor Details
#initialize(target = "https://api.cloudfoundry.com", token = nil) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 |
# File 'lib/cfoundry/v2/base.rb', line 14 def initialize( target = "https://api.cloudfoundry.com", token = nil) super end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def backtrace @backtrace end |
#log ⇒ Object
Returns the value of attribute log.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def log @log end |
#proxy ⇒ Object
Returns the value of attribute proxy.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def proxy @proxy end |
#target ⇒ Object
Returns the value of attribute target.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def target @target end |
#token ⇒ Object
Returns the value of attribute token.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def token @token end |
#trace ⇒ Object
Returns the value of attribute trace.
12 13 14 |
# File 'lib/cfoundry/v2/base.rb', line 12 def trace @trace end |
Instance Method Details
#all_pages(paginated) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cfoundry/v2/base.rb', line 108 def all_pages(paginated) payload = paginated[:resources] while next_page = paginated[:next_url] paginated = request_path(Net::HTTP::Get, next_page, :accept => :json) payload += paginated[:resources] end payload end |
#crashes(guid) ⇒ Object
99 100 101 |
# File 'lib/cfoundry/v2/base.rb', line 99 def crashes(guid) get("v2", "apps", guid, "crashes", :accept => :json) end |
#files(guid, instance, *path) ⇒ Object Also known as: file
65 66 67 |
# File 'lib/cfoundry/v2/base.rb', line 65 def files(guid, instance, *path) get("v2", "apps", guid, "instances", instance, "files", *path) end |
#info ⇒ Object
Cloud metadata
38 39 40 |
# File 'lib/cfoundry/v2/base.rb', line 38 def info get("info", :accept => :json) end |
#instances(guid) ⇒ Object
95 96 97 |
# File 'lib/cfoundry/v2/base.rb', line 95 def instances(guid) get("v2", "apps", guid, "instances", :accept => :json) end |
#resource_match(fingerprints) ⇒ Object
42 43 44 45 |
# File 'lib/cfoundry/v2/base.rb', line 42 def resource_match(fingerprints) put(fingerprints, "v2", "resource_match", :content => :json, :accept => :json) end |
#stats(guid) ⇒ Object
103 104 105 |
# File 'lib/cfoundry/v2/base.rb', line 103 def stats(guid) get("v2", "apps", guid, "stats", :accept => :json) end |
#stream_file(guid, instance, *path) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cfoundry/v2/base.rb', line 70 def stream_file(guid, instance, *path) redirect = ( Net::HTTP::Get, ["v2", "apps", guid, "instances", instance, "files", *path], :return_response => true) if loc = redirect["location"] uri = URI.parse(loc + "&tail") Net::HTTP.start(uri.host, uri.port) do |http| req = Net::HTTP::Get.new(uri.request_uri) req["Authorization"] = @token http.request(req) do |response| response.read_body do |chunk| yield chunk end end end else yield redirect.body end end |
#uaa ⇒ Object
The UAA used for this client.
‘false` if no UAA (legacy)
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cfoundry/v2/base.rb', line 24 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cfoundry/v2/base.rb', line 47 def upload_app(guid, zipfile, resources = []) payload = { :resources => MultiJson.dump(resources), :application => UploadIO.new( if zipfile.is_a? File zipfile elsif zipfile.is_a? String File.new(zipfile, "rb") end, "application/zip") } put(payload, "v2", "apps", guid, "bits") rescue EOFError retry end |