Skip to content

Commit

Permalink
Merge pull request #41 from sechosebio/master
Browse files Browse the repository at this point in the history
Avoid compile-time config for api_url
  • Loading branch information
stueccles authored May 8, 2022
2 parents cdab0ac + a9d53c8 commit b42e808
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The library has a number of configuration options you can use to overwrite defau
- `config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
- `config :segment, :send_to_http` If set to `false`, the library will override the Tesla Adapter implementation to only log segment calls to `debug` but not make any actual API calls. This can be useful if you want to switch off Segment for test or dev. Default value is true
- `config :segment, :tesla, :adapter` This config option allows for overriding the HTTP Adapter for Tesla (which the library defaults to Hackney).This can be useful if you prefer something else, or want to mock the adapter for testing.
- `config :segment, api_url: "https://self-hosted-segment-api.com/v1/"` The Segment-compatible API endpoint that will receive your events. Defaults to `https://api.segment.io/v1/`. This setting is only useful if you are using a Segment-compatible alternative API like [Rudderstack](https://rudderstack.com/).
- `config :segment, api_url: "https://self-hosted-segment-api.com/v1/"` The Segment-compatible API endpoint that will receive your events. Defaults to `https://api.segment.io/v1/`. This setting is only useful if you are using Segment's EU instance or a Segment-compatible alternative API like [Rudderstack](https://rudderstack.com/).

## Usage in Phoenix

Expand Down
4 changes: 1 addition & 3 deletions lib/segment/client/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ defmodule Segment.Http do
require Logger
use Retry

@segment_api_url Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")

@doc """
Create a Tesla client with the Segment Source Write API Key
"""
Expand All @@ -66,7 +64,7 @@ defmodule Segment.Http do
@spec client(String.t(), adapter()) :: client()
def client(api_key, adapter) do
middleware = [
{Tesla.Middleware.BaseUrl, @segment_api_url},
{Tesla.Middleware.BaseUrl, Segment.Config.api_url()},
Tesla.Middleware.JSON,
{Tesla.Middleware.BasicAuth, %{username: api_key, password: ""}}
]
Expand Down
4 changes: 4 additions & 0 deletions lib/segment/config.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
defmodule Segment.Config do
@moduledoc false

def api_url do
Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")
end

def service do
Application.get_env(:segment, :sender_impl, Segment.Analytics.Batcher)
end
Expand Down

0 comments on commit b42e808

Please # to comment.