Skip to content

Commit b42e808

Browse files
authored
Merge pull request #41 from sechosebio/master
Avoid compile-time config for api_url
2 parents cdab0ac + a9d53c8 commit b42e808

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The library has a number of configuration options you can use to overwrite defau
139139
- `config :segment, :retry_start` The time (in ms) to start the first retry. Default value is 100
140140
- `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
141141
- `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.
142-
- `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/).
142+
- `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/).
143143

144144
## Usage in Phoenix
145145

lib/segment/client/http.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ defmodule Segment.Http do
4040
require Logger
4141
use Retry
4242

43-
@segment_api_url Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")
44-
4543
@doc """
4644
Create a Tesla client with the Segment Source Write API Key
4745
"""
@@ -66,7 +64,7 @@ defmodule Segment.Http do
6664
@spec client(String.t(), adapter()) :: client()
6765
def client(api_key, adapter) do
6866
middleware = [
69-
{Tesla.Middleware.BaseUrl, @segment_api_url},
67+
{Tesla.Middleware.BaseUrl, Segment.Config.api_url()},
7068
Tesla.Middleware.JSON,
7169
{Tesla.Middleware.BasicAuth, %{username: api_key, password: ""}}
7270
]

lib/segment/config.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
defmodule Segment.Config do
22
@moduledoc false
33

4+
def api_url do
5+
Application.get_env(:segment, :api_url, "https://api.segment.io/v1/")
6+
end
7+
48
def service do
59
Application.get_env(:segment, :sender_impl, Segment.Analytics.Batcher)
610
end

0 commit comments

Comments
 (0)