Class: Kameleoon::Network::UrlProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/network/url_provider.rb

Overview

UrlProvider is used as a source of URLs for network calls.

Constant Summary collapse

TRACKING_PATH =
'/visit/events'
VISITOR_DATA_PATH =
'/visit/visitor'
GET_DATA_PATH =
'/map/map'
POST_DATA_PATH =
'/map/maps'
ACCESS_TOKEN_PATH =
'/oauth/token'
CONFIGURATION_API_URL_FORMAT =
'https://sdk-config.kameleoon.eu/%s'
RT_CONFIGURATION_URL =
'https://events.kameleoon.com:8110/sse'
DEFAULT_DATA_API_DOMAIN =
'data.kameleoon.io'
TEST_DATA_API_DOMAIN =
'data.kameleoon.net'
DEFAULT_AUTOMATION_API_DOMAIN =
'api.kameleoon.com'
TEST_AUTOMATION_API_DOMAIN =
'api.kameleoon.net'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_code, data_api_domain = DEFAULT_DATA_API_DOMAIN, automation_api_domain = DEFAULT_AUTOMATION_API_DOMAIN) ⇒ UrlProvider

Returns a new instance of UrlProvider.



26
27
28
29
30
31
32
33
34
# File 'lib/kameleoon/network/url_provider.rb', line 26

def initialize(
  site_code,
  data_api_domain = DEFAULT_DATA_API_DOMAIN,
  automation_api_domain = DEFAULT_AUTOMATION_API_DOMAIN
)
  @site_code = site_code
  @data_api_domain = data_api_domain
  @automation_api_domain = automation_api_domain
end

Instance Attribute Details

#automation_api_domainObject (readonly)

Returns the value of attribute automation_api_domain.



24
25
26
# File 'lib/kameleoon/network/url_provider.rb', line 24

def automation_api_domain
  @automation_api_domain
end

#data_api_domainObject (readonly)

Returns the value of attribute data_api_domain.



24
25
26
# File 'lib/kameleoon/network/url_provider.rb', line 24

def data_api_domain
  @data_api_domain
end

#site_codeObject (readonly)

Returns the value of attribute site_code.



24
25
26
# File 'lib/kameleoon/network/url_provider.rb', line 24

def site_code
  @site_code
end

Instance Method Details

#apply_data_api_domain(domain) ⇒ Object



36
37
38
# File 'lib/kameleoon/network/url_provider.rb', line 36

def apply_data_api_domain(domain)
  @data_api_domain = domain if domain.is_a?(String)
end

#make_access_token_urlObject



88
89
90
# File 'lib/kameleoon/network/url_provider.rb', line 88

def make_access_token_url
  "https://#{@automation_api_domain}#{ACCESS_TOKEN_PATH}"
end

#make_api_data_get_request_url(key) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/kameleoon/network/url_provider.rb', line 66

def make_api_data_get_request_url(key)
  params = {
    siteCode: @site_code,
    key: key
  }
  "https://#{@data_api_domain}#{GET_DATA_PATH}?#{UriHelper.encode_query(params)}"
end

#make_configuration_url(environment = nil, timestamp = nil) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/kameleoon/network/url_provider.rb', line 74

def make_configuration_url(environment = nil, timestamp = nil)
  url = format(CONFIGURATION_API_URL_FORMAT, @site_code)
  params = {}
  params[:environment] = environment unless environment.nil?
  params[:ts] = timestamp unless timestamp.nil?
  url = "#{url}?#{UriHelper.encode_query(params)}" unless params.empty?
  url
end

#make_real_time_urlObject



83
84
85
86
# File 'lib/kameleoon/network/url_provider.rb', line 83

def make_real_time_url
  params = { siteCode: @site_code }
  "#{RT_CONFIGURATION_URL}?#{UriHelper.encode_query(params)}"
end

#make_tracking_urlObject



40
41
42
43
44
45
46
47
48
# File 'lib/kameleoon/network/url_provider.rb', line 40

def make_tracking_url
  params = {
    sdkName: SDK_NAME,
    sdkVersion: SDK_VERSION,
    siteCode: @site_code,
    bodyUa: true
  }
  "https://#{@data_api_domain}#{TRACKING_PATH}?#{UriHelper.encode_query(params)}"
end

#make_visitor_data_get_url(visitor_code, filter, is_unique_identifier = false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kameleoon/network/url_provider.rb', line 50

def make_visitor_data_get_url(visitor_code, filter, is_unique_identifier = false)
  params = { siteCode: @site_code }
  params[is_unique_identifier ? :mappingValue : :visitorCode] = visitor_code
  params[:maxNumberPreviousVisits] = filter.previous_visit_amount
  params[:version] = 0
  params[:kcs] = true if filter.kcs
  params[:currentVisit] = true if filter.current_visit
  params[:customData] = true if filter.custom_data
  params[:conversion] = true if filter.conversions
  params[:geolocation] = true if filter.geolocation
  params[:experiment] = true if filter.experiments
  params[:page] = true if filter.page_views
  params[:staticData] = true if filter.device || filter.browser || filter.operating_system
  "https://#{@data_api_domain}#{VISITOR_DATA_PATH}?#{UriHelper.encode_query(params)}"
end