class Heroku::Api::Postgres::Client
Attributes
oauth_client_key[R]
Public Class Methods
new(oauth_client_key)
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 11 def initialize(oauth_client_key) @oauth_client_key = oauth_client_key @basic_url = Databases::STARTER_HOST end
Public Instance Methods
backups()
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 16 def backups @backups ||= Backups.new(self) end
databases()
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 20 def databases @databases ||= Databases.new(self) end
perform_get_request(path, options = {})
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 24 def perform_get_request(path, options = {}) url = build_uri(path, options) req = Net::HTTP::Get.new(url) add_auth_headers(req) response = start_request(req, url) parse_response(response) end
perform_post_request(path, params = {}, options = {})
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 32 def perform_post_request(path, params = {}, options = {}) url = build_uri(path, options) req = Net::HTTP::Post.new(url) add_auth_headers(req) req.body = params.to_json response = start_request(req, url) parse_response(response) end
Private Instance Methods
add_auth_headers(req)
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 47 def add_auth_headers(req) req['Accept'] = 'application/vnd.heroku+json; version=3' req.basic_auth '', @oauth_client_key end
build_uri(path, host: @basic_url)
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 43 def build_uri(path, host: @basic_url) URI.join(host, path) end
parse_response(response)
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 58 def parse_response(response) if %w[200 201].include? response.code JSON.parse(response.body, symbolize_names: true) else { error: { status: response.code.to_i } } end end
start_request(req, url)
click to toggle source
# File lib/heroku/api/postgres/client.rb, line 52 def start_request(req, url) http_new = Net::HTTP.new(url.hostname, url.port) http_new.use_ssl = true http_new.start { |http| http.request(req) } end