Skip to content

Commit

Permalink
Support create context with given context data.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermeswaldemarin committed Jul 30, 2024
1 parent e647628 commit d2af1b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
35 changes: 35 additions & 0 deletions example/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,38 @@
ctx.track("payment", properties)

ctx.close

context_data = Absmartly.context_data
ctx2 = Absmartly.create_context_with(context_config, context_data)

treatment = ctx2.treatment("exp_test_ab")
puts(treatment) # 0
treatment1 = ctx2.treatment("net_seasons")
puts(treatment1) # 1
treatment2 = ctx2.treatment("Experimento!")
puts(treatment2) # 1
treatment3 = ctx2.treatment("test")
puts(treatment3) # 1

ctx2.set_unit("db_user_id", 1000013)
ctx2.set_units(db_user_id2: 1000013, session_id2: 12311)

ctx2.set_attribute("user_agent", "Chrome 2022")
ctx2.set_attributes(
customer_age: "new_customer",
customer_point: 20,
)

ctx2.set_override("new_exp", 3)
ctx2.set_overrides(
exp_test_experiment: 1,
exp_another_experiment: 0,
)
ctx2.publish
properties = {
value: 125,
fee: 125
}
ctx2.track("payment", properties)

ctx2.close
2 changes: 1 addition & 1 deletion lib/a_b_smartly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_context(config)
end

def create_context_with(config, data)
Context.create(get_utc_format, config, scheduler, data,
Context.create(get_utc_format, config, data,
@context_data_provider, @context_event_handler, @context_event_logger, @variable_parser,
AudienceMatcher.new(@audience_deserializer))
end
Expand Down
8 changes: 8 additions & 0 deletions lib/absmartly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def create_context(context_config)
sdk.create_context(context_config)
end

def create_context_with(context_config, data)
sdk.create_context_with(context_config, data)
end

def context_data
sdk.context_data
end

private
def client_config
@client_config = ClientConfig.create
Expand Down

0 comments on commit d2af1b6

Please sign in to comment.