Class: Heroku::Client
- Inherits:
-
Object
show all
- Extended by:
- Helpers
- Includes:
- Helpers
- Defined in:
- lib/heroku/client.rb,
lib/heroku/client/ssl_endpoint.rb
Overview
A Ruby class to call the Heroku REST API. You might use this if you want to manage your Heroku apps from within a Ruby program, such as Capistrano.
Example:
require 'heroku'
heroku = Heroku::Client.new('[email protected]', 'mypass')
heroku.create()
Defined Under Namespace
Modules: JSON
Classes: AppCrashed, Cisaurus, ConsoleSession, HerokuPostgresql, Pgbackups, Rendezvous, Service
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_collaborator(app_name, email) ⇒ Object
Invite a person by email address to collaborate on the app.
-
#add_config_vars(app_name, new_vars) ⇒ Object
-
#add_domain(app_name, domain) ⇒ Object
-
#add_drain(app_name, url) ⇒ Object
-
#add_key(key) ⇒ Object
Add an ssh public key to the current user.
-
#add_ssl(app_name, pem, key) ⇒ Object
-
#addons(filters = {}) ⇒ Object
-
#clear_config_vars(app_name) ⇒ Object
-
#clear_ssl(app_name) ⇒ Object
-
#config_vars(app_name) ⇒ Object
-
#confirm_billing ⇒ Object
-
#console(app_name, cmd = nil) ⇒ Object
Execute a one-off console command, or start a new console tty session if cmd is nil.
-
#create(name = nil, options = {}) ⇒ Object
Create a new app, with an optional name.
-
#create_app(name = nil, options = {}) ⇒ Object
-
#create_complete?(name) ⇒ Boolean
-
#create_request(name = nil, options = {}) ⇒ Object
-
#database_reset(app_name) ⇒ Object
-
#database_session(app_name) ⇒ Object
-
#delete(uri, extra_headers = {}) ⇒ Object
-
#deprecate ⇒ Object
-
#destroy(name) ⇒ Object
Destroy the app permanently.
-
#disable_feature(app, name) ⇒ Object
-
#dynos(app_name) ⇒ Object
-
#enable_feature(app, name) ⇒ Object
-
#escape(value) ⇒ Object
-
#extract_warning(response) ⇒ Object
-
#get(uri, extra_headers = {}) ⇒ Object
-
#get_feature(app, name) ⇒ Object
-
#heroku_headers ⇒ Object
-
#httpcache_purge(app_name) ⇒ Object
-
#info(name_or_domain) ⇒ Object
Show info such as mode, custom domain, and collaborators on an app.
-
#initialize(user, password, host = Heroku::Auth.host) ⇒ Client
constructor
A new instance of Client.
-
#install_addon(app_name, addon, config = {}) ⇒ Object
-
#installed_addons(app_name) ⇒ Object
-
#keys ⇒ Object
Get the list of ssh public keys for the current user.
-
#list ⇒ Object
Show a list of apps which you are a collaborator on.
-
#list_collaborators(app_name) ⇒ Object
Get a list of collaborators on the app, returns an array of hashes each with :email.
-
#list_domains(app_name) ⇒ Object
-
#list_drains(app_name) ⇒ Object
-
#list_features(app) ⇒ Object
-
#list_stacks(app_name, options = {}) ⇒ Object
Get a list of stacks available to the app, with the current one marked.
-
#logs(app_name) ⇒ Object
Fetch recent logs from the app server.
-
#maintenance(app_name, mode) ⇒ Object
-
#migrate_to_stack(app_name, stack) ⇒ Object
Request a stack migration.
-
#on_warning(&blk) ⇒ Object
-
#post(uri, payload = "", extra_headers = {}) ⇒ Object
-
#process(method, uri, extra_headers = {}, payload = nil) ⇒ Object
-
#ps(app_name) ⇒ Object
Retreive ps list for the given app name.
-
#ps_restart(app, opts = {}) ⇒ Object
-
#ps_run(app, opts = {}) ⇒ Object
-
#ps_scale(app, opts = {}) ⇒ Object
-
#ps_stop(app, opts = {}) ⇒ Object
-
#put(uri, payload, extra_headers = {}) ⇒ Object
-
#rake(app_name, cmd) ⇒ Object
Run a rake command on the Heroku app and return output as a string.
-
#read_logs(app_name, options = []) ⇒ Object
-
#release(app, release) ⇒ Object
-
#releases(app) ⇒ Object
-
#remove_all_keys ⇒ Object
Clear all keys on the current user.
-
#remove_collaborator(app_name, email) ⇒ Object
-
#remove_config_var(app_name, key) ⇒ Object
-
#remove_domain(app_name, domain) ⇒ Object
-
#remove_domains(app_name) ⇒ Object
-
#remove_drain(app_name, url) ⇒ Object
-
#remove_key(key) ⇒ Object
Remove an existing ssh public key from the current user.
-
#remove_ssl(app_name, domain) ⇒ Object
-
#resource(uri, options = {}) ⇒ Object
-
#restart(app_name) ⇒ Object
-
#rollback(app, release = nil) ⇒ Object
-
#run_console_command(url, command, prefix = nil) ⇒ Object
internal method to run console commands formatting the output.
-
#set_dynos(app_name, qty) ⇒ Object
-
#set_workers(app_name, qty) ⇒ Object
Scales the background dynos.
-
#ssl_endpoint_add(app, pem, key) ⇒ Object
-
#ssl_endpoint_info(app, cname) ⇒ Object
-
#ssl_endpoint_list(app) ⇒ Object
-
#ssl_endpoint_remove(app, cname) ⇒ Object
-
#ssl_endpoint_rollback(app, cname) ⇒ Object
-
#ssl_endpoint_update(app, cname, pem, key) ⇒ Object
-
#start(app_name, command, attached = false) ⇒ Object
-
#uninstall_addon(app_name, addon, options = {}) ⇒ Object
-
#update(name, attributes) ⇒ Object
-
#upgrade_addon(app_name, addon, config = {}) ⇒ Object
(also: #downgrade_addon)
-
#workers(app_name) ⇒ Object
-
#xml(raw) ⇒ Object
Methods included from Helpers
action, ask, confirm, confirm_command, create_git_remote, display, display_header, display_object, display_row, display_table, error, error_with_failure, error_with_failure=, extended, extended_into, fail, format_bytes, format_date, format_error, format_with_bang, get_terminal_environment, git, has_git?, home_directory, host_name, hprint, hputs, included, included_into, json_decode, json_encode, launchy, line_formatter, longest, output_with_bang, quantify, redisplay, retry_on_exception, run_command, running_on_a_mac?, running_on_windows?, set_buffer, shell, spinner, status, string_distance, styled_array, styled_error, styled_hash, styled_header, suggestion, time_ago, truncate, with_tty
Constructor Details
#initialize(user, password, host = Heroku::Auth.host) ⇒ Client
Returns a new instance of Client.
34
35
36
37
38
39
|
# File 'lib/heroku/client.rb', line 34
def initialize(user, password, host=Heroku::Auth.host)
require 'rest_client'
@user = user
@password = password
@host = host
end
|
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
32
33
34
|
# File 'lib/heroku/client.rb', line 32
def host
@host
end
|
#password ⇒ Object
Returns the value of attribute password.
32
33
34
|
# File 'lib/heroku/client.rb', line 32
def password
@password
end
|
#user ⇒ Object
Returns the value of attribute user.
32
33
34
|
# File 'lib/heroku/client.rb', line 32
def user
@user
end
|
Class Method Details
.auth(user, password, host = Heroku::Auth.host) ⇒ Object
53
54
55
56
57
|
# File 'lib/heroku/client.rb', line 53
def self.auth(user, password, host=Heroku::Auth.host)
deprecate client = new(user, password, host)
json_decode client.post('/login', { :username => user, :password => password }, :accept => 'json').to_s
end
|
.deprecate ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/heroku/client.rb', line 41
def self.deprecate
method = caller.first.split('`').last[0...-1]
source = caller[1].split(' ').first[0...-3]
$stderr.puts(" ! DEPRECATED: Heroku::Client##{method} is deprecated, please use the heroku-api gem.")
$stderr.puts(" ! DEPRECATED: More information available at https://github.com/heroku/heroku.rb")
$stderr.puts(" ! DEPRECATED: Deprecated method called from #{source}.")
end
|
.gem_version_string ⇒ Object
28
29
30
|
# File 'lib/heroku/client.rb', line 28
def self.gem_version_string
"heroku-gem/#{version}"
end
|
.version ⇒ Object
24
25
26
|
# File 'lib/heroku/client.rb', line 24
def self.version
Heroku::VERSION
end
|
Instance Method Details
#add_collaborator(app_name, email) ⇒ Object
Invite a person by email address to collaborate on the app.
158
159
160
161
|
# File 'lib/heroku/client.rb', line 158
def add_collaborator(app_name, email)
deprecate xml(post("/apps/#{escape app_name}/collaborators", { 'collaborator[email]' => email }).to_s)
end
|
#add_config_vars(app_name, new_vars) ⇒ Object
133
134
135
136
|
# File 'lib/heroku/client.rb', line 133
def add_config_vars(app_name, new_vars)
deprecate put("/apps/#{escape app_name}/config_vars", json_encode(new_vars), :accept => :json).to_s
end
|
#add_domain(app_name, domain) ⇒ Object
185
186
187
188
|
# File 'lib/heroku/client.rb', line 185
def add_domain(app_name, domain)
deprecate post("/apps/#{escape app_name}/domains", domain).to_s
end
|
#add_drain(app_name, url) ⇒ Object
542
543
544
|
# File 'lib/heroku/client.rb', line 542
def add_drain(app_name, url)
post("/apps/#{escape app_name}/logs/drains", "url=#{url}").to_s
end
|
#add_key(key) ⇒ Object
Add an ssh public key to the current user.
211
212
213
214
|
# File 'lib/heroku/client.rb', line 211
def add_key(key)
deprecate post("/user/keys", key, { 'Content-Type' => 'text/ssh-authkey' }).to_s
end
|
#add_ssl(app_name, pem, key) ⇒ Object
421
422
423
|
# File 'lib/heroku/client.rb', line 421
def add_ssl(app_name, pem, key)
json_decode(post("/apps/#{escape app_name}/ssl", :pem => pem, :key => key).to_s)
end
|
#addons(filters = {}) ⇒ Object
550
551
552
553
554
555
|
# File 'lib/heroku/client.rb', line 550
def addons(filters = {})
url = "/addons"
params = filters.map{|k,v| "#{k}=#{v}"}.join("&")
params = nil if params.empty?
json_decode get([url,params].compact.join("?"), :accept => 'application/json').to_s
end
|
#clear_config_vars(app_name) ⇒ Object
143
144
145
146
|
# File 'lib/heroku/client.rb', line 143
def clear_config_vars(app_name)
deprecate delete("/apps/#{escape app_name}/config_vars").to_s
end
|
#clear_ssl(app_name) ⇒ Object
429
430
431
|
# File 'lib/heroku/client.rb', line 429
def clear_ssl(app_name)
delete("/apps/#{escape app_name}/ssl")
end
|
#config_vars(app_name) ⇒ Object
128
129
130
131
|
# File 'lib/heroku/client.rb', line 128
def config_vars(app_name)
deprecate json_decode get("/apps/#{escape app_name}/config_vars", :accept => :json).to_s
end
|
#confirm_billing ⇒ Object
586
587
588
|
# File 'lib/heroku/client.rb', line 586
def confirm_billing
post("/user/#{escape(@user)}/confirm_billing").to_s
end
|
#console(app_name, cmd = nil) ⇒ Object
Execute a one-off console command, or start a new console tty session if cmd is nil.
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
# File 'lib/heroku/client.rb', line 448
def console(app_name, cmd=nil)
if block_given?
id = post("/apps/#{escape app_name}/consoles").to_s
yield ConsoleSession.new(id, app_name, self)
delete("/apps/#{escape app_name}/consoles/#{id}").to_s
else
run_console_command("/apps/#{escape app_name}/console", cmd)
end
rescue RestClient::BadGateway => e
raise(AppCrashed, <<-ERROR)
Unable to attach to a dyno to open a console session.
Your application may have crashed.
Check the output of "heroku ps" and "heroku logs" for more information.
ERROR
end
|
#create(name = nil, options = {}) ⇒ Object
Create a new app, with an optional name.
82
83
84
85
86
87
88
89
90
|
# File 'lib/heroku/client.rb', line 82
def create(name=nil, options={})
deprecate name = create_request(name, options)
loop do
break if create_complete?(name)
sleep 1
end
name
end
|
#create_app(name = nil, options = {}) ⇒ Object
92
93
94
95
96
|
# File 'lib/heroku/client.rb', line 92
def create_app(name=nil, options={})
deprecate options[:name] = name if name
json_decode(post("/apps", { :app => options }, :accept => "application/json").to_s)
end
|
#create_complete?(name) ⇒ Boolean
104
105
106
107
|
# File 'lib/heroku/client.rb', line 104
def create_complete?(name)
deprecate put("/apps/#{name}/status", {}).code == 201
end
|
#create_request(name = nil, options = {}) ⇒ Object
98
99
100
101
102
|
# File 'lib/heroku/client.rb', line 98
def create_request(name=nil, options={})
deprecate options[:name] = name if name
xml(post('/apps', :app => options).to_s).elements["//app/name"].text
end
|
#database_reset(app_name) ⇒ Object
578
579
580
|
# File 'lib/heroku/client.rb', line 578
def database_reset(app_name)
post("/apps/#{escape app_name}/database/reset", '').to_s
end
|
#database_session(app_name) ⇒ Object
574
575
576
|
# File 'lib/heroku/client.rb', line 574
def database_session(app_name)
json_decode(post("/apps/#{escape app_name}/database/session2", '', :x_taps_version => ::Taps.version).to_s)
end
|
#delete(uri, extra_headers = {}) ⇒ Object
618
619
620
|
# File 'lib/heroku/client.rb', line 618
def delete(uri, ={}) process(:delete, uri, )
end
|
#deprecate ⇒ Object
49
50
51
|
# File 'lib/heroku/client.rb', line 49
def deprecate
self.class.deprecate
end
|
#destroy(name) ⇒ Object
Destroy the app permanently.
117
118
119
120
|
# File 'lib/heroku/client.rb', line 117
def destroy(name)
deprecate delete("/apps/#{name}").to_s
end
|
#disable_feature(app, name) ⇒ Object
320
321
322
323
|
# File 'lib/heroku/client.rb', line 320
def disable_feature(app, name)
deprecate json_decode delete("/features/#{name}?app=#{app}", :accept => :json).to_s
end
|
#dynos(app_name) ⇒ Object
240
241
242
243
244
|
# File 'lib/heroku/client.rb', line 240
def dynos(app_name)
deprecate doc = xml(get("/apps/#{escape app_name}").to_s)
doc.elements["//app/dynos"].text.to_i
end
|
#enable_feature(app, name) ⇒ Object
315
316
317
318
|
# File 'lib/heroku/client.rb', line 315
def enable_feature(app, name)
deprecate json_decode post("/features/#{name}?app=#{app}", :accept => :json).to_s
end
|
#escape(value) ⇒ Object
667
668
669
670
|
# File 'lib/heroku/client.rb', line 667
def escape(value) escaped = URI.escape(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
escaped.gsub('.', '%2E') end
|
642
643
644
645
646
647
648
649
650
651
652
|
# File 'lib/heroku/client.rb', line 642
def (response)
return unless response
if response.[:x_heroku_warning] && @warning_callback
warning = response.[:x_heroku_warning]
@displayed_warnings ||= {}
unless @displayed_warnings[warning]
@warning_callback.call(warning)
@displayed_warnings[warning] = true
end
end
end
|
#get(uri, extra_headers = {}) ⇒ Object
606
607
608
|
# File 'lib/heroku/client.rb', line 606
def get(uri, ={}) process(:get, uri, )
end
|
#get_feature(app, name) ⇒ Object
310
311
312
313
|
# File 'lib/heroku/client.rb', line 310
def get_feature(app, name)
deprecate json_decode get("features/#{name}?app=#{app}", :accept => :json).to_s
end
|
654
655
656
657
658
659
660
661
|
# File 'lib/heroku/client.rb', line 654
def {
'X-Heroku-API-Version' => '2',
'User-Agent' => Heroku.user_agent,
'X-Ruby-Version' => RUBY_VERSION,
'X-Ruby-Platform' => RUBY_PLATFORM
}
end
|
#httpcache_purge(app_name) ⇒ Object
582
583
584
|
# File 'lib/heroku/client.rb', line 582
def httpcache_purge(app_name)
delete("/apps/#{escape app_name}/httpcache").to_s
end
|
#info(name_or_domain) ⇒ Object
Show info such as mode, custom domain, and collaborators on an app.
71
72
73
74
75
76
77
78
79
|
# File 'lib/heroku/client.rb', line 71
def info(name_or_domain)
deprecate raise ArgumentError.new("name_or_domain is required for info") unless name_or_domain
name_or_domain = name_or_domain.gsub(/^(http:\/\/)?(www\.)?/, '')
doc = xml(get("/apps/#{name_or_domain}").to_s)
attrs = hash_from_xml_doc(doc)[:app]
attrs.merge!(:collaborators => list_collaborators(attrs[:name]))
attrs.merge!(:addons => installed_addons(attrs[:name]))
end
|
#install_addon(app_name, addon, config = {}) ⇒ Object
561
562
563
|
# File 'lib/heroku/client.rb', line 561
def install_addon(app_name, addon, config={})
configure_addon :install, app_name, addon, config
end
|
#installed_addons(app_name) ⇒ Object
557
558
559
|
# File 'lib/heroku/client.rb', line 557
def installed_addons(app_name)
json_decode get("/apps/#{escape app_name}/addons", :accept => 'application/json').to_s
end
|
#keys ⇒ Object
Get the list of ssh public keys for the current user.
202
203
204
205
206
207
208
|
# File 'lib/heroku/client.rb', line 202
def keys
deprecate doc = xml get('/user/keys').to_s
doc.elements.to_a('//keys/key').map do |key|
key.elements['contents'].text
end
end
|
#list ⇒ Object
Show a list of apps which you are a collaborator on.
60
61
62
63
64
65
66
67
68
|
# File 'lib/heroku/client.rb', line 60
def list
deprecate doc = xml(get('/apps').to_s)
doc.elements.to_a("//apps/app").map do |a|
name = a.elements.to_a("name").first
owner = a.elements.to_a("owner").first
[name.text, owner.text]
end
end
|
#list_collaborators(app_name) ⇒ Object
Get a list of collaborators on the app, returns an array of hashes each with :email
149
150
151
152
153
154
155
|
# File 'lib/heroku/client.rb', line 149
def list_collaborators(app_name)
deprecate doc = xml(get("/apps/#{escape app_name}/collaborators").to_s)
doc.elements.to_a("//collaborators/collaborator").map do |a|
{ :email => a.elements['email'].text }
end
end
|
#list_domains(app_name) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/heroku/client.rb', line 169
def list_domains(app_name)
deprecate doc = xml(get("/apps/#{escape app_name}/domains").to_s)
doc.elements.to_a("//domain-names/*").map do |d|
attrs = { :domain => d.elements['domain'].text }
if cert = d.elements['cert']
attrs[:cert] = {
:expires_at => Time.parse(cert.elements['expires-at'].text),
:subject => cert.elements['subject'].text,
:issuer => cert.elements['issuer'].text,
}
end
attrs
end
end
|
#list_drains(app_name) ⇒ Object
538
539
540
|
# File 'lib/heroku/client.rb', line 538
def list_drains(app_name)
get("/apps/#{escape app_name}/logs/drains").to_s
end
|
#list_features(app) ⇒ Object
305
306
307
308
|
# File 'lib/heroku/client.rb', line 305
def list_features(app)
deprecate json_decode(get("features?app=#{app}", :accept => :json).to_s)
end
|
#list_stacks(app_name, options = {}) ⇒ Object
Get a list of stacks available to the app, with the current one marked.
326
327
328
329
330
331
332
333
334
|
# File 'lib/heroku/client.rb', line 326
def list_stacks(app_name, options={})
deprecate include_deprecated = options.delete(:include_deprecated) || false
json_decode get("/apps/#{escape app_name}/stack",
:params => { :include_deprecated => include_deprecated },
:accept => 'application/json'
).to_s
end
|
#logs(app_name) ⇒ Object
Fetch recent logs from the app server.
300
301
302
303
|
# File 'lib/heroku/client.rb', line 300
def logs(app_name)
deprecate get("/apps/#{escape app_name}/logs").to_s
end
|
#maintenance(app_name, mode) ⇒ Object
122
123
124
125
126
|
# File 'lib/heroku/client.rb', line 122
def maintenance(app_name, mode)
deprecate mode = mode == :on ? '1' : '0'
post("/apps/#{escape app_name}/server/maintenance", :maintenance_mode => mode).to_s
end
|
#migrate_to_stack(app_name, stack) ⇒ Object
Request a stack migration.
337
338
339
340
|
# File 'lib/heroku/client.rb', line 337
def migrate_to_stack(app_name, stack)
deprecate put("/apps/#{escape app_name}/stack", stack, :accept => 'text/plain').to_s
end
|
#on_warning(&blk) ⇒ Object
590
591
592
|
# File 'lib/heroku/client.rb', line 590
def on_warning(&blk)
@warning_callback = blk
end
|
#post(uri, payload = "", extra_headers = {}) ⇒ Object
610
611
612
|
# File 'lib/heroku/client.rb', line 610
def post(uri, payload="", ={}) process(:post, uri, , payload)
end
|
#process(method, uri, extra_headers = {}, payload = nil) ⇒ Object
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
# File 'lib/heroku/client.rb', line 622
def process(method, uri, ={}, payload=nil)
= .merge()
args = [method, payload, ].compact
resource_options = default_resource_options_for_uri(uri)
begin
response = resource(uri, resource_options).send(*args)
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
host = URI.parse(realize_full_uri(uri)).host
error "Unable to connect to #{host}"
rescue RestClient::SSLCertificateNotVerified => ex
host = URI.parse(realize_full_uri(uri)).host
error "WARNING: Unable to verify SSL certificate for #{host}\nTo disable SSL verification, run with HEROKU_SSL_VERIFY=disable"
end
(response)
response
end
|
#ps(app_name) ⇒ Object
Retreive ps list for the given app name.
229
230
231
232
|
# File 'lib/heroku/client.rb', line 229
def ps(app_name)
deprecate json_decode get("/apps/#{escape app_name}/ps", :accept => 'application/json').to_s
end
|
#ps_restart(app, opts = {}) ⇒ Object
274
275
276
277
|
# File 'lib/heroku/client.rb', line 274
def ps_restart(app, opts={})
deprecate post("/apps/#{app}/ps/restart", opts)
end
|
#ps_run(app, opts = {}) ⇒ Object
264
265
266
267
|
# File 'lib/heroku/client.rb', line 264
def ps_run(app, opts={})
deprecate json_decode post("/apps/#{app}/ps", opts, :accept => :json).to_s
end
|
#ps_scale(app, opts = {}) ⇒ Object
269
270
271
272
|
# File 'lib/heroku/client.rb', line 269
def ps_scale(app, opts={})
deprecate Integer(post("/apps/#{app}/ps/scale", opts).to_s)
end
|
#ps_stop(app, opts = {}) ⇒ Object
279
280
281
282
|
# File 'lib/heroku/client.rb', line 279
def ps_stop(app, opts={})
deprecate post("/apps/#{app}/ps/stop", opts)
end
|
#put(uri, payload, extra_headers = {}) ⇒ Object
614
615
616
|
# File 'lib/heroku/client.rb', line 614
def put(uri, payload, ={}) process(:put, uri, , payload)
end
|
#rake(app_name, cmd) ⇒ Object
Run a rake command on the Heroku app and return output as a string
343
344
345
346
|
# File 'lib/heroku/client.rb', line 343
def rake(app_name, cmd)
start(app_name, "rake #{cmd}", :attached).to_s
end
|
#read_logs(app_name, options = []) ⇒ Object
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
# File 'lib/heroku/client.rb', line 482
def read_logs(app_name, options=[])
query = "&" + options.join("&") unless options.empty?
url = get("/apps/#{escape app_name}/logs?logplex=true#{query}").to_s
if url == 'Use old logs'
puts get("/apps/#{escape app_name}/logs").to_s
else
puts "getting new logs from #{url}"
uri = URI.parse(url);
if uri.scheme == 'https'
proxy = https_proxy
else
proxy = http_proxy
end
if proxy
proxy_uri = URI.parse(proxy)
http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
else
http = Net::HTTP.new(uri.host, uri.port)
end
if uri.scheme == 'https'
http.use_ssl = true
if ENV["HEROKU_SSL_VERIFY"] == "disable"
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
else
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = local_ca_file
http.verify_callback = lambda do |preverify_ok, ssl_context|
if (!preverify_ok) || ssl_context.error != 0
error "WARNING: Unable to verify SSL certificate for #{host}\nTo disable SSL verification, run with HEROKU_SSL_VERIFY=disable"
end
true
end
end
end
http.read_timeout = 60 * 60 * 24
begin
http.start do
http.request_get(uri.path + (uri.query ? "?" + uri.query : "")) do |request|
request.read_body do |chunk|
yield chunk
end
end
end
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, SocketError
error("Could not connect to logging service")
rescue Timeout::Error, EOFError
error("\nRequest timed out")
end
end
end
|
#release(app, release) ⇒ Object
289
290
291
292
|
# File 'lib/heroku/client.rb', line 289
def release(app, release)
deprecate json_decode get("/apps/#{app}/releases/#{release}", :accept => :json).to_s
end
|
#releases(app) ⇒ Object
284
285
286
287
|
# File 'lib/heroku/client.rb', line 284
def releases(app)
deprecate json_decode get("/apps/#{app}/releases", :accept => :json).to_s
end
|
#remove_all_keys ⇒ Object
Clear all keys on the current user.
223
224
225
226
|
# File 'lib/heroku/client.rb', line 223
def remove_all_keys
deprecate delete("/user/keys").to_s
end
|
#remove_collaborator(app_name, email) ⇒ Object
164
165
166
167
|
# File 'lib/heroku/client.rb', line 164
def remove_collaborator(app_name, email)
deprecate delete("/apps/#{escape app_name}/collaborators/#{escape(email)}").to_s
end
|
#remove_config_var(app_name, key) ⇒ Object
138
139
140
141
|
# File 'lib/heroku/client.rb', line 138
def remove_config_var(app_name, key)
deprecate delete("/apps/#{escape app_name}/config_vars/#{escape(key)}", :accept => :json).to_s
end
|
#remove_domain(app_name, domain) ⇒ Object
190
191
192
193
194
|
# File 'lib/heroku/client.rb', line 190
def remove_domain(app_name, domain)
deprecate raise ArgumentError.new("invalid domain: #{domain.inspect}") if domain.to_s.strip == ""
delete("/apps/#{escape app_name}/domains/#{domain}").to_s
end
|
#remove_domains(app_name) ⇒ Object
196
197
198
199
|
# File 'lib/heroku/client.rb', line 196
def remove_domains(app_name)
deprecate delete("/apps/#{escape app_name}/domains").to_s
end
|
#remove_drain(app_name, url) ⇒ Object
546
547
548
|
# File 'lib/heroku/client.rb', line 546
def remove_drain(app_name, url)
delete("/apps/#{escape app_name}/logs/drains?url=#{URI.escape(url)}").to_s
end
|
#remove_key(key) ⇒ Object
Remove an existing ssh public key from the current user.
217
218
219
220
|
# File 'lib/heroku/client.rb', line 217
def remove_key(key)
deprecate delete("/user/keys/#{escape(key)}").to_s
end
|
#remove_ssl(app_name, domain) ⇒ Object
425
426
427
|
# File 'lib/heroku/client.rb', line 425
def remove_ssl(app_name, domain)
delete("/apps/#{escape app_name}/domains/#{domain}/ssl").to_s
end
|
#resource(uri, options = {}) ⇒ Object
596
597
598
599
600
601
602
603
604
|
# File 'lib/heroku/client.rb', line 596
def resource(uri, options={})
RestClient.proxy = case URI.parse(realize_full_uri(uri)).scheme
when "http"
http_proxy
when "https"
https_proxy
end
RestClient::Resource.new(realize_full_uri(uri), options.merge(:user => user, :password => password))
end
|
#restart(app_name) ⇒ Object
235
236
237
238
|
# File 'lib/heroku/client.rb', line 235
def restart(app_name)
deprecate delete("/apps/#{escape app_name}/server").to_s
end
|
#rollback(app, release = nil) ⇒ Object
294
295
296
297
|
# File 'lib/heroku/client.rb', line 294
def rollback(app, release=nil)
deprecate post("/apps/#{app}/releases", :rollback => release)
end
|
#run_console_command(url, command, prefix = nil) ⇒ Object
internal method to run console commands formatting the output
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/heroku/client.rb', line 465
def run_console_command(url, command, prefix=nil)
output = post(url, { :command => command }, :accept => "text/plain").to_s
return output unless prefix
if output.include?("\n")
lines = output.split("\n")
(lines[0..-2] << "#{prefix}#{lines.last}").join("\n")
else
prefix + output
end
rescue RestClient::RequestFailed => e
if e.http_code == 422
Heroku::Command.(e.http_body, :raw => true)
else
raise e
end
end
|
#set_dynos(app_name, qty) ⇒ Object
253
254
255
256
|
# File 'lib/heroku/client.rb', line 253
def set_dynos(app_name, qty)
deprecate put("/apps/#{escape app_name}/dynos", :dynos => qty).to_s
end
|
#set_workers(app_name, qty) ⇒ Object
Scales the background dynos.
259
260
261
262
|
# File 'lib/heroku/client.rb', line 259
def set_workers(app_name, qty)
deprecate put("/apps/#{escape app_name}/workers", :workers => qty).to_s
end
|
#ssl_endpoint_add(app, pem, key) ⇒ Object
2
3
4
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 2
def ssl_endpoint_add(app, pem, key)
json_decode(post("apps/#{escape app}/ssl-endpoints", :accept => :json, :pem => pem, :key => key).to_s)
end
|
#ssl_endpoint_info(app, cname) ⇒ Object
6
7
8
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 6
def ssl_endpoint_info(app, cname)
json_decode(get("apps/#{escape app}/ssl-endpoints/#{escape(cname)}", :accept => :json).to_s)
end
|
#ssl_endpoint_list(app) ⇒ Object
10
11
12
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 10
def ssl_endpoint_list(app)
json_decode(get("apps/#{escape app}/ssl-endpoints", :accept => :json).to_s)
end
|
#ssl_endpoint_remove(app, cname) ⇒ Object
14
15
16
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 14
def ssl_endpoint_remove(app, cname)
json_decode(delete("apps/#{escape app}/ssl-endpoints/#{escape(cname)}", :accept => :json).to_s)
end
|
#ssl_endpoint_rollback(app, cname) ⇒ Object
18
19
20
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 18
def ssl_endpoint_rollback(app, cname)
json_decode(post("apps/#{escape app}/ssl-endpoints/#{escape(cname)}/rollback", :accept => :json).to_s)
end
|
#ssl_endpoint_update(app, cname, pem, key) ⇒ Object
22
23
24
|
# File 'lib/heroku/client/ssl_endpoint.rb', line 22
def ssl_endpoint_update(app, cname, pem, key)
json_decode(put("apps/#{escape app}/ssl-endpoints/#{escape(cname)}", :accept => :json, :pem => pem, :key => key).to_s)
end
|
#start(app_name, command, attached = false) ⇒ Object
Run a service. If Responds to #each and yields output as it’s received.
415
416
417
418
419
|
# File 'lib/heroku/client.rb', line 415
def start(app_name, command, attached=false)
deprecate service = Service.new(self, app_name)
service.start(command, attached)
end
|
#uninstall_addon(app_name, addon, options = {}) ⇒ Object
570
571
572
|
# File 'lib/heroku/client.rb', line 570
def uninstall_addon(app_name, addon, options={})
configure_addon :uninstall, app_name, addon, options
end
|
#update(name, attributes) ⇒ Object
Update an app. Available attributes:
:name => rename the app (changes http and git urls)
111
112
113
114
|
# File 'lib/heroku/client.rb', line 111
def update(name, attributes)
deprecate put("/apps/#{name}", :app => attributes).to_s
end
|
#upgrade_addon(app_name, addon, config = {}) ⇒ Object
Also known as:
downgrade_addon
565
566
567
|
# File 'lib/heroku/client.rb', line 565
def upgrade_addon(app_name, addon, config={})
configure_addon :upgrade, app_name, addon, config
end
|
#workers(app_name) ⇒ Object
246
247
248
249
250
|
# File 'lib/heroku/client.rb', line 246
def workers(app_name)
deprecate doc = xml(get("/apps/#{escape app_name}").to_s)
doc.elements["//app/workers"].text.to_i
end
|
#xml(raw) ⇒ Object
663
664
665
|
# File 'lib/heroku/client.rb', line 663
def xml(raw) REXML::Document.new(raw)
end
|