class Heroku::Client::HerokuPostgresql
Constants
- Version
Attributes
attachment[R]
Public Class Methods
add_headers(headers)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 10 def self.add_headers(headers) @headers.merge! headers end
headers()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 14 def self.headers @headers end
new(attachment)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 19 def initialize(attachment) @attachment = attachment end
Public Instance Methods
backups()
click to toggle source
backups
# File lib/heroku/client/heroku_postgresql.rb, line 118 def backups http_get "#{resource_name}/transfers" end
backups_capture()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 126 def backups_capture http_post "#{resource_name}/backups" end
backups_delete(id)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 134 def backups_delete(id) http_delete "#{resource_name}/backups/#{URI.encode(id)}" end
backups_get(id, verbose=false)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 122 def backups_get(id, verbose=false) http_get "#{resource_name}/transfers/#{URI.encode(id)}?verbose=#{verbose}" end
backups_restore(backup_url)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 130 def backups_restore(backup_url) http_post "#{resource_name}/restores", 'backup_url' => backup_url end
connection_reset()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 63 def connection_reset http_post "#{resource_name}/connection_reset" end
get_database(extended=false)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 71 def get_database(extended=false) query = extended ? '?extended=true' : '' http_get resource_name + query end
get_wait_status()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 76 def get_wait_status http_get "#{resource_name}/wait_status" end
heroku_postgresql_host()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 23 def heroku_postgresql_host if attachment.starter_plan? determine_host(ENV["HEROKU_POSTGRESQL_HOST"], "postgres-starter-api.heroku.com") else if ENV['SHOGUN'] "shogun-#{ENV['SHOGUN']}.herokuapp.com" else determine_host(ENV["HEROKU_POSTGRESQL_HOST"], "postgres-api.heroku.com") end end end
heroku_postgresql_resource()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 39 def heroku_postgresql_resource if ENV['HEROKU_HEADERS'] self.class.add_headers json_decode(ENV['HEROKU_HEADERS']) end RestClient::Resource.new( "https://#{heroku_postgresql_host}/client/v11/databases", :user => Heroku::Auth.user, :password => Heroku::Auth.password, :headers => self.class.headers ) end
ingress()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 51 def ingress http_put "#{resource_name}/ingress" end
link_delete(id)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 113 def link_delete(id) http_delete "#{resource_name}/links/#{id}" end
link_list()
click to toggle source
links
# File lib/heroku/client/heroku_postgresql.rb, line 105 def link_list http_get "#{resource_name}/links" end
link_set(target, as = nil)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 109 def link_set(target, as = nil) http_post "#{resource_name}/links", 'target' => target, 'as' => as end
maintenance_info()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 92 def maintenance_info http_get "#{resource_name}/maintenance" end
maintenance_run()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 96 def maintenance_run http_post "#{resource_name}/maintenance" end
maintenance_window_set(description)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 100 def maintenance_window_set(description) http_put "#{resource_name}/maintenance_window", 'description' => description end
metrics()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 55 def metrics http_get "#{resource_name}/metrics" end
pg_copy(source_name, source_url, target_name, target_url)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 138 def pg_copy(source_name, source_url, target_name, target_url) http_post "#{resource_name}/transfers", { 'from_name' => source_name, 'from_url' => source_url, 'to_name' => target_name, 'to_url' => target_url, } end
reset()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 59 def reset http_put "#{resource_name}/reset" end
resource_name()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 35 def resource_name attachment.resource_name end
rotate_credentials()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 67 def rotate_credentials http_post "#{resource_name}/credentials_rotation" end
schedule(opts={})
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 151 def schedule(opts={}) http_post "#{resource_name}/transfer-schedules", opts end
schedules()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 147 def schedules http_get "#{resource_name}/transfer-schedules" end
unfollow()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 80 def unfollow http_put "#{resource_name}/unfollow" end
unschedule(id)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 155 def unschedule(id) http_delete "#{resource_name}/transfer-schedules/#{URI.encode(id.to_s)}" end
upgrade()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 84 def upgrade http_post "#{resource_name}/upgrade" end
upgrade_status()
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 88 def upgrade_status http_get "#{resource_name}/upgrade_status" end
Protected Instance Methods
checking_client_version() { || ... }
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 171 def checking_client_version begin yield rescue RestClient::BadRequest => e if message = json_decode(e.response.to_s)["upgrade_message"] abort(message) else raise e end end end
display_heroku_warning(response)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 183 def display_heroku_warning(response) warning = response.headers[:x_heroku_warning] display warning if warning response end
http_delete(path)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 215 def http_delete(path) checking_client_version do response = heroku_postgresql_resource[path].delete display_heroku_warning response sym_keys(json_decode(response.to_s)) end end
http_get(path)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 189 def http_get(path) checking_client_version do retry_on_exception(RestClient::Exception) do response = heroku_postgresql_resource[path].get display_heroku_warning response sym_keys(json_decode(response.to_s)) end end end
http_post(path, payload = {})
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 199 def http_post(path, payload = {}) checking_client_version do response = heroku_postgresql_resource[path].post(json_encode(payload)) display_heroku_warning response sym_keys(json_decode(response.to_s)) end end
http_put(path, payload = {})
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 207 def http_put(path, payload = {}) checking_client_version do response = heroku_postgresql_resource[path].put(json_encode(payload)) display_heroku_warning response sym_keys(json_decode(response.to_s)) end end
sym_keys(c)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 161 def sym_keys(c) if c.is_a?(Array) c.map { |e| sym_keys(e) } else c.inject({}) do |h, (k, v)| h[k.to_sym] = v; h end end end
Private Instance Methods
determine_host(value, default)
click to toggle source
# File lib/heroku/client/heroku_postgresql.rb, line 225 def determine_host(value, default) if value.nil? default else "#{value}.herokuapp.com" end end