Skip to content

Commit

Permalink
Merge pull request #73 from ludwigbacklund/custom-backend-url
Browse files Browse the repository at this point in the history
Add backend_url option to client initializer
  • Loading branch information
unicodeveloper authored Mar 7, 2024
2 parents a68fa20 + 2805f1b commit d221667
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,17 @@ client = Novu::Client.new(
| enable_retry | enabling/disable the Exponential Retry mechanism | false | Boolean |


### Custom backend URL

To use a custom backend URL, for example to be able to use the EU Novu API, you can pass a custom `backend_url` when initializing the client.

```ruby
client = Novu::Client.new(
access_token: '<your-novu-api_key>',
backend_url: 'https://eu.api.novu.co/v1'
)
```

### For more information about these methods and their parameters, see the [API documentation](https://docs.novu.co/api-reference).

## Contributing
Expand Down
5 changes: 3 additions & 2 deletions lib/novu/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Client
include Novu::Api::Tenants
include Novu::Api::Topics

base_uri "https://api.novu.co/v1"
format :json

attr_accessor :enable_retry, :max_retries, :initial_delay, :max_delay, :idempotency_key
Expand All @@ -54,7 +53,7 @@ class Client
# - max_retries [Integer]
# - initial_delay [Integer]
# - max_delay [Integer]
def initialize(access_token: nil, idempotency_key: nil, enable_retry: false, retry_config: {} )
def initialize(access_token: nil, idempotency_key: nil, enable_retry: false, retry_config: {}, backend_url: "https://api.novu.co/v1")
raise ArgumentError, "Api Key cannot be blank or nil" if access_token.blank?

@idempotency_key = idempotency_key.blank? ? UUID.new.generate : idempotency_key
Expand All @@ -68,6 +67,8 @@ def initialize(access_token: nil, idempotency_key: nil, enable_retry: false, ret
@initial_delay = retry_config[:initial_delay]
@max_delay = retry_config[:max_delay]

self.base_uri = backend_url

self.class.default_options.merge!(headers: {
"Authorization" => "ApiKey #{@access_token}",
"User-Agent" => "novu/ruby/#{Novu::VERSION}"
Expand Down

0 comments on commit d221667

Please sign in to comment.