posthog-ruby 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/posthog/feature_flag.rb +2 -2
- data/lib/posthog/feature_flags.rb +38 -38
- data/lib/posthog/version.rb +1 -1
- metadata +6 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9be467263d4138e0b223e18281a9b0af56351fbf9d807b01bf4ff8f87d004a7
|
4
|
+
data.tar.gz: 1c4a9990d2958023b7db53511e64aa90ade5364d06e42e23b2b981d6acb59ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abde921140981a63fb82677e5024c4fcce79f9e560a870b0fd91114eaff0df1af0a5908742fbab3dee612d1d1a866998e9f1d10a587484e4baaf06b2f7cafd45
|
7
|
+
data.tar.gz: 7d88779cd59527ba500d8a2dcee0692a7135da88910d8045b276f32b635caee887b3fe2382a85fd6408b0e8cd57c58e0ca84495c99f912763a13f2b62e01dc78
|
data/lib/posthog/feature_flag.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Represents a feature flag returned by /
|
1
|
+
# Represents a feature flag returned by /flags v2
|
2
2
|
class FeatureFlag
|
3
3
|
attr_reader :key, :enabled, :variant, :reason, :metadata
|
4
4
|
|
@@ -43,7 +43,7 @@ class EvaluationReason
|
|
43
43
|
json.transform_keys!(&:to_s)
|
44
44
|
@code = json["code"]
|
45
45
|
@description = json["description"]
|
46
|
-
@condition_index = json["condition_index"]
|
46
|
+
@condition_index = json["condition_index"]&.to_i if json["condition_index"]
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,26 +51,26 @@ class PostHog
|
|
51
51
|
|
52
52
|
def get_feature_variants(distinct_id, groups={}, person_properties={}, group_properties={}, raise_on_error=false)
|
53
53
|
# TODO: Convert to options hash for easier argument passing
|
54
|
-
|
55
|
-
if !
|
56
|
-
logger.debug "Missing feature flags key: #{
|
54
|
+
flags_data = get_all_flags_and_payloads(distinct_id, groups, person_properties, group_properties, false, raise_on_error)
|
55
|
+
if !flags_data.key?(:featureFlags)
|
56
|
+
logger.debug "Missing feature flags key: #{flags_data.to_json}"
|
57
57
|
{}
|
58
58
|
else
|
59
|
-
stringify_keys(
|
59
|
+
stringify_keys(flags_data[:featureFlags] || {})
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def get_feature_payloads(distinct_id, groups = {}, person_properties = {}, group_properties = {}, only_evaluate_locally = false)
|
64
|
-
|
65
|
-
if !
|
66
|
-
logger.debug "Missing feature flag payloads key: #{
|
64
|
+
flags_data = get_all_flags_and_payloads(distinct_id, groups, person_properties, group_properties)
|
65
|
+
if !flags_data.key?(:featureFlagPayloads)
|
66
|
+
logger.debug "Missing feature flag payloads key: #{flags_data.to_json}"
|
67
67
|
return {}
|
68
68
|
else
|
69
|
-
stringify_keys(
|
69
|
+
stringify_keys(flags_data[:featureFlagPayloads] || {})
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
73
|
+
def get_flags(distinct_id, groups={}, person_properties={}, group_properties={})
|
74
74
|
request_data = {
|
75
75
|
"distinct_id": distinct_id,
|
76
76
|
"groups": groups,
|
@@ -78,26 +78,26 @@ class PostHog
|
|
78
78
|
"group_properties": group_properties,
|
79
79
|
}
|
80
80
|
|
81
|
-
|
81
|
+
flags_response = _request_feature_flag_evaluation(request_data)
|
82
82
|
|
83
83
|
# Only normalize if we have flags in the response
|
84
|
-
if
|
84
|
+
if flags_response[:flags]
|
85
85
|
#v4 format
|
86
|
-
flags_hash =
|
86
|
+
flags_hash = flags_response[:flags].transform_values do |flag|
|
87
87
|
FeatureFlag.new(flag)
|
88
88
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
elsif
|
89
|
+
flags_response[:flags] = flags_hash
|
90
|
+
flags_response[:featureFlags] = flags_hash.transform_values(&:get_value).transform_keys(&:to_sym)
|
91
|
+
flags_response[:featureFlagPayloads] = flags_hash.transform_values(&:payload).transform_keys(&:to_sym)
|
92
|
+
elsif flags_response[:featureFlags]
|
93
93
|
#v3 format
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
[key, FeatureFlag.from_value_and_payload(key, value,
|
94
|
+
flags_response[:featureFlags] = flags_response[:featureFlags] || {}
|
95
|
+
flags_response[:featureFlagPayloads] = flags_response[:featureFlagPayloads] || {}
|
96
|
+
flags_response[:flags] = flags_response[:featureFlags].map do |key, value|
|
97
|
+
[key, FeatureFlag.from_value_and_payload(key, value, flags_response[:featureFlagPayloads][key])]
|
98
98
|
end.to_h
|
99
99
|
end
|
100
|
-
|
100
|
+
flags_response
|
101
101
|
end
|
102
102
|
|
103
103
|
def get_remote_config_payload(flag_key)
|
@@ -143,13 +143,13 @@ class PostHog
|
|
143
143
|
|
144
144
|
if !flag_was_locally_evaluated && !only_evaluate_locally
|
145
145
|
begin
|
146
|
-
|
147
|
-
if !
|
148
|
-
logger.debug "Missing feature flags key: #{
|
146
|
+
flags_data = get_all_flags_and_payloads(distinct_id, groups, person_properties, group_properties, false, true)
|
147
|
+
if !flags_data.key?(:featureFlags)
|
148
|
+
logger.debug "Missing feature flags key: #{flags_data.to_json}"
|
149
149
|
flags = {}
|
150
150
|
else
|
151
|
-
flags = stringify_keys(
|
152
|
-
request_id =
|
151
|
+
flags = stringify_keys(flags_data[:featureFlags] || {})
|
152
|
+
request_id = flags_data[:requestId]
|
153
153
|
end
|
154
154
|
|
155
155
|
response = flags[key]
|
@@ -167,7 +167,7 @@ class PostHog
|
|
167
167
|
|
168
168
|
def get_all_flags(distinct_id, groups = {}, person_properties = {}, group_properties = {}, only_evaluate_locally = false)
|
169
169
|
if @quota_limited.true?
|
170
|
-
logger.debug "Not fetching flags from
|
170
|
+
logger.debug "Not fetching flags from server - quota limited"
|
171
171
|
return {}
|
172
172
|
end
|
173
173
|
# returns a string hash of all flags
|
@@ -180,8 +180,8 @@ class PostHog
|
|
180
180
|
|
181
181
|
flags = {}
|
182
182
|
payloads = {}
|
183
|
-
|
184
|
-
request_id = nil # Only for /
|
183
|
+
fallback_to_server = @feature_flags.empty?
|
184
|
+
request_id = nil # Only for /flags requests
|
185
185
|
|
186
186
|
@feature_flags.each do |flag|
|
187
187
|
begin
|
@@ -192,15 +192,15 @@ class PostHog
|
|
192
192
|
payloads[flag[:key]] = match_payload
|
193
193
|
end
|
194
194
|
rescue InconclusiveMatchError => e
|
195
|
-
|
195
|
+
fallback_to_server = true
|
196
196
|
rescue StandardError => e
|
197
197
|
@on_error.call(-1, "Error computing flag locally: #{e}. #{e.backtrace.join("\n")} ")
|
198
|
-
|
198
|
+
fallback_to_server = true
|
199
199
|
end
|
200
200
|
end
|
201
|
-
if
|
201
|
+
if fallback_to_server && !only_evaluate_locally
|
202
202
|
begin
|
203
|
-
flags_and_payloads =
|
203
|
+
flags_and_payloads = get_flags(distinct_id, groups, person_properties, group_properties)
|
204
204
|
|
205
205
|
unless flags_and_payloads.key?(:featureFlags)
|
206
206
|
raise StandardError.new("Error flags response: #{flags_and_payloads}")
|
@@ -240,8 +240,8 @@ class PostHog
|
|
240
240
|
response = _compute_flag_payload_locally(key, match_value)
|
241
241
|
end
|
242
242
|
if response == nil and !only_evaluate_locally
|
243
|
-
|
244
|
-
response =
|
243
|
+
flags_payloads = get_feature_payloads(distinct_id, groups, person_properties, group_properties)
|
244
|
+
response = flags_payloads[key.downcase] || nil
|
245
245
|
end
|
246
246
|
response
|
247
247
|
end
|
@@ -395,7 +395,7 @@ class PostHog
|
|
395
395
|
|
396
396
|
if group_name.nil?
|
397
397
|
logger.warn "[FEATURE FLAGS] Unknown group type index #{aggregation_group_type_index} for feature flag #{flag[:key]}"
|
398
|
-
# failover to `/
|
398
|
+
# failover to `/flags/`
|
399
399
|
raise InconclusiveMatchError.new("Flag has unknown group type index")
|
400
400
|
end
|
401
401
|
|
@@ -403,7 +403,7 @@ class PostHog
|
|
403
403
|
|
404
404
|
if !groups.key?(group_name_symbol)
|
405
405
|
# Group flags are never enabled if appropriate `groups` aren't passed in
|
406
|
-
# don't failover to `/
|
406
|
+
# don't failover to `/flags/`, since response will be the same
|
407
407
|
logger.warn "[FEATURE FLAGS] Can't compute group feature flag: #{flag[:key]} without group names passed in"
|
408
408
|
return false
|
409
409
|
end
|
@@ -566,7 +566,7 @@ class PostHog
|
|
566
566
|
end
|
567
567
|
|
568
568
|
def _request_feature_flag_evaluation(data={})
|
569
|
-
uri = URI("#{@host}/
|
569
|
+
uri = URI("#{@host}/flags/?v=2")
|
570
570
|
req = Net::HTTP::Post.new(uri)
|
571
571
|
req['Content-Type'] = 'application/json'
|
572
572
|
data['token'] = @project_api_key
|
data/lib/posthog/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posthog-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
|
+
autorequire:
|
8
9
|
bindir: bin
|
9
10
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-30 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: concurrent-ruby
|
@@ -121,20 +122,6 @@ dependencies:
|
|
121
122
|
- - "~>"
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: 0.51.0
|
124
|
-
- !ruby/object:Gem::Dependency
|
125
|
-
name: codecov
|
126
|
-
requirement: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: 0.6.0
|
131
|
-
type: :development
|
132
|
-
prerelease: false
|
133
|
-
version_requirements: !ruby/object:Gem::Requirement
|
134
|
-
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: 0.6.0
|
138
125
|
description: The PostHog ruby library
|
139
126
|
email: hey@posthog.com
|
140
127
|
executables:
|
@@ -165,6 +152,7 @@ homepage: https://github.com/PostHog/posthog-ruby
|
|
165
152
|
licenses:
|
166
153
|
- MIT
|
167
154
|
metadata: {}
|
155
|
+
post_install_message:
|
168
156
|
rdoc_options: []
|
169
157
|
require_paths:
|
170
158
|
- lib
|
@@ -179,7 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
167
|
- !ruby/object:Gem::Version
|
180
168
|
version: '0'
|
181
169
|
requirements: []
|
182
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.5.10
|
171
|
+
signing_key:
|
183
172
|
specification_version: 4
|
184
173
|
summary: PostHog library
|
185
174
|
test_files: []
|