# File lib/heroku/client/pgbackups.rb, line 7 def initialize(uri) require 'rest_client' @uri = URI.parse(uri) end
# File lib/heroku/client/pgbackups.rb, line 12 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
# File lib/heroku/client/pgbackups.rb, line 22 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
# File lib/heroku/client/pgbackups.rb, line 55 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
# File lib/heroku/client/pgbackups.rb, line 44 def get_backup(name, opts={}) name = URI.escape(name) resource = authenticated_resource("/client/backups/#{name}") json_decode get(resource).body end
# File lib/heroku/client/pgbackups.rb, line 39 def get_backups(opts={}) resource = authenticated_resource("/client/backups") json_decode get(resource).body end
# File lib/heroku/client/pgbackups.rb, line 50 def get_latest_backup resource = authenticated_resource("/client/latest_backup") json_decode get(resource).body end
# File lib/heroku/client/pgbackups.rb, line 34 def get_transfer(id) resource = authenticated_resource("/client/transfers/#{id}") json_decode get(resource).body end
# File lib/heroku/client/pgbackups.rb, line 29 def get_transfers resource = authenticated_resource("/client/transfers") json_decode get(resource).body end
# File lib/heroku/client/pgbackups.rb, line 92 def check_errors yield rescue RestClient::Unauthorized error "Invalid PGBACKUPS_URL" end
# File lib/heroku/client/pgbackups.rb, line 84 def delete(resource) check_errors do response = resource.delete display_heroku_warning response response end end
# File lib/heroku/client/pgbackups.rb, line 98 def display_heroku_warning(response) warning = response.headers[:x_heroku_warning] display warning if warning response end
# File lib/heroku/client/pgbackups.rb, line 68 def get(resource) check_errors do response = resource.get display_heroku_warning response response end end
# File lib/heroku/client/pgbackups.rb, line 76 def post(resource, params) check_errors do response = resource.post(params) display_heroku_warning response response end end