Class: ParamBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/capi_param_builder.rb

Constant Summary collapse

FBC_NAME =
"_fbc"
FBP_NAME =
"_fbp"
DEFAULT_1PC_AGE =
90 * 24 * 3600
LANGUAGE_TOKEN =

Original Ruby language token

"BQ"
SUPPORTED_LANGUAGE_TOKENS =
["AQ", "Ag", "Aw", "BA", "BQ", "Bg"]
MIN_PAYLOAD_SPLIT_LENGTH =
4
MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH =
5
IPV4_REGEX =
/\A(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/
IPV6_REGEX =
/\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,7}:\z|\A(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}\z|\A(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}\z|\A(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}\z|\A[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}\z|\A:(?::[0-9a-fA-F]{1,4}){1,7}\z|\A::\z|\A(?:[0-9a-fA-F]{1,4}:){6}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/
DEFAULT_FORMAT =

Appendix constants

0x01
LANGUAGE_TOKEN_INDEX =

Ruby language token index

0x05
APPENDIX_LENGTH_V1 =
2
APPENDIX_LENGTH_V2 =
8
APPENDIX_NO_CHANGE =

Appendix type constants

0x00
APPENDIX_GENERAL_NEW =
0x01
APPENDIX_NET_NEW =
0x02
APPENDIX_MODIFIED_NEW =
0x03

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ ParamBuilder

Returns a new instance of ParamBuilder.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/capi_param_builder.rb', line 38

def initialize(input = nil)
  @fbc_params_configs = [FbcParamConfigs.new("fbclid", "", "clickID")]
  @appendix_net_new = get_appendix(APPENDIX_NET_NEW)
  @appendix_modified_new = get_appendix(APPENDIX_MODIFIED_NEW)
  @appendix_no_change = get_appendix(APPENDIX_NO_CHANGE)

  if input.nil?
    return
  end

  if input.is_a?(Array)
    @domain_list = []
    input.each do |domain_item|
      @domain_list.push(extract_host_from_http_host(domain_item.downcase))
    end
  elsif input.is_a?(EtldPlusOneResolver)
    @etld_plus_one_resolver = input
  end
end

Instance Method Details

#get_cookies_to_setObject



203
204
205
# File 'lib/capi_param_builder.rb', line 203

def get_cookies_to_set()
  return @cookie_to_set
end

#get_fbcObject



207
208
209
# File 'lib/capi_param_builder.rb', line 207

def get_fbc()
  return @fbc
end

#get_fbpObject



211
212
213
# File 'lib/capi_param_builder.rb', line 211

def get_fbp()
  return @fbp
end

#process_request(host, queries, cookies, referer = nil) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/capi_param_builder.rb', line 177

def process_request(host, queries, cookies, referer=nil)
  compute_etld_plus_one_for_host(host)
  @cookie_to_set_dict = {}
  @cookie_to_set = Set.new()
  @fbc = pre_process_cookies(cookies, FBC_NAME)
  @fbp = pre_process_cookies(cookies, FBP_NAME)

  # Get new fbc payload
  new_fbc_payload = get_new_fbc_payload_from_url(queries, referer)

  # fbc update
  updated_fbc_cookie = get_updated_fbc_cookie(@fbc, new_fbc_payload)
  if !updated_fbc_cookie.nil?
    @cookie_to_set_dict[FBC_NAME] = updated_fbc_cookie
    @fbc = updated_fbc_cookie.value
  end
  # fbp update
  updated_fbp_cookie = get_updated_fbp_cookie(@fbp)
  if !updated_fbp_cookie.nil?
    @cookie_to_set_dict[FBP_NAME] = updated_fbp_cookie
    @fbp = updated_fbp_cookie.value
  end
  @cookie_to_set = Set.new(@cookie_to_set_dict.values)
  return @cookie_to_set
end