Class: PGBackups::Client

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

Instance Method Summary (collapse)

Methods included from Heroku::Helpers

#app_urls, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_row, #display_table, #error, #fail, #format_bytes, #format_date, #get_terminal_environment, #git, #has_git?, #home_directory, #json_decode, #json_encode, #longest, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #time_ago, #truncate

Constructor Details

- (Client) initialize(uri)

A new instance of Client



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

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

Instance Method Details

- (Object) authenticated_resource(path)



11
12
13
14
15
16
17
18
19
# File 'lib/pgbackups/client.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

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



21
22
23
24
25
26
# File 'lib/pgbackups/client.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 resource.post(params).body
end

- (Object) delete_backup(name)



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

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

- (Object) get_backup(name, opts = {})



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

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

- (Object) get_backups(opts = {})



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

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

- (Object) get_latest_backup



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

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

- (Object) get_transfer(id)



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

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

- (Object) get_transfers



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

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