Class: Heroku::Api::Postgres::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/api/postgres/client.rb

Constant Summary collapse

STARTER_HOST =
'https://postgres-starter-api.heroku.com'
PRO_HOST =
'https://postgres-api.heroku.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_key) ⇒ Client

Returns a new instance of Client.



24
25
26
27
# File 'lib/heroku/api/postgres/client.rb', line 24

def initialize(client_key)
  @client_key = client_key
  @basic_url = STARTER_HOST
end

Instance Attribute Details

#client_keyObject

Returns the value of attribute client_key.



22
23
24
# File 'lib/heroku/api/postgres/client.rb', line 22

def client_key
  @client_key
end

#heroku_clientObject

Returns the value of attribute heroku_client.



22
23
24
# File 'lib/heroku/api/postgres/client.rb', line 22

def heroku_client
  @heroku_client
end

Instance Method Details

#backupsObject



29
30
31
# File 'lib/heroku/api/postgres/client.rb', line 29

def backups
  @backups ||= Backups.new(self)
end

#credentialsObject



37
38
39
# File 'lib/heroku/api/postgres/client.rb', line 37

def credentials
  @credentials ||= Credentials.new(self)
end

#databasesObject



33
34
35
# File 'lib/heroku/api/postgres/client.rb', line 33

def databases
  @databases ||= Databases.new(self)
end

#db_host(app_id, database_id) ⇒ Object

the database id matches the field ‘id` in pro plans and the field addon_service.id in free plans



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

def db_host(app_id, database_id)
  all_addons = heroku_client.addon.list_by_app(app_id)
  database_json = all_addons.find do |addon|
    [addon['id'], addon['addon_service']['id']].include?(database_id)
  end
  return STARTER_HOST if database_json.nil?

  host_for(database_json)
end

#perform_get_request(path, options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/heroku/api/postgres/client.rb', line 52

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



60
61
62
63
64
65
66
67
# File 'lib/heroku/api/postgres/client.rb', line 60

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