Class: Heroku::Client::Pgbackups

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

Direct Known Subclasses

Pgbackups::Client

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(uri) ⇒ Pgbackups

Returns a new instance of Pgbackups.


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

def initialize(uri)
  @uri = URI.parse(uri)
end

Instance Method Details

#authenticated_resource(path) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/heroku/client/pgbackups.rb', line 11

def authenticated_resource(path)
  host = "#{@uri.scheme}://#{@uri.host}"
  host += ":#{@uri.port}" if @uri.port
  RestClient::Resource.new("#{host}#{path}",
    :user     => @uri.user,
    :password => @uri.password,
    :headers  => {:x_heroku_gem_version => Heroku::Client.version}
  )
end

#create_transfer(from_url, from_name, to_url, to_name, opts = {}) ⇒ Object


21
22
23
24
25
26
# File 'lib/heroku/client/pgbackups.rb', line 21

def create_transfer(from_url, from_name, to_url, to_name, opts={})
  # opts[:expire] => true will delete the oldest backup if at the plan limit
  resource = authenticated_resource("/client/transfers")
  params = {:from_url => from_url, :from_name => from_name, :to_url => to_url, :to_name => to_name}.merge opts
  json_decode post(resource, params).body
end

#delete_backup(name) ⇒ Object


54
55
56
57
58
59
60
61
62
63
# File 'lib/heroku/client/pgbackups.rb', line 54

def delete_backup(name)
  name = URI.escape(name)
  begin
    resource = authenticated_resource("/client/backups/#{name}")
    delete(resource).body
    true
  rescue RestClient::ResourceNotFound => e
    false
  end
end

#get_backup(name, opts = {}) ⇒ Object


43
44
45
46
47
# File 'lib/heroku/client/pgbackups.rb', line 43

def get_backup(name, opts={})
  name = URI.escape(name)
  resource = authenticated_resource("/client/backups/#{name}")
  json_decode get(resource).body
end

#get_backups(opts = {}) ⇒ Object


38
39
40
41
# File 'lib/heroku/client/pgbackups.rb', line 38

def get_backups(opts={})
  resource = authenticated_resource("/client/backups")
  json_decode get(resource).body
end

#get_latest_backupObject


49
50
51
52
# File 'lib/heroku/client/pgbackups.rb', line 49

def get_latest_backup
  resource = authenticated_resource("/client/latest_backup")
  json_decode get(resource).body
end

#get_transfer(id) ⇒ Object


33
34
35
36
# File 'lib/heroku/client/pgbackups.rb', line 33

def get_transfer(id)
  resource = authenticated_resource("/client/transfers/#{id}")
  json_decode get(resource).body
end

#get_transfersObject


28
29
30
31
# File 'lib/heroku/client/pgbackups.rb', line 28

def get_transfers
  resource = authenticated_resource("/client/transfers")
  json_decode get(resource).body
end