Class: Heroku::Client::HerokuPostgresqlApp

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/heroku/client/heroku_postgresql_backups.rb

Constant Summary collapse

Version =
11

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#action, #app_owner, #ask, #confirm, #confirm_command, #create_git_remote, #debug, #debugging?, #default_org_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, #error_log, #error_log_path, 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?, #has_git_remote?, #has_http_git_entry_in_netrc, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #org?, #org_host, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #stderr_print, #stderr_puts, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #update_git_remote, #warn_if_using_jruby, #with_tty

Constructor Details

#initialize(app_name) ⇒ HerokuPostgresqlApp

Returns a new instance of HerokuPostgresqlApp


11
12
13
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 11

def initialize(app_name)
  @app_name = app_name
end

Class Method Details

.headersObject


7
8
9
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 7

def self.headers
  Heroku::Client::HerokuPostgresql.headers
end

Instance Method Details

#display_heroku_warning(response) ⇒ Object


78
79
80
81
82
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 78

def display_heroku_warning(response)
  warning = response.headers[:x_heroku_warning]
  display warning if warning
  response
end

#heroku_postgresql_hostObject


35
36
37
38
39
40
41
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 35

def heroku_postgresql_host
  if ENV['SHOGUN']
    "shogun-#{ENV['SHOGUN']}.herokuapp.com"
  else
    determine_host(ENV["HEROKU_POSTGRESQL_HOST"], "postgres-api.heroku.com")
  end
end

#heroku_postgresql_resourceObject


43
44
45
46
47
48
49
50
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 43

def heroku_postgresql_resource
  RestClient::Resource.new(
    "https://#{heroku_postgresql_host}/client/v11/apps",
    :user => Heroku::Auth.user,
    :password => Heroku::Auth.password,
    :headers => self.class.headers
    )
end

#http_delete(path) ⇒ Object


70
71
72
73
74
75
76
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 70

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) ⇒ Object


52
53
54
55
56
57
58
59
60
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 52

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 = {}) ⇒ Object


62
63
64
65
66
67
68
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 62

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

#transfersObject


15
16
17
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 15

def transfers
  http_get "#{@app_name}/transfers"
end

#transfers_cancel(id) ⇒ Object


27
28
29
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 27

def transfers_cancel(id)
  http_post "#{@app_name}/transfers/#{URI.encode(id.to_s)}/actions/cancel"
end

#transfers_delete(id) ⇒ Object


23
24
25
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 23

def transfers_delete(id)
  http_delete "#{@app_name}/transfers/#{URI.encode(id.to_s)}"
end

#transfers_get(id, verbose = false) ⇒ Object


19
20
21
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 19

def transfers_get(id, verbose=false)
  http_get "#{@app_name}/transfers/#{URI.encode(id.to_s)}?verbose=#{verbose}"
end

#transfers_public_url(id) ⇒ Object


31
32
33
# File 'lib/heroku/client/heroku_postgresql_backups.rb', line 31

def transfers_public_url(id)
  http_post "#{@app_name}/transfers/#{URI.encode(id.to_s)}/actions/public-url"
end