posthog-ruby 2.4.0 → 2.4.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: 82b54dc83e83826a9f0b9ba3b8fbacbdd6575f1f16bc2b1c051bdaf249501ef9
4
- data.tar.gz: aaea2cad50cc149f51224f4693edac7e177daaed821db12ba5a949fecb4d75d1
3
+ metadata.gz: f17b77ed0648665e282dc6f9483695eebcb955c08f4873350d5bbd01277c6534
4
+ data.tar.gz: e4e638cd17a013f3b3c1e012a5fd08f825fe6e43ce741050c31f7b084a718b96
5
5
  SHA512:
6
- metadata.gz: 8a0f8cf3a6f108d96cabea6e31d58a9a13894a49e2d16473e6439bcfa7b025c0a9ee9c7812c7ca6072b5e2f2e9ecedb8467c8e0ab75771e87e1cebbf7b2c5e24
7
- data.tar.gz: ab37a07e0cc7e98c274d8cbf708915a96af1c671b8016d1c6158f674583eff1c29b42cebee1ed780f1ba99ec611321d3a9765cac0b9104da759fc3f727822cfa
6
+ metadata.gz: 9b22dfa3f6765ffbfeb912d775ce5eee8ee4db21be2236dc13679d816c43fff161a707f33ff280ccc4d101e729d593fd909df8ff38c4d8ac8187da48071a506d
7
+ data.tar.gz: df159e86bc400f53d3d85b4068fc158f600fc32bc5015e022305d27d8cf65487ae946a90934fc7737efdc8086b387a9988883490d7298d261c9520c68c9e1078
@@ -174,6 +174,7 @@ class PostHog
174
174
  # group_properties: {"organization": {"name": "PostHog", "employees": 11}}
175
175
  # ```
176
176
  def get_feature_flag(key, distinct_id, groups: {}, person_properties: {}, group_properties: {}, only_evaluate_locally: false, send_feature_flag_events: true)
177
+ person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
177
178
  feature_flag_response, flag_was_locally_evaluated = @feature_flags_poller.get_feature_flag(key, distinct_id, groups, person_properties, group_properties, only_evaluate_locally)
178
179
 
179
180
  feature_flag_reported_key = "#{key}_#{feature_flag_response}"
@@ -204,6 +205,7 @@ class PostHog
204
205
  #
205
206
  # @return [Hash] String (not symbol) key value pairs of flag and their values
206
207
  def get_all_flags(distinct_id, groups: {}, person_properties: {}, group_properties: {}, only_evaluate_locally: false)
208
+ person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
207
209
  return @feature_flags_poller.get_all_flags(distinct_id, groups, person_properties, group_properties, only_evaluate_locally)
208
210
  end
209
211
 
@@ -218,6 +220,7 @@ class PostHog
218
220
  # @option [Boolean] only_evaluate_locally
219
221
  #
220
222
  def get_feature_flag_payload(key, distinct_id, match_value: nil, groups: {}, person_properties: {}, group_properties: {}, only_evaluate_locally: false)
223
+ person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
221
224
  @feature_flags_poller.get_feature_flag_payload(key, distinct_id, match_value, groups, person_properties, group_properties, only_evaluate_locally)
222
225
  end
223
226
 
@@ -230,6 +233,7 @@ class PostHog
230
233
  # @option [Boolean] only_evaluate_locally
231
234
  #
232
235
  def get_all_flags_and_payloads(distinct_id, groups: {}, person_properties: {}, group_properties: {}, only_evaluate_locally: false)
236
+ person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
233
237
  @feature_flags_poller.get_all_flags_and_payloads(distinct_id, groups, person_properties, group_properties, only_evaluate_locally)
234
238
  end
235
239
 
@@ -288,5 +292,32 @@ class PostHog
288
292
  def worker_running?
289
293
  @worker_thread && @worker_thread.alive?
290
294
  end
295
+
296
+ def add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
297
+
298
+ groups ||= {}
299
+ person_properties ||= {}
300
+ group_properties ||= {}
301
+
302
+ symbolize_keys! groups
303
+ symbolize_keys! person_properties
304
+ symbolize_keys! group_properties
305
+
306
+ group_properties.each do |key, value|
307
+ symbolize_keys! value
308
+ end
309
+
310
+ all_person_properties = { "distinct_id" => distinct_id }.merge(person_properties)
311
+
312
+ all_group_properties = {}
313
+ if groups
314
+ groups.each do |group_name, group_key|
315
+ all_group_properties[group_name] = {
316
+ "$group_key" => group_key}.merge(group_properties&.dig(group_name) || {})
317
+ end
318
+ end
319
+
320
+ return all_person_properties, all_group_properties
321
+ end
291
322
  end
292
323
  end
@@ -220,7 +220,7 @@ class PostHog
220
220
  end
221
221
 
222
222
  def self.relative_date_parse_for_feature_flag_matching(value)
223
- match = /^([0-9]+)([a-z])$/.match(value)
223
+ match = /^-?([0-9]+)([a-z])$/.match(value)
224
224
  parsed_dt = DateTime.now.new_offset(0)
225
225
  if match
226
226
  number = match[1].to_i
@@ -310,20 +310,20 @@ class PostHog
310
310
  else
311
311
  self.compare(override_value.to_s, value.to_s, operator)
312
312
  end
313
- when 'is_date_before', 'is_date_after', 'is_relative_date_before', 'is_relative_date_after'
314
- if operator == 'is_relative_date_before' || operator == 'is_relative_date_after'
315
- parsed_date = self.relative_date_parse_for_feature_flag_matching(value.to_s)
316
- override_date = PostHog::Utils.convert_to_datetime(override_value.to_s)
317
- else
313
+ when 'is_date_before', 'is_date_after'
314
+ override_date = PostHog::Utils.convert_to_datetime(override_value.to_s)
315
+ parsed_date = self.relative_date_parse_for_feature_flag_matching(value.to_s)
316
+
317
+ if parsed_date.nil?
318
318
  parsed_date = PostHog::Utils.convert_to_datetime(value.to_s)
319
- override_date = PostHog::Utils.convert_to_datetime(override_value.to_s)
320
319
  end
320
+
321
321
  if !parsed_date
322
322
  raise InconclusiveMatchError.new("Invalid date format")
323
323
  end
324
- if operator == 'is_date_before' or operator == 'is_relative_date_before'
324
+ if operator == 'is_date_before'
325
325
  return override_date < parsed_date
326
- elsif operator == 'is_date_after' or operator == 'is_relative_date_after'
326
+ elsif operator == 'is_date_after'
327
327
  return override_date > parsed_date
328
328
  end
329
329
  else
@@ -1,3 +1,3 @@
1
1
  class PostHog
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby