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 90cc972
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
absmartly-sdk (1.1.1)
absmartly-sdk (1.1.2)
faraday (~> 2.0)
faraday-retry (~> 2.0)
murmurhash3 (~> 0.1.7)
Expand Down
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
2 changes: 1 addition & 1 deletion lib/absmartly/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Absmartly
VERSION = "1.1.1"
VERSION = "1.1.2"
end

0 comments on commit 90cc972

Please sign in to comment.