-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathdata_source_builder_common.rb
More file actions
79 lines (72 loc) · 2.02 KB
/
data_source_builder_common.rb
File metadata and controls
79 lines (72 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
require "ldclient-rb/impl/data_system/http_config_options"
module LaunchDarkly
module Impl
module DataSystem
#
# DataSourceBuilderCommon is a mixin that provides common HTTP configuration
# setters for data source builders (polling and streaming).
#
# Each builder that includes this module must define a DEFAULT_BASE_URI constant.
#
module DataSourceBuilderCommon
#
# Sets the base URI for HTTP requests.
#
# @param uri [String]
# @return [self]
#
def base_uri(uri)
@base_uri = uri
self
end
#
# Sets a custom socket factory for HTTP connections.
#
# @param factory [Object]
# @return [self]
#
def socket_factory(factory)
@socket_factory = factory
self
end
#
# Sets the read timeout for HTTP connections.
#
# @param timeout [Float] Timeout in seconds
# @return [self]
#
def read_timeout(timeout)
@read_timeout = timeout
self
end
#
# Sets the connect timeout for HTTP connections.
#
# @param timeout [Float] Timeout in seconds
# @return [self]
#
def connect_timeout(timeout)
@connect_timeout = timeout
self
end
private
#
# Builds an HttpConfigOptions instance from the current builder settings.
# Uses self.class::DEFAULT_BASE_URI if base_uri was not explicitly set.
# Read/connect timeouts default to HttpConfigOptions defaults if not set.
#
# @return [HttpConfigOptions]
#
def build_http_config
HttpConfigOptions.new(
base_uri: @base_uri || self.class::DEFAULT_BASE_URI,
socket_factory: @socket_factory,
read_timeout: @read_timeout,
connect_timeout: @connect_timeout
)
end
end
end
end
end