amplitude-experiment 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff36301b51f9c519b85c5361aa6e50e45d0e55738ee6d36e10b3599e6b91b98b
4
- data.tar.gz: 6e03119d4dd2b6f33c4f0ba312043aac2eb688f211cf827a046d90457a40dcdb
3
+ metadata.gz: 53e7251a50e66bfd3145abbf399860592fec625dba57df40b84cd2f235a41fd3
4
+ data.tar.gz: 7405cf8193e72163cc9df7d216460e2eee5b3352ff255e97eed7ec7f5de7367a
5
5
  SHA512:
6
- metadata.gz: cf4ab1ee2bdc9dc1d40c0b95cbb2a6f4559a7473fa64997045bbb7b0bc9ac3a5c05cc5826a3f411198e3807f41e57de9c491cf44bbe2409c02fd368174d425a5
7
- data.tar.gz: 9fb0b7f55cde6e6e51774b5dc434c8f9ec4707b94a03576636a5bec115c23f4e60d09a93fb855595f41be65b8a9ef0b912c671587df16bbe5587950b267e3a5a
6
+ metadata.gz: cb9498e7a4bd0112e981732e136b2b6907fd34bc9c8bb645e41645c6074edcd891e95bee9919dc987bafdd4bd26969c07e6400884051375756dbb4524d83ba11
7
+ data.tar.gz: 990927832f1a67b211f982c4a350997d2a2cb91b0d2a62d605b412547e835404145b5546271f4af9dd75af4582b64fb887529f380c1ee4980ac9e81330e581c6
@@ -16,9 +16,10 @@ Gem::Specification.new do |spec|
16
16
  'amplitude-experiment.gemspec',
17
17
  'Gemfile',
18
18
  'lib/experiment/local/evaluation/lib/**/*']
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
  spec.extra_rdoc_files = ['README.md']
21
21
 
22
+ spec.add_development_dependency 'psych', '~> 4.0'
22
23
  spec.add_development_dependency 'rake', '~> 13.0'
23
24
  spec.add_development_dependency 'rdoc', '= 6.4'
24
25
  spec.add_development_dependency 'rspec', '~> 3.6'
@@ -26,7 +27,6 @@ Gem::Specification.new do |spec|
26
27
  spec.add_development_dependency 'simplecov', '~> 0.21'
27
28
  spec.add_development_dependency 'webmock', '~> 3.14'
28
29
  spec.add_development_dependency 'yard', '~> 0.9'
29
- spec.add_development_dependency 'psych', '~> 4.0'
30
30
  spec.metadata['rubygems_mfa_required'] = 'false'
31
31
  spec.add_runtime_dependency 'ffi', '~> 1.15.5'
32
32
  end
@@ -20,7 +20,7 @@ module AmplitudeExperiment
20
20
  else
21
21
  Logger::INFO
22
22
  end
23
- @fetcher = LocalEvaluationFetcher.new(api_key, @config.debug, @config.server_url)
23
+ @fetcher = LocalEvaluationFetcher.new(api_key, @logger, @config.server_url)
24
24
  raise ArgumentError, 'Experiment API key is empty' if @api_key.nil? || @api_key.empty?
25
25
  end
26
26
 
@@ -38,9 +38,9 @@ module AmplitudeExperiment
38
38
 
39
39
  user_str = user.to_json
40
40
  @logger.debug("[Experiment] Evaluate: User: #{user_str} - Rules: #{flags}") if @config.debug
41
- results_json = evaluation(flags, user_str)
42
- @logger.debug("[Experiment] evaluate - result: #{results_json}") if @config.debug
43
- parse_results_json(results_json, flag_keys)
41
+ result = evaluation(flags, user_str)
42
+ @logger.debug("[Experiment] evaluate - result: #{result}") if @config.debug
43
+ parse_results(result, flag_keys)
44
44
  end
45
45
 
46
46
  # Fetch initial flag configurations and start polling for updates.
@@ -61,8 +61,7 @@ module AmplitudeExperiment
61
61
 
62
62
  private
63
63
 
64
- def parse_results_json(results_json, flag_keys)
65
- result = JSON.parse(results_json)
64
+ def parse_results(result, flag_keys)
66
65
  variants = {}
67
66
  result.each do |key, value|
68
67
  next if value['isDefaultVariant'] || (flag_keys.empty? && flag_keys.include?(key))
@@ -1,5 +1,6 @@
1
1
  # rubocop:disable all
2
2
  require 'ffi'
3
+ require 'json'
3
4
 
4
5
  # The evaluation wrapper
5
6
  module EvaluationInterop
@@ -59,7 +60,13 @@ end
59
60
  def evaluation(rule_json, user_json)
60
61
  lib = EvaluationInterop.libevaluation_interop_symbols()
61
62
  fn = lib[:kotlin][:root][:evaluate]
62
- evaluation_result = fn.call(rule_json, user_json)
63
- evaluation_result.read_string
63
+ result_json = fn.call(rule_json, user_json).read_string
64
+ result = JSON.parse(result_json)
65
+ if result["error"] != nil
66
+ raise "#{result["error"]}"
67
+ elsif result["result"] == nil
68
+ raise "Evaluation result is nil."
69
+ end
70
+ result["result"]
64
71
  end
65
72
  # rubocop:disable all
@@ -5,11 +5,11 @@ module AmplitudeExperiment
5
5
  class LocalEvaluationFetcher
6
6
  FLAG_CONFIG_TIMEOUT = 5000
7
7
 
8
- def initialize(api_key, debug, server_url = 'https://api.lab.amplitude.com')
8
+ def initialize(api_key, logger, server_url = 'https://api.lab.amplitude.com')
9
9
  @api_key = api_key
10
10
  @server_url = server_url
11
- @debug = debug
12
- @http = PersistentHttpClient.get(server_url, { read_timeout: FLAG_CONFIG_TIMEOUT })
11
+ @logger = logger
12
+ @http = PersistentHttpClient.get(server_url, { read_timeout: FLAG_CONFIG_TIMEOUT })
13
13
  end
14
14
 
15
15
  # Fetch local evaluation mode flag configs from the Experiment API server.
@@ -27,7 +27,7 @@ module AmplitudeExperiment
27
27
  response = @http.request(request)
28
28
  raise "flagConfigs - received error response: #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPOK)
29
29
 
30
- @logger.debug("[Experiment] Fetch flag configs: #{response.body}") if @debug
30
+ @logger.debug("[Experiment] Fetch flag configs: #{response.body}")
31
31
  response.body
32
32
  end
33
33
 
@@ -47,7 +47,7 @@ module AmplitudeExperiment
47
47
  raise "flagConfigs - received error response: #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPOK)
48
48
 
49
49
  flag_configs = parse(response.body)
50
- @logger.debug("[Experiment] Fetch flag configs: #{request.body}") if @debug
50
+ @logger.debug("[Experiment] Fetch flag configs: #{request.body}")
51
51
  flag_configs
52
52
  end
53
53
 
@@ -1,3 +1,3 @@
1
1
  module AmplitudeExperiment
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplitude-experiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amplitude
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +122,6 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0.9'
111
- - !ruby/object:Gem::Dependency
112
- name: psych
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '4.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '4.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: ffi
127
127
  requirement: !ruby/object:Gem::Requirement