posthog-ruby 2.3.0 → 2.4.0

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: d80e39f962a2bba799e013b2dfdcd88ab25a7b777d2185e8ef03c2c53446c7c0
4
- data.tar.gz: 9550b79aad4b9c18c3870f0fa684181ce197e5fdaa5dbb3db7bba40c85005e6c
3
+ metadata.gz: 82b54dc83e83826a9f0b9ba3b8fbacbdd6575f1f16bc2b1c051bdaf249501ef9
4
+ data.tar.gz: aaea2cad50cc149f51224f4693edac7e177daaed821db12ba5a949fecb4d75d1
5
5
  SHA512:
6
- metadata.gz: 35f6eb8128e2ff82739a7d9cdeb5f99b0a0a4c5923c7d295c17bedcccb44f562040e429f08c78cc1621ac6f35df46f6fecb6176505ffcff83540b8bb74d3a119
7
- data.tar.gz: ecb9bb5e660722b07e16f765a920f642b5ff7b3a1a20ad9b20c3db12c1646ee6dd706e3696106d23f73e51f6fa15894b0fd03f09470cfe1dcb7b432fb3c36738
6
+ metadata.gz: 8a0f8cf3a6f108d96cabea6e31d58a9a13894a49e2d16473e6439bcfa7b025c0a9ee9c7812c7ca6072b5e2f2e9ecedb8467c8e0ab75771e87e1cebbf7b2c5e24
7
+ data.tar.gz: ab37a07e0cc7e98c274d8cbf708915a96af1c671b8016d1c6158f674583eff1c29b42cebee1ed780f1ba99ec611321d3a9765cac0b9104da759fc3f727822cfa
@@ -15,6 +15,7 @@ class PostHog
15
15
 
16
16
  # @param [Hash] opts
17
17
  # @option opts [String] :api_key Your project's api_key
18
+ # @option opts [String] :personal_api_key Your personal API key
18
19
  # @option opts [FixNum] :max_queue_size Maximum number of calls to be
19
20
  # remain queued. Defaults to 10_000.
20
21
  # @option opts [Bool] :test_mode +true+ if messages should remain
@@ -205,6 +205,52 @@ class PostHog
205
205
 
206
206
  # Class methods
207
207
 
208
+ def self.compare(lhs, rhs, operator)
209
+ if operator == "gt"
210
+ return lhs > rhs
211
+ elsif operator == "gte"
212
+ return lhs >= rhs
213
+ elsif operator == "lt"
214
+ return lhs < rhs
215
+ elsif operator == "lte"
216
+ return lhs <= rhs
217
+ else
218
+ raise "Invalid operator: #{operator}"
219
+ end
220
+ end
221
+
222
+ def self.relative_date_parse_for_feature_flag_matching(value)
223
+ match = /^([0-9]+)([a-z])$/.match(value)
224
+ parsed_dt = DateTime.now.new_offset(0)
225
+ if match
226
+ number = match[1].to_i
227
+
228
+ if number >= 10000
229
+ # Guard against overflow, disallow numbers greater than 10_000
230
+ return nil
231
+ end
232
+
233
+ interval = match[2]
234
+ if interval == "h"
235
+ parsed_dt = parsed_dt - (number/24r)
236
+ elsif interval == "d"
237
+ parsed_dt = parsed_dt.prev_day(number)
238
+ elsif interval == "w"
239
+ parsed_dt = parsed_dt.prev_day(number*7)
240
+ elsif interval == "m"
241
+ parsed_dt = parsed_dt.prev_month(number)
242
+ elsif interval == "y"
243
+ parsed_dt = parsed_dt.prev_year(number)
244
+ else
245
+ return nil
246
+ end
247
+ parsed_dt
248
+ else
249
+ nil
250
+ end
251
+ end
252
+
253
+
208
254
  def self.match_property(property, property_values)
209
255
  # only looks for matches where key exists in property_values
210
256
  # doesn't support operator is_not_set
@@ -225,11 +271,21 @@ class PostHog
225
271
  override_value = property_values[key]
226
272
 
227
273
  case operator
228
- when 'exact'
229
- value.is_a?(Array) ? value.include?(override_value) : value == override_value
230
- when 'is_not'
231
- value.is_a?(Array) ? !value.include?(override_value) : value != override_value
232
- when'is_set'
274
+ when 'exact', 'is_not'
275
+ if value.is_a?(Array)
276
+ values_stringified = value.map { |val| val.to_s.downcase }
277
+ if operator == 'exact'
278
+ return values_stringified.any?(override_value.to_s.downcase)
279
+ else
280
+ return !values_stringified.any?(override_value.to_s.downcase)
281
+ end
282
+ end
283
+ if operator == 'exact'
284
+ value.to_s.downcase == override_value.to_s.downcase
285
+ else
286
+ value.to_s.downcase != override_value.to_s.downcase
287
+ end
288
+ when 'is_set'
233
289
  property_values.key?(key)
234
290
  when 'icontains'
235
291
  override_value.to_s.downcase.include?(value.to_s.downcase)
@@ -239,25 +295,39 @@ class PostHog
239
295
  PostHog::Utils.is_valid_regex(value.to_s) && !Regexp.new(value.to_s).match(override_value.to_s).nil?
240
296
  when 'not_regex'
241
297
  PostHog::Utils.is_valid_regex(value.to_s) && Regexp.new(value.to_s).match(override_value.to_s).nil?
242
- when 'gt'
243
- override_value.class == value.class && override_value > value
244
- when 'gte'
245
- override_value.class == value.class && override_value >= value
246
- when 'lt'
247
- override_value.class == value.class && override_value < value
248
- when 'lte'
249
- override_value.class == value.class && override_value <= value
250
- when 'is_date_before', 'is_date_after'
251
- parsed_date = PostHog::Utils::convert_to_datetime(value)
252
- override_date = PostHog::Utils::convert_to_datetime(override_value)
253
- if operator == 'is_date_before'
254
- return override_date < parsed_date
298
+ when 'gt', 'gte', 'lt', 'lte'
299
+ parsed_value = nil
300
+ begin
301
+ parsed_value = Float(value)
302
+ rescue StandardError => e
303
+ end
304
+ if !parsed_value.nil? && !override_value.nil?
305
+ if override_value.is_a?(String)
306
+ self.compare(override_value, value.to_s, operator)
307
+ else
308
+ self.compare(override_value, parsed_value, operator)
309
+ end
310
+ else
311
+ self.compare(override_value.to_s, value.to_s, operator)
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)
255
317
  else
318
+ parsed_date = PostHog::Utils.convert_to_datetime(value.to_s)
319
+ override_date = PostHog::Utils.convert_to_datetime(override_value.to_s)
320
+ end
321
+ if !parsed_date
322
+ raise InconclusiveMatchError.new("Invalid date format")
323
+ end
324
+ if operator == 'is_date_before' or operator == 'is_relative_date_before'
325
+ return override_date < parsed_date
326
+ elsif operator == 'is_date_after' or operator == 'is_relative_date_after'
256
327
  return override_date > parsed_date
257
328
  end
258
329
  else
259
- logger.error "Unknown operator: #{operator}"
260
- false
330
+ raise InconclusiveMatchError.new("Unknown operator: #{operator}")
261
331
  end
262
332
  end
263
333
 
@@ -1,3 +1,3 @@
1
1
  class PostHog
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
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.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubygems_version: 3.0.3.1
181
+ rubygems_version: 3.1.2
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: PostHog library