Skip to content

Commit

Permalink
feat(db-api) Start adding boilerplate for database API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-scalingo committed Dec 20, 2022
1 parent 8a036b4 commit f983100
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/scalingo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "scalingo/auth"
require "scalingo/billing"
require "scalingo/regional"
require "scalingo/regional_database"

module Scalingo
class Client < CoreClient
Expand All @@ -26,12 +27,28 @@ def osc_fr1
scalingo: self,
)
end
alias osc_fr1 apps_api_osc_fr1

def osc_secnum_fr1
@osc_secnum_fr1 ||= Regional.new(
"https://api.osc-secnum-fr1.scalingo.com/v1",
scalingo: self,
)
end
alias osc_secnum_fr1 apps_api_osc_secnum_fr1

def db_api_osc_fr1
@db_api_osc_fr1 ||= RegionalDatabase.new(
"https://db-api.osc-fr1.scalingo.com",
scalingo: self,
)
end

def db_api_osc_secnum_fr1
@db_api_osc_secnum_fr1 ||= RegionalDatabase.new(
"https://db-api.osc-fr1.scalingo.com",
scalingo: self,
)
end
end
end
13 changes: 13 additions & 0 deletions lib/scalingo/regional_database.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "scalingo/api/client"

module Scalingo
class RegionalDatabaseAPI < API::Client
require "scalingo/regional_database/databases"
require "scalingo/regional_database/backups"

register_handlers!(
databases: Databases,
backups: Backups,
)
end
end
31 changes: 31 additions & 0 deletions lib/scalingo/regional_database/backups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "scalingo/api/endpoint"

module Scalingo
class RegionalDatabase::Backups < API::Endpoint
def for(addon_id, headers = nil, &block)
data = nil

response = connection.get(
"databases/#{addonn_id}/backups",
data,
headers,
&block
)

unpack(:addons) { response }
end

def find(addon_id, backup_id, headers = nil, &block)
data = nil

response = connection.get(
"databases/#{addon_id}/backups/#{backup_id}",
data,
headers,
&block
)

unpack(:backup) { response }
end
end
end
18 changes: 18 additions & 0 deletions lib/scalingo/regional_database/databases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "scalingo/api/endpoint"

module Scalingo
class RegionalDatabase::Databases < API::Endpoint
def find(id, headers = nil, &block)
data = nil

response = connection.get(
"databases/#{id}",
data,
headers,
&block
)

unpack(:database) { response }
end
end
end

0 comments on commit f983100

Please sign in to comment.