Class: Heroku::Api::Postgres::Client
- Inherits:
-
Object
- Object
- Heroku::Api::Postgres::Client
- 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
-
#heroku_client ⇒ Object
readonly
Returns the value of attribute heroku_client.
-
#oauth_client_key ⇒ Object
readonly
Returns the value of attribute oauth_client_key.
Instance Method Summary collapse
- #backups ⇒ Object
- #credentials ⇒ Object
- #databases ⇒ Object
-
#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.
-
#initialize(oauth_client_key) ⇒ Client
constructor
A new instance of Client.
- #perform_get_request(path, options = {}) ⇒ Object
- #perform_post_request(path, params = {}, options = {}) ⇒ Object
Constructor Details
#initialize(oauth_client_key) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 |
# File 'lib/heroku/api/postgres/client.rb', line 16 def initialize(oauth_client_key) @oauth_client_key = oauth_client_key @basic_url = STARTER_HOST @heroku_client = PlatformAPI.connect_oauth(oauth_client_key) end |
Instance Attribute Details
#heroku_client ⇒ Object (readonly)
Returns the value of attribute heroku_client.
14 15 16 |
# File 'lib/heroku/api/postgres/client.rb', line 14 def heroku_client @heroku_client end |
#oauth_client_key ⇒ Object (readonly)
Returns the value of attribute oauth_client_key.
14 15 16 |
# File 'lib/heroku/api/postgres/client.rb', line 14 def oauth_client_key @oauth_client_key end |
Instance Method Details
#backups ⇒ Object
22 23 24 |
# File 'lib/heroku/api/postgres/client.rb', line 22 def backups @backups ||= Backups.new(self) end |
#credentials ⇒ Object
30 31 32 |
# File 'lib/heroku/api/postgres/client.rb', line 30 def credentials @credentials ||= Credentials.new(self) end |
#databases ⇒ Object
26 27 28 |
# File 'lib/heroku/api/postgres/client.rb', line 26 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
35 36 37 38 39 40 41 42 43 |
# File 'lib/heroku/api/postgres/client.rb', line 35 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
45 46 47 48 49 50 51 |
# File 'lib/heroku/api/postgres/client.rb', line 45 def perform_get_request(path, = {}) url = build_uri(path, **) 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
53 54 55 56 57 58 59 60 |
# File 'lib/heroku/api/postgres/client.rb', line 53 def perform_post_request(path, params = {}, = {}) url = build_uri(path, **) req = Net::HTTP::Post.new(url) add_auth_headers(req) req.body = params.to_json response = start_request(req, url) parse_response(response) end |