Module: Trevosdk
- Defined in:
- lib/trevosdk.rb,
lib/trevosdk/core.rb,
lib/trevosdk/client.rb,
lib/trevosdk/poller.rb,
lib/trevosdk/batcher.rb,
lib/trevosdk/version.rb,
lib/trevosdk/transport.rb
Defined Under Namespace
Modules: Core
Classes: Client, ConfigPoller, EventBatcher, ExposureDeduper, TransportRequest, TransportResponse
Constant Summary
collapse
- VERSION =
"0.1.0"
- CONFIG_URL =
"https://api.trevosdk.com/v1/config"
- INGESTION_URL =
"https://ingest.trevosdk.com/v1/events"
- ALIAS_URL =
"https://ingest.trevosdk.com/v1/alias"
- DEFAULT_POLL_INTERVAL_S =
60.0
- MIN_POLL_INTERVAL_S =
10.0
- DEFAULT_FLUSH_INTERVAL_S =
5.0
- MIN_FLUSH_INTERVAL_S =
0.5
- DEFAULT_MAX_BATCH_SIZE =
50
- SERVER_MAX_BATCH_SIZE =
500
- MAX_QUEUE_SIZE =
10_000
- REQUEST_TIMEOUT_S =
10.0
- SERVER_EXPOSURE_DEDUP_MAX_KEYS =
100_000
- FORCE_VARIANTS_ENV =
"TREVO_FORCE_VARIANTS"
- DEFAULT_TRANSPORT =
lambda do |request|
uri = URI.parse(request.url)
timeout = request.timeout_s || REQUEST_TIMEOUT_S
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.open_timeout = timeout
http.read_timeout = timeout
http.write_timeout = timeout if http.respond_to?(:write_timeout=)
response = http.send_request(request.method, uri.request_uri, request.body, request.)
TransportResponse.new(
status: response.code.to_i,
body: response.body.to_s,
headers: response..to_h
)
end
Class Method Summary
collapse
Class Method Details
51
52
53
|
# File 'lib/trevosdk/transport.rb', line 51
def (secret_key)
{"Content-Type" => "application/json", "Authorization" => "Bearer #{secret_key}"}
end
|
.client ⇒ Object
16
17
18
|
# File 'lib/trevosdk.rb', line 16
def client
@client || raise("Trevosdk.init has not been called")
end
|
.close ⇒ Object
20
21
22
23
|
# File 'lib/trevosdk.rb', line 20
def close
@client&.close
@client = nil
end
|
.init(secret_key, **options) ⇒ Object
Process-wide singleton for the common one-client-per-app setup
(e.g. a Rails config/initializers/trevosdk.rb).
11
12
13
14
|
# File 'lib/trevosdk.rb', line 11
def init(secret_key, **options)
@client&.close
@client = Client.new(secret_key, **options)
end
|