Skip to content

Commit

Permalink
Merge pull request #48 from Scalingo/feat/db-api/add-default-region-f…
Browse files Browse the repository at this point in the history
…or-db-api

feat(databases): Add default region management
  • Loading branch information
aurelien-reeves-scalingo authored Jan 3, 2023
2 parents 65bc6fe + e23e35d commit 16c26b9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

* Bugfix: response of Backups#create was not properly unpacked ([#44](https://github.com/Scalingo/scalingo-ruby-api/issues/44))
* New: Add default region for database API ([#45](https://github.com/Scalingo/scalingo-ruby-api/issues/44))

## 3.2.0 - 2022-12-23

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ scalingo.db_api_osc_fr1.backups.for(addon_id)

# get URL to download backup archive
scalingo.db_api_osc_fr1.backups.archive(addon_id, backup_id)

# you can omit the region to use the default one
scalingo.databases.find(addon_id)

```

## Development
Expand Down
7 changes: 7 additions & 0 deletions lib/scalingo/core_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def region(name = nil)
public_send(name || config.default_region)
end

def database_region(name = nil)
public_send(name || "db_api_#{config.default_region}")
end

## Authentication helpers / Token management
def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
if !access_token && !bearer_token
Expand Down Expand Up @@ -102,5 +106,8 @@ def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
def_delegator :region, :notifiers
def_delegator :region, :operations
def_delegator :region, :scm_repo_links

def_delegator :database_region, :databases
def_delegator :database_region, :backups
end
end
23 changes: 23 additions & 0 deletions spec/scalingo/core_client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "spec_helper"

RSpec.describe Scalingo::CoreClient do
subject { described_class.new }

describe "#database_region" do
it "forwards call to the specified region" do
allow(subject).to receive("db_api_osc_secnum_fr1")

subject.database_region("db_api_osc_secnum_fr1")

expect(subject).to have_received("db_api_osc_secnum_fr1")
end

it "forwards call to default db_api region" do
allow(subject).to receive("db_api_#{subject.config.default_region}")

subject.database_region

expect(subject).to have_received("db_api_#{subject.config.default_region}")
end
end
end

0 comments on commit 16c26b9

Please sign in to comment.