Class: Rox::Core::RequestConfigurationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/core/network/request_configuration_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(sdk_settings, buid, device_properties) ⇒ RequestConfigurationBuilder

Returns a new instance of RequestConfigurationBuilder.



8
9
10
11
12
13
# File 'lib/rox/core/network/request_configuration_builder.rb', line 8

def initialize(sdk_settings, buid, device_properties)
  @sdk_settings = sdk_settings
  @buid = buid
  @device_properties = device_properties
  @rox_options = device_properties.rox_options
end

Instance Method Details

#build_for_apiObject



25
26
27
# File 'lib/rox/core/network/request_configuration_builder.rb', line 25

def build_for_api
  build_request_with_full_params("#{Rox::Core::Environment.api_path}/#{relative_path}")
end

#build_for_cdnObject



20
21
22
23
# File 'lib/rox/core/network/request_configuration_builder.rb', line 20

def build_for_cdn
  RequestData.new("#{Rox::Core::Environment.cdn_path}/#{relative_path}",
                  Rox::Core::PropertyType::DISTINCT_ID.name => @device_properties.distinct_id)
end

#build_for_roxyObject



15
16
17
18
# File 'lib/rox/core/network/request_configuration_builder.rb', line 15

def build_for_roxy
  roxy_endpoint = URI.join(@rox_options.roxy_url, Rox::Core::Environment.roxy_internal_path).to_s
  build_request_with_full_params(roxy_endpoint)
end

#build_request_with_full_params(url) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rox/core/network/request_configuration_builder.rb', line 33

def build_request_with_full_params(url)
  query_params = {}

  @buid.query_string_parts.each do |key, value|
    query_params[key] = value unless query_params.include?(key)
  end

  @device_properties.all_properties.each do |key, value|
    query_params[key] = value unless query_params.include?(key)
  end

  query_params[Rox::Core::PropertyType::CACHE_MISS_RELATIVE_URL.name] = relative_path
  query_params['devModeSecret'] = @sdk_settings.dev_mode_secret

  RequestData.new(url, query_params)
end

#relative_pathObject



29
30
31
# File 'lib/rox/core/network/request_configuration_builder.rb', line 29

def relative_path
  "#{@device_properties.rollout_key}/#{@buid.value}"
end