Class: CFoundry::V2::Base
Instance Attribute Summary
Attributes inherited from BaseClient
#rest_client
Instance Method Summary
collapse
Methods inherited from BaseClient
#delete, #get, #info, #initialize, #password_score, #post, #put, #refresh_token!, #request, #request_raw, #stream_url, #token=, #trace=, #uaa
#proxy_options_for
Instance Method Details
#all_pages(paginated) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/cfoundry/v2/base.rb', line 100
def all_pages(paginated)
payload = []
for_each(paginated) do |resource|
payload << resource
end
payload
end
|
#crashes(guid) ⇒ Object
76
77
78
|
# File 'lib/cfoundry/v2/base.rb', line 76
def crashes(guid)
get("v2", "apps", guid, "crashes", :accept => :json)
end
|
#files(guid, instance, *path) ⇒ Object
Also known as:
file
55
56
57
|
# File 'lib/cfoundry/v2/base.rb', line 55
def files(guid, instance, *path)
get("v2", "apps", guid, "instances", instance, "files", *path)
end
|
#for_each(paginated, &block) ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/cfoundry/v2/base.rb', line 91
def for_each(paginated, &block)
paginated[:resources].each &block
while (next_page = paginated[:next_url])
paginated = get(next_page, :accept => :json)
paginated[:resources].each &block
end
end
|
#instances(guid) ⇒ Object
72
73
74
|
# File 'lib/cfoundry/v2/base.rb', line 72
def instances(guid)
get("v2", "apps", guid, "instances", :accept => :json)
end
|
#poll_upload_until_finished(guid) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/cfoundry/v2/base.rb', line 43
def poll_upload_until_finished(guid)
while true
response = get("v2", "jobs", guid, :accept => :json)
break if response[:entity][:status] == "finished"
if response[:entity][:status] == "failed"
raise CFoundry::BadResponse
end
sleep 0.2
end
end
|
#resource_match(fingerprints) ⇒ Object
12
13
14
|
# File 'lib/cfoundry/v2/base.rb', line 12
def resource_match(fingerprints)
put("v2", "resource_match", :content => :json, :accept => :json, :payload => fingerprints)
end
|
#stats(guid) ⇒ Object
80
81
82
|
# File 'lib/cfoundry/v2/base.rb', line 80
def stats(guid)
get("v2", "apps", guid, "stats", :accept => :json)
end
|
#stream_file(guid, instance, *path, &blk) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/cfoundry/v2/base.rb', line 61
def stream_file(guid, instance, *path, &blk)
path_and_options = path + [{:return_response => true, :follow_redirects => false}]
redirect = get("v2", "apps", guid, "instances", instance, "files", *path_and_options)
if location = redirect[:headers]["location"]
stream_url(location + "&tail", &blk)
else
yield redirect[:body]
end
end
|
#update_app(guid, diff) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/cfoundry/v2/base.rb', line 84
def update_app(guid, diff)
put("v2", "apps", guid,
:content => :json,
:payload => diff,
:return_response => true)
end
|
#upload_app(guid, zipfile = nil, resources = []) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cfoundry/v2/base.rb', line 16
def upload_app(guid, zipfile = nil, resources = [])
payload = {}
payload[:resources] = MultiJson.dump(resources)
if zipfile
payload[:application] =
UploadIO.new(
if zipfile.is_a? File
zipfile
elsif zipfile.is_a? String
File.new(zipfile, "rb")
end,
"application/zip")
end
response = put("v2", "apps", guid, "bits",
:payload => payload,
:params => {"async" => "true"})
if response.present?
response_json = JSON.parse(response)
poll_upload_until_finished(response_json['metadata']['guid'])
end
rescue EOFError
retry
end
|