posthog-ruby 1.2.3 → 1.3.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/client.rb +23 -4
- data/lib/posthog/field_parser.rb +2 -2
- data/lib/posthog/noop_worker.rb +16 -0
- data/lib/posthog/{worker.rb → send_worker.rb} +1 -1
- data/lib/posthog/version.rb +1 -1
- data/lib/posthog.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cc2c1e12c53fc80013ff8d49d082d1d35ad625fa0db972e53afbc205f595664
|
4
|
+
data.tar.gz: f95c1cb5502e0ae2d58e10b0575065fb797bbccd73d96098249a50ab6f60ee0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8947ba953b888db638dff4ee913fa697eb80d0ac4e8796a705143278bae9aef67d7d966cdb6112309e2a51b5432fe340676036f2756bcbef885f801c929de13d
|
7
|
+
data.tar.gz: c95c85e49f02acd99043120ccc6b7889b30553da9d968cdc08f7bfe13e130bd5f42380a68714c712f0444777a24bfcb29e252a28ce319f01242a362c9ca2e4e0
|
data/lib/posthog/client.rb
CHANGED
@@ -4,7 +4,8 @@ require 'time'
|
|
4
4
|
require 'posthog/defaults'
|
5
5
|
require 'posthog/logging'
|
6
6
|
require 'posthog/utils'
|
7
|
-
require 'posthog/
|
7
|
+
require 'posthog/send_worker'
|
8
|
+
require 'posthog/noop_worker'
|
8
9
|
require 'posthog/feature_flags'
|
9
10
|
|
10
11
|
class PostHog
|
@@ -15,7 +16,9 @@ class PostHog
|
|
15
16
|
# @param [Hash] opts
|
16
17
|
# @option opts [String] :api_key Your project's api_key
|
17
18
|
# @option opts [FixNum] :max_queue_size Maximum number of calls to be
|
18
|
-
# remain queued.
|
19
|
+
# remain queued. Defaults to 10_000.
|
20
|
+
# @option opts [Bool] :test_mode +true+ if messages should remain
|
21
|
+
# queued for testing. Defaults to +false+.
|
19
22
|
# @option opts [Proc] :on_error Handles error calls from the API.
|
20
23
|
def initialize(opts = {})
|
21
24
|
symbolize_keys!(opts)
|
@@ -24,7 +27,11 @@ class PostHog
|
|
24
27
|
@api_key = opts[:api_key]
|
25
28
|
@max_queue_size = opts[:max_queue_size] || Defaults::Queue::MAX_SIZE
|
26
29
|
@worker_mutex = Mutex.new
|
27
|
-
@worker =
|
30
|
+
@worker = if opts[:test_mode]
|
31
|
+
NoopWorker.new(@queue)
|
32
|
+
else
|
33
|
+
SendWorker.new(@queue, @api_key, opts)
|
34
|
+
end
|
28
35
|
@worker_thread = nil
|
29
36
|
@feature_flags_poller = nil
|
30
37
|
@personal_api_key = nil
|
@@ -45,7 +52,7 @@ class PostHog
|
|
45
52
|
at_exit { @worker_thread && @worker_thread[:should_exit] = true }
|
46
53
|
end
|
47
54
|
|
48
|
-
# Synchronously waits until the worker has
|
55
|
+
# Synchronously waits until the worker has cleared the queue.
|
49
56
|
#
|
50
57
|
# Use only for scripts which are not long-running, and will specifically
|
51
58
|
# exit
|
@@ -56,6 +63,13 @@ class PostHog
|
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
# Clears the queue without waiting.
|
67
|
+
#
|
68
|
+
# Use only in test mode
|
69
|
+
def clear
|
70
|
+
@queue.clear
|
71
|
+
end
|
72
|
+
|
59
73
|
# @!macro common_attrs
|
60
74
|
# @option attrs [String] :message_id ID that uniquely
|
61
75
|
# identifies a message across the API. (optional)
|
@@ -96,6 +110,11 @@ class PostHog
|
|
96
110
|
enqueue(FieldParser.parse_for_alias(attrs))
|
97
111
|
end
|
98
112
|
|
113
|
+
# @return [Hash] pops the last message from the queue
|
114
|
+
def dequeue_last_message
|
115
|
+
@queue.pop
|
116
|
+
end
|
117
|
+
|
99
118
|
# @return [Fixnum] number of messages in the queue
|
100
119
|
def queued_messages
|
101
120
|
@queue.length
|
data/lib/posthog/field_parser.rb
CHANGED
@@ -54,7 +54,7 @@ class PostHog
|
|
54
54
|
def parse_for_alias(fields)
|
55
55
|
common = parse_common_fields(fields)
|
56
56
|
|
57
|
-
distinct_id = common[:distinct_id] # must move to properties
|
57
|
+
distinct_id = common[:distinct_id] # must both be set and move to properties
|
58
58
|
|
59
59
|
alias_field = fields[:alias]
|
60
60
|
check_presence! alias_field, 'alias'
|
@@ -63,7 +63,7 @@ class PostHog
|
|
63
63
|
{
|
64
64
|
type: 'alias',
|
65
65
|
event: '$create_alias',
|
66
|
-
distinct_id:
|
66
|
+
distinct_id: distinct_id,
|
67
67
|
properties:
|
68
68
|
{ distinct_id: distinct_id, alias: alias_field }.merge(
|
69
69
|
common[:properties] || {}
|
data/lib/posthog/version.rb
CHANGED
data/lib/posthog.rb
CHANGED
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -153,16 +153,17 @@ files:
|
|
153
153
|
- lib/posthog/field_parser.rb
|
154
154
|
- lib/posthog/logging.rb
|
155
155
|
- lib/posthog/message_batch.rb
|
156
|
+
- lib/posthog/noop_worker.rb
|
156
157
|
- lib/posthog/response.rb
|
158
|
+
- lib/posthog/send_worker.rb
|
157
159
|
- lib/posthog/transport.rb
|
158
160
|
- lib/posthog/utils.rb
|
159
161
|
- lib/posthog/version.rb
|
160
|
-
- lib/posthog/worker.rb
|
161
162
|
homepage: https://github.com/PostHog/posthog-ruby
|
162
163
|
licenses:
|
163
164
|
- MIT
|
164
165
|
metadata: {}
|
165
|
-
post_install_message:
|
166
|
+
post_install_message:
|
166
167
|
rdoc_options: []
|
167
168
|
require_paths:
|
168
169
|
- lib
|
@@ -177,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
178
|
- !ruby/object:Gem::Version
|
178
179
|
version: '0'
|
179
180
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
181
|
-
signing_key:
|
181
|
+
rubygems_version: 3.1.6
|
182
|
+
signing_key:
|
182
183
|
specification_version: 4
|
183
184
|
summary: PostHog library
|
184
185
|
test_files: []
|