altertable 1.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6578d35fc3a2278e59800c3e1856da5f5a569b8051d912d4dff7f0485fde74e9
4
- data.tar.gz: f29994d0c964d70e1f45b000e1fc19ef5ae8b7ce1464d46f3f423374e4d17c15
3
+ metadata.gz: e63f277260656f5e0ed3c5696ae4fc974f99ddbbc75a6e983917d60d1b7af644
4
+ data.tar.gz: d52d275511b219aa0df3e8d9ee42e30830f3fb9fa399fe91a8198e35c15bbbc3
5
5
  SHA512:
6
- metadata.gz: '029043ea4734d6ef374f7a426fc48c0b2a387c40d2cd6c5db332e0fef769da063a9ef884ecef6b6538a92d62830b92ddf6b9b76e3753552014332977cc56cc5d'
7
- data.tar.gz: 9d517e40f86b34ad5985df17c4ed1511d0c0e0bc8231e24f2fae2a3bf698fc34838ac4d7291a07f9ae1c18a4e520c481c5c9c84c6d605e982f226c6f7147fca2
6
+ metadata.gz: '0295a9615766d0fa8487568349a705705211cfb511087c0e79de3a6ac1804b3d33280e24167a7511dee768edb9f27f9c3fc83107af303af44ac62f5b519f8802'
7
+ data.tar.gz: de4d98a9ef278872d585e56941754d0a7b7515eb91065a2545f6e5e403b2d3eb5412c65cce24617426458aee040e03b4cd54f1775d4b28ac33f285cc311a236b
@@ -0,0 +1 @@
1
+ github: [altertable-ai]
@@ -37,7 +37,7 @@ body:
37
37
  - type: input
38
38
  id: runtime
39
39
  attributes:
40
- label: "{language} Version"
40
+ label: "Ruby Version"
41
41
  validations:
42
42
  required: true
43
43
  - type: dropdown
@@ -0,0 +1,13 @@
1
+ ## What
2
+
3
+ <!-- What does this PR do? One sentence is fine. -->
4
+
5
+ ## Why
6
+
7
+ <!-- Link an issue or explain the motivation. -->
8
+
9
+ ## Checklist
10
+
11
+ - [ ] Tests added or updated
12
+ - [ ] `CHANGELOG.md` updated (skip for docs/CI-only changes)
13
+ - [ ] Breaking change noted in commit footer (`BREAKING CHANGE: …`) and changelog
@@ -6,11 +6,11 @@ on:
6
6
  pull_request: {}
7
7
  jobs:
8
8
  lint:
9
- runs-on: ubuntu-latest
9
+ runs-on: ubuntu-24.04
10
10
  steps:
11
- - uses: actions/checkout@v4
11
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
12
12
  - name: Set up Ruby
13
- uses: ruby/setup-ruby@v1
13
+ uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1
14
14
  with:
15
15
  ruby-version: "3.4"
16
16
  bundler-cache: true
@@ -18,7 +18,7 @@ jobs:
18
18
  run: bundle exec rubocop
19
19
 
20
20
  test:
21
- runs-on: ubuntu-latest
21
+ runs-on: ubuntu-24.04
22
22
  strategy:
23
23
  matrix:
24
24
  ruby-version: ["3.2", "3.3", "3.4", "4.0"]
@@ -38,12 +38,12 @@ jobs:
38
38
  --health-start-period 10s
39
39
 
40
40
  steps:
41
- - uses: actions/checkout@v4
41
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
42
42
  with:
43
43
  submodules: recursive
44
44
 
45
45
  - name: Set up Ruby
46
- uses: ruby/setup-ruby@v1
46
+ uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1
47
47
  with:
48
48
  ruby-version: ${{ matrix.ruby-version }}
49
49
  bundler-cache: true
@@ -53,11 +53,11 @@ jobs:
53
53
 
54
54
  typing:
55
55
  name: "Typing"
56
- runs-on: ubuntu-latest
56
+ runs-on: ubuntu-24.04
57
57
  steps:
58
- - uses: actions/checkout@v4
58
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
59
59
  - name: Set up Ruby
60
- uses: ruby/setup-ruby@v1
60
+ uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1
61
61
  with:
62
62
  ruby-version: "3.4"
63
63
  bundler-cache: true
@@ -7,14 +7,14 @@ on:
7
7
 
8
8
  jobs:
9
9
  check:
10
- runs-on: ubuntu-latest
10
+ runs-on: ubuntu-24.04
11
11
 
12
12
  permissions:
13
13
  contents: write
14
14
  pull-requests: write
15
15
 
16
16
  steps:
17
- - uses: googleapis/release-please-action@v4
17
+ - uses: googleapis/release-please-action@8b8fd2cc23b2e18957157a9d923d75aa0c6f6ad5 # v4
18
18
  id: release
19
19
  with:
20
20
  token: ${{ secrets.GITHUB_TOKEN }}
@@ -29,7 +29,7 @@ jobs:
29
29
 
30
30
  if: ${{ needs.check.outputs.release_created }}
31
31
 
32
- runs-on: ubuntu-latest
32
+ runs-on: ubuntu-24.04
33
33
 
34
34
  permissions:
35
35
  contents: write
@@ -37,11 +37,11 @@ jobs:
37
37
  id-token: write
38
38
 
39
39
  steps:
40
- - uses: actions/checkout@v4
40
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
41
41
  with:
42
42
  persist-credentials: false
43
- - uses: ruby/setup-ruby@v1
43
+ - uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1
44
44
  with:
45
45
  ruby-version: 3.4
46
46
  bundler-cache: true
47
- - uses: rubygems/release-gem@v1
47
+ - uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1
@@ -1,4 +1,5 @@
1
1
  name: Semantic Pull Request
2
+
2
3
  on:
3
4
  pull_request_target:
4
5
  types:
@@ -6,11 +7,33 @@ on:
6
7
  - edited
7
8
  - synchronize
8
9
 
10
+ permissions:
11
+ pull-requests: read
12
+
13
+ concurrency:
14
+ group: semantic-pr-${{ github.event.pull_request.number }}
15
+ cancel-in-progress: true
16
+
9
17
  jobs:
10
18
  main:
11
19
  name: Validate PR title
12
- runs-on: ubuntu-latest
20
+ runs-on: ubuntu-24.04
21
+ timeout-minutes: 5
13
22
  steps:
14
- - uses: amannn/action-semantic-pull-request@v5
23
+ - name: Validate pull request title
24
+ uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
15
25
  env:
16
26
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+ with:
28
+ types: |
29
+ feat
30
+ fix
31
+ perf
32
+ revert
33
+ docs
34
+ style
35
+ chore
36
+ refactor
37
+ test
38
+ build
39
+ ci
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.1.2"
2
+ ".": "1.3.0"
3
3
  }
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.0](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.2.0...altertable/v1.3.0) (2026-09-04)
4
+
5
+
6
+ ### Features
7
+
8
+ * **client:** add batch track, identify, and alias ([#53](https://github.com/altertable-ai/altertable-ruby/issues/53)) ([2aff25b](https://github.com/altertable-ai/altertable-ruby/commit/2aff25b8b6f8767da113fce38901160dffbd9733))
9
+
10
+ ## [1.2.0](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.1.2...altertable/v1.2.0) (2026-08-27)
11
+
12
+
13
+ ### Features
14
+
15
+ * **adapters:** support explicit proxy configuration ([#51](https://github.com/altertable-ai/altertable-ruby/issues/51)) ([309aa8f](https://github.com/altertable-ai/altertable-ruby/commit/309aa8f43c43f57cf87cf23a6d1034298612b0be))
16
+
3
17
  ## [1.1.2](https://github.com/altertable-ai/altertable-ruby/compare/altertable/v1.1.1...altertable/v1.1.2) (2026-03-19)
4
18
 
5
19
 
data/CODE_OF_CONDUCT.md CHANGED
@@ -70,14 +70,14 @@ Community leaders will follow these Community Impact Guidelines in determining t
70
70
 
71
71
  ## Attribution
72
72
 
73
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
73
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct/][v2.1].
74
74
 
75
75
  Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
76
76
 
77
- For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
77
+ For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq/][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations/][translations].
78
78
 
79
79
  [homepage]: https://www.contributor-covenant.org
80
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
81
- [Mozilla CoC]: https://github.com/mozilla/diversity
82
- [FAQ]: https://www.contributor-covenant.org/faq
83
- [translations]: https://www.contributor-covenant.org/translations
80
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct/
81
+ [Mozilla CoC]: https://github.com/mozilla/inclusion
82
+ [FAQ]: https://www.contributor-covenant.org/faq/
83
+ [translations]: https://www.contributor-covenant.org/translations/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- altertable (1.1.2)
4
+ altertable (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -47,38 +47,67 @@ Altertable.init('pk_live_abc123', environment: 'production', debug: true)
47
47
 
48
48
  Record an action performed by a user.
49
49
 
50
- `Altertable.track(event, distinct_id, **options)`
50
+ `Altertable.track(event, distinct_id, **options)`
51
+ `Altertable.track(event_payload, **options)`
52
+ `Altertable.track(event_payloads, **options)`
51
53
 
52
54
  ```ruby
53
55
  Altertable.track('item_purchased', 'user_123', properties: {
54
56
  item_id: 'item_999',
55
57
  price: 19.99
56
58
  })
59
+
60
+ Altertable.track({
61
+ event: 'item_purchased',
62
+ distinct_id: 'user_123',
63
+ properties: { item_id: 'item_999', price: 19.99 }
64
+ })
65
+
66
+ Altertable.track([
67
+ { event: 'signup', distinct_id: 'user_1', properties: { plan: 'pro' } },
68
+ { event: 'login', distinct_id: 'user_2', timestamp: '2025-06-15T14:30:00.000Z' }
69
+ ])
57
70
  ```
58
71
 
59
72
  ### Identifying Users
60
73
 
61
74
  Link a user ID to their traits (like email or name).
62
75
 
63
- `Altertable.identify(user_id, **options)`
76
+ `Altertable.identify(user_id, **options)`
77
+ `Altertable.identify(identify_payload, **options)`
78
+ `Altertable.identify(identify_payloads, **options)`
64
79
 
65
80
  ```ruby
66
81
  Altertable.identify('user_123', traits: {
67
82
  email: 'user@example.com',
68
83
  name: 'John Doe'
69
84
  })
85
+
86
+ Altertable.identify([
87
+ { user_id: 'user_1', traits: { email: 'one@example.com' } },
88
+ { user_id: 'user_2', traits: { email: 'two@example.com' } }
89
+ ])
70
90
  ```
71
91
 
72
92
  ### Alias
73
93
 
74
94
  Merge a previous anonymous ID with a newly identified user ID.
75
95
 
76
- `Altertable.alias(distinct_id, new_user_id, **options)`
96
+ `Altertable.alias(distinct_id, new_user_id, **options)`
97
+ `Altertable.alias(alias_payload, **options)`
98
+ `Altertable.alias(alias_payloads, **options)`
77
99
 
78
100
  ```ruby
79
101
  Altertable.alias('anon_session_456', 'user_123')
102
+
103
+ Altertable.alias([
104
+ { distinct_id: 'anon_1', new_user_id: 'user_1' },
105
+ { distinct_id: 'anon_2', new_user_id: 'user_2' }
106
+ ])
80
107
  ```
81
108
 
109
+ A Hash payload posts one object; an Array posts a JSON array on the same endpoint. Omitted `timestamp` values default to the current time as ISO 8601.
110
+
82
111
  ## Configuration
83
112
 
84
113
  You can configure the client by passing options during initialization.
@@ -92,6 +121,7 @@ You can configure the client by passing options during initialization.
92
121
  | `debug` | Boolean | `false` | Enable debug logging. |
93
122
  | `on_error` | Proc | `nil` | Callback for handling errors. |
94
123
  | `adapter` | Symbol | auto-detect | HTTP adapter to use (`:faraday`, `:httpx`, `:net_http`). |
124
+ | `proxy` | String, Boolean | adapter default | Proxy to use for requests. Pass a URI string to force a specific proxy, or `false` to disable proxying (including any `HTTP_PROXY`/`HTTPS_PROXY` environment variables) for a fixed, trusted `base_url`. Unset by default: the `:faraday` and `:net_http` adapters auto-detect a proxy from the environment as they normally would; `:httpx` never does. |
95
125
 
96
126
  ## License
97
127
 
data/SECURITY.md CHANGED
@@ -8,7 +8,7 @@ Only the latest minor release receives security patches.
8
8
 
9
9
  **Do not open a public issue.**
10
10
 
11
- Email security@altertable.ai with:
11
+ Email <security@altertable.ai> with:
12
12
 
13
13
  1. Description of the vulnerability
14
14
  2. Steps to reproduce
@@ -15,13 +15,17 @@ module Altertable
15
15
  end
16
16
 
17
17
  class FaradayAdapter < Base
18
- def initialize(base_url:, timeout:, headers: {})
19
- super
18
+ # proxy left unset (default) follows Faraday's own env-based auto-detection
19
+ # (HTTP_PROXY/HTTPS_PROXY/NO_PROXY). Pass `false` to disable proxying entirely for
20
+ # fixed, trusted destinations, or a URI string to force a specific proxy.
21
+ def initialize(base_url:, timeout:, headers: {}, proxy: nil)
22
+ super(base_url: base_url, timeout: timeout, headers: headers)
20
23
  require "faraday"
21
-
24
+
22
25
  @conn = Faraday.new(url: @base_url) do |f|
23
26
  @headers.each { |k, v| f.headers[k] = v }
24
27
  f.options.timeout = @timeout
28
+ f.proxy = proxy unless proxy.nil?
25
29
  f.adapter Faraday.default_adapter
26
30
  end
27
31
  end
@@ -46,10 +50,14 @@ module Altertable
46
50
  end
47
51
 
48
52
  class HttpxAdapter < Base
49
- def initialize(base_url:, timeout:, headers: {})
50
- super
53
+ # This adapter never auto-detects HTTP_PROXY/HTTPS_PROXY (httpx requires the :proxy
54
+ # plugin to be loaded explicitly). `proxy: false` and the default (unset) are
55
+ # therefore equivalent; pass a URI string to force a specific proxy.
56
+ def initialize(base_url:, timeout:, headers: {}, proxy: nil)
57
+ super(base_url: base_url, timeout: timeout, headers: headers)
51
58
  require "httpx"
52
- @client = HTTPX.plugin(:retries).with(
59
+ client = proxy ? HTTPX.plugin(:proxy).plugin(:retries).with(proxy: { uri: proxy }) : HTTPX.plugin(:retries)
60
+ @client = client.with(
53
61
  timeout: { operation_timeout: @timeout },
54
62
  headers: @headers,
55
63
  base_url: @base_url
@@ -74,11 +82,15 @@ module Altertable
74
82
  end
75
83
 
76
84
  class NetHttpAdapter < Base
77
- def initialize(base_url:, timeout:, headers: {})
78
- super
85
+ # proxy left unset (default) follows Net::HTTP's own env-based auto-detection
86
+ # (HTTP_PROXY/HTTPS_PROXY/NO_PROXY). Pass `false` to disable proxying entirely for
87
+ # fixed, trusted destinations, or a URI string to force a specific proxy.
88
+ def initialize(base_url:, timeout:, headers: {}, proxy: nil)
89
+ super(base_url: base_url, timeout: timeout, headers: headers)
79
90
  require "net/http"
80
91
  require "uri"
81
92
  @uri = URI.parse(@base_url)
93
+ @proxy = proxy
82
94
  end
83
95
 
84
96
  def post(path, body: nil, params: {})
@@ -89,7 +101,7 @@ module Altertable
89
101
  @headers.each { |k, v| req[k] = v }
90
102
  req.body = body if body
91
103
 
92
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: @timeout, read_timeout: @timeout) do |http|
104
+ Net::HTTP.start(uri.host, uri.port, *proxy_start_args, use_ssl: uri.scheme == "https", open_timeout: @timeout, read_timeout: @timeout) do |http|
93
105
  resp = http.request(req)
94
106
  Response.new(resp.code.to_i, resp.body, resp.to_hash)
95
107
  end
@@ -98,6 +110,18 @@ module Altertable
98
110
  rescue StandardError => e
99
111
  raise Altertable::NetworkError.new(e.message, e)
100
112
  end
113
+
114
+ private
115
+
116
+ # Net::HTTP.start's p_addr defaults to :ENV; returning [] here preserves that.
117
+ # Passing an explicit nil p_addr (i.e. [nil]) is how Net::HTTP disables proxying.
118
+ def proxy_start_args
119
+ return [] if @proxy.nil?
120
+ return [nil] if @proxy == false
121
+
122
+ proxy_uri = URI.parse(@proxy)
123
+ [proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password]
124
+ end
101
125
  end
102
126
  end
103
127
  end
@@ -28,54 +28,43 @@ module Altertable
28
28
  "X-API-Key" => @api_key,
29
29
  "Content-Type" => "application/json"
30
30
  }
31
- @adapter = select_adapter(adapter_name, { base_url: @base_url, timeout: @timeout, headers: headers })
31
+ @adapter = select_adapter(adapter_name, { base_url: @base_url, timeout: @timeout, headers: headers, proxy: options[:proxy] })
32
32
  end
33
33
 
34
- def track(event, distinct_id, **options)
35
- properties = options[:properties] || {}
36
- timestamp = options[:timestamp] || Time.now.utc.iso8601(3)
37
- payload = {
38
- timestamp: timestamp,
39
- event: event,
40
- environment: @environment,
41
- distinct_id: distinct_id,
42
- properties: {
43
- '$lib': "altertable-ruby",
44
- '$lib_version': Altertable::VERSION
45
- }.merge(properties)
46
- }
47
- payload[:properties]["$release"] = @release if @release
48
- payload[:anonymous_id] = options[:anonymous_id] if options.key?(:anonymous_id)
49
- payload[:device_id] = options[:device_id] if options.key?(:device_id)
50
-
51
- post("/track", payload)
34
+ def track(event, distinct_id = nil, **options)
35
+ case event
36
+ when Array
37
+ payloads = map_batch(event, "events") { |item| track_payload_from_item(merge_payload(item, options)) }
38
+ post("/track", payloads)
39
+ when Hash
40
+ post("/track", track_payload_from_item(merge_payload(event, options)))
41
+ else
42
+ post("/track", track_payload(event, distinct_id, options))
43
+ end
52
44
  end
53
45
 
54
46
  def identify(user_id, **options)
55
- traits = options[:traits] || {}
56
- timestamp = options[:timestamp] || Time.now.utc.iso8601(3)
57
- payload = {
58
- timestamp: timestamp,
59
- environment: @environment,
60
- distinct_id: user_id,
61
- traits: traits
62
- }
63
- payload[:anonymous_id] = options[:anonymous_id] if options.key?(:anonymous_id)
64
- payload[:device_id] = options[:device_id] if options.key?(:device_id)
65
-
66
- post("/identify", payload)
47
+ case user_id
48
+ when Array
49
+ payloads = map_batch(user_id, "identifies") { |item| identify_payload_from_item(merge_payload(item, options)) }
50
+ post("/identify", payloads)
51
+ when Hash
52
+ post("/identify", identify_payload_from_item(merge_payload(user_id, options)))
53
+ else
54
+ post("/identify", identify_payload(user_id, options))
55
+ end
67
56
  end
68
57
 
69
- def alias(distinct_id, new_user_id, **options)
70
- timestamp = options[:timestamp] || Time.now.utc.iso8601(3)
71
- payload = {
72
- timestamp: timestamp,
73
- environment: @environment,
74
- distinct_id: distinct_id,
75
- new_user_id: new_user_id
76
- }
77
-
78
- post("/alias", payload)
58
+ def alias(distinct_id, new_user_id = nil, **options)
59
+ case distinct_id
60
+ when Array
61
+ payloads = map_batch(distinct_id, "aliases") { |item| alias_payload_from_item(merge_payload(item, options)) }
62
+ post("/alias", payloads)
63
+ when Hash
64
+ post("/alias", alias_payload_from_item(merge_payload(distinct_id, options)))
65
+ else
66
+ post("/alias", alias_payload(distinct_id, new_user_id, options))
67
+ end
79
68
  end
80
69
 
81
70
  private
@@ -107,6 +96,108 @@ module Altertable
107
96
  false
108
97
  end
109
98
 
99
+ def map_batch(items, name, &block)
100
+ raise ArgumentError, "#{name} must be a non-empty Array" unless items.is_a?(Array) && !items.empty?
101
+
102
+ items.each_with_index do |item, index|
103
+ raise ArgumentError, "#{name}[#{index}] must be a Hash" unless item.is_a?(Hash)
104
+ end
105
+
106
+ items.map(&block)
107
+ end
108
+
109
+ def merge_payload(item, options)
110
+ return item if options.empty?
111
+
112
+ item.merge(options)
113
+ end
114
+
115
+ def item_value(item, key)
116
+ if item.key?(key)
117
+ item[key]
118
+ elsif item.key?(key.to_s)
119
+ item[key.to_s]
120
+ end
121
+ end
122
+
123
+ def item_options(item, *keys)
124
+ keys.each_with_object({}) do |key, opts|
125
+ opts[key] = item_value(item, key) if item.key?(key) || item.key?(key.to_s)
126
+ end
127
+ end
128
+
129
+ def blank?(value)
130
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
131
+ end
132
+
133
+ def default_timestamp
134
+ Time.now.utc.iso8601(3)
135
+ end
136
+
137
+ def track_payload_from_item(item)
138
+ event = item_value(item, :event)
139
+ distinct_id = item_value(item, :distinct_id)
140
+ raise ArgumentError, "event is required" if blank?(event)
141
+ raise ArgumentError, "distinct_id is required" if blank?(distinct_id)
142
+
143
+ track_payload(event, distinct_id, item_options(item, :properties, :anonymous_id, :device_id, :timestamp))
144
+ end
145
+
146
+ def identify_payload_from_item(item)
147
+ user_id = item_value(item, :user_id)
148
+ raise ArgumentError, "user_id is required" if blank?(user_id)
149
+
150
+ identify_payload(user_id, item_options(item, :traits, :anonymous_id, :device_id, :timestamp))
151
+ end
152
+
153
+ def alias_payload_from_item(item)
154
+ distinct_id = item_value(item, :distinct_id)
155
+ new_user_id = item_value(item, :new_user_id)
156
+ raise ArgumentError, "distinct_id is required" if blank?(distinct_id)
157
+ raise ArgumentError, "new_user_id is required" if blank?(new_user_id)
158
+
159
+ alias_payload(distinct_id, new_user_id, item_options(item, :timestamp))
160
+ end
161
+
162
+ def track_payload(event, distinct_id, options)
163
+ properties = options[:properties] || {}
164
+ payload = {
165
+ timestamp: options[:timestamp] || default_timestamp,
166
+ event: event,
167
+ environment: @environment,
168
+ distinct_id: distinct_id,
169
+ properties: {
170
+ '$lib': "altertable-ruby",
171
+ '$lib_version': Altertable::VERSION
172
+ }.merge(properties)
173
+ }
174
+ payload[:properties]["$release"] = @release if @release
175
+ payload[:anonymous_id] = options[:anonymous_id] if options.key?(:anonymous_id)
176
+ payload[:device_id] = options[:device_id] if options.key?(:device_id)
177
+ payload
178
+ end
179
+
180
+ def identify_payload(user_id, options)
181
+ payload = {
182
+ timestamp: options[:timestamp] || default_timestamp,
183
+ environment: @environment,
184
+ distinct_id: user_id,
185
+ traits: options[:traits] || {}
186
+ }
187
+ payload[:anonymous_id] = options[:anonymous_id] if options.key?(:anonymous_id)
188
+ payload[:device_id] = options[:device_id] if options.key?(:device_id)
189
+ payload
190
+ end
191
+
192
+ def alias_payload(distinct_id, new_user_id, options)
193
+ {
194
+ timestamp: options[:timestamp] || default_timestamp,
195
+ environment: @environment,
196
+ distinct_id: distinct_id,
197
+ new_user_id: new_user_id
198
+ }
199
+ end
200
+
110
201
  def post(path, payload)
111
202
  res = @adapter.post(path, body: payload.to_json)
112
203
  handle_response(res)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Altertable
4
- VERSION = "1.1.2"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/altertable.rb CHANGED
@@ -10,7 +10,7 @@ module Altertable
10
10
  @client = Client.new(api_key, options)
11
11
  end
12
12
 
13
- def track(event, distinct_id, **options)
13
+ def track(event, distinct_id = nil, **options)
14
14
  client.track(event, distinct_id, **options)
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module Altertable
18
18
  client.identify(user_id, **options)
19
19
  end
20
20
 
21
- def alias(distinct_id, new_user_id, **options)
21
+ def alias(distinct_id, new_user_id = nil, **options)
22
22
  client.alias(distinct_id, new_user_id, **options)
23
23
  end
24
24
 
data/rbi/altertable.rbi CHANGED
@@ -34,14 +34,14 @@ module Altertable
34
34
  sig { params(api_key: String, options: T::Hash[Symbol, T.untyped]).void }
35
35
  def initialize(api_key, options = {}); end
36
36
 
37
- sig { params(event: String, distinct_id: String, options: T.untyped).returns(T.untyped) }
38
- def track(event, distinct_id, **options); end
37
+ sig { params(event: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), distinct_id: T.nilable(String), options: T.untyped).returns(T.untyped) }
38
+ def track(event, distinct_id = nil, **options); end
39
39
 
40
- sig { params(user_id: String, options: T.untyped).returns(T.untyped) }
40
+ sig { params(user_id: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), options: T.untyped).returns(T.untyped) }
41
41
  def identify(user_id, **options); end
42
42
 
43
- sig { params(distinct_id: String, new_user_id: String, options: T.untyped).returns(T.untyped) }
44
- def alias(distinct_id, new_user_id, **options); end
43
+ sig { params(distinct_id: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), new_user_id: T.nilable(String), options: T.untyped).returns(T.untyped) }
44
+ def alias(distinct_id, new_user_id = nil, **options); end
45
45
 
46
46
  private
47
47
 
@@ -51,7 +51,7 @@ module Altertable
51
51
  sig { params(gem_name: String).returns(T::Boolean) }
52
52
  def try_require(gem_name); end
53
53
 
54
- sig { params(path: String, payload: T::Hash[T.any(Symbol, String), T.untyped]).returns(T.untyped) }
54
+ sig { params(path: String, payload: T.any(T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]])).returns(T.untyped) }
55
55
  def post(path, payload); end
56
56
 
57
57
  sig { params(res: T.untyped).returns(T.untyped) }
@@ -82,8 +82,8 @@ module Altertable
82
82
  end
83
83
 
84
84
  class FaradayAdapter < Base
85
- sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String])).void }
86
- def initialize(base_url:, timeout:, headers: nil); end
85
+ sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String]), proxy: T.nilable(T.any(String, T::Boolean))).void }
86
+ def initialize(base_url:, timeout:, headers: nil, proxy: nil); end
87
87
 
88
88
  sig { params(path: String, body: T.nilable(String), params: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]), block: T.nilable(T.proc.params(arg0: T.untyped).void)).returns(Altertable::Adapters::Response) }
89
89
  def post(path, body: nil, params: nil, &block); end
@@ -95,8 +95,8 @@ module Altertable
95
95
  end
96
96
 
97
97
  class HttpxAdapter < Base
98
- sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String])).void }
99
- def initialize(base_url:, timeout:, headers: nil); end
98
+ sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String]), proxy: T.nilable(T.any(String, T::Boolean))).void }
99
+ def initialize(base_url:, timeout:, headers: nil, proxy: nil); end
100
100
 
101
101
  sig { params(path: String, body: T.nilable(String), params: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]), block: T.nilable(T.proc.params(arg0: T.untyped).void)).returns(Altertable::Adapters::Response) }
102
102
  def post(path, body: nil, params: nil, &block); end
@@ -108,25 +108,30 @@ module Altertable
108
108
  end
109
109
 
110
110
  class NetHttpAdapter < Base
111
- sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String])).void }
112
- def initialize(base_url:, timeout:, headers: nil); end
111
+ sig { params(base_url: String, timeout: T.any(Integer, Float), headers: T.nilable(T::Hash[String, String]), proxy: T.nilable(T.any(String, T::Boolean))).void }
112
+ def initialize(base_url:, timeout:, headers: nil, proxy: nil); end
113
113
 
114
114
  sig { params(path: String, body: T.nilable(String), params: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]), block: T.nilable(T.proc.params(arg0: T.untyped).void)).returns(Altertable::Adapters::Response) }
115
115
  def post(path, body: nil, params: nil, &block); end
116
+
117
+ private
118
+
119
+ sig { returns(T::Array[T.untyped]) }
120
+ def proxy_start_args; end
116
121
  end
117
122
  end
118
123
 
119
124
  sig { params(api_key: String, options: T::Hash[Symbol, T.untyped]).returns(Client) }
120
125
  def self.init(api_key, options = {}); end
121
126
 
122
- sig { params(event: String, distinct_id: String, options: T.untyped).returns(T.untyped) }
123
- def self.track(event, distinct_id, **options); end
127
+ sig { params(event: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), distinct_id: T.nilable(String), options: T.untyped).returns(T.untyped) }
128
+ def self.track(event, distinct_id = nil, **options); end
124
129
 
125
- sig { params(user_id: String, options: T.untyped).returns(T.untyped) }
130
+ sig { params(user_id: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), options: T.untyped).returns(T.untyped) }
126
131
  def self.identify(user_id, **options); end
127
132
 
128
- sig { params(distinct_id: String, new_user_id: String, options: T.untyped).returns(T.untyped) }
129
- def self.alias(distinct_id, new_user_id, **options); end
133
+ sig { params(distinct_id: T.any(String, T::Hash[T.any(Symbol, String), T.untyped], T::Array[T::Hash[T.any(Symbol, String), T.untyped]]), new_user_id: T.nilable(String), options: T.untyped).returns(T.untyped) }
134
+ def self.alias(distinct_id, new_user_id = nil, **options); end
130
135
 
131
136
  sig { returns(Client) }
132
137
  def self.client; end
@@ -19,7 +19,7 @@ module Altertable
19
19
  class FaradayAdapter < Base
20
20
  @conn: untyped
21
21
 
22
- def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String]) -> void
22
+ def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String], ?proxy: (String | bool)?) -> void
23
23
  def post: (String path, ?body: String?, ?params: ::Hash[Symbol | String, untyped]) -> Response
24
24
 
25
25
  private
@@ -30,7 +30,7 @@ module Altertable
30
30
  class HttpxAdapter < Base
31
31
  @client: untyped
32
32
 
33
- def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String]) -> void
33
+ def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String], ?proxy: (String | bool)?) -> void
34
34
  def post: (String path, ?body: String?, ?params: ::Hash[Symbol | String, untyped]) -> Response
35
35
 
36
36
  private
@@ -40,9 +40,14 @@ module Altertable
40
40
 
41
41
  class NetHttpAdapter < Base
42
42
  @uri: URI::HTTP | URI::HTTPS
43
+ @proxy: (String | bool)?
43
44
 
44
- def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String]) -> void
45
+ def initialize: (base_url: String, timeout: Integer | Float, ?headers: ::Hash[String, String], ?proxy: (String | bool)?) -> void
45
46
  def post: (String path, ?body: String?, ?params: ::Hash[Symbol | String, untyped]) -> Response
47
+
48
+ private
49
+
50
+ def proxy_start_args: () -> ::Array[untyped]
46
51
  end
47
52
  end
48
53
  end
@@ -16,16 +16,22 @@ module Altertable
16
16
  def initialize: (String api_key, ?::Hash[Symbol, untyped] options) -> void
17
17
 
18
18
  def track: (String event, String distinct_id, **untyped options) -> untyped
19
+ | (::Hash[Symbol | String, untyped] event_payload, **untyped options) -> untyped
20
+ | (::Array[::Hash[Symbol | String, untyped]] event_payloads, **untyped options) -> untyped
19
21
 
20
22
  def identify: (String user_id, **untyped options) -> untyped
23
+ | (::Hash[Symbol | String, untyped] identify_payload, **untyped options) -> untyped
24
+ | (::Array[::Hash[Symbol | String, untyped]] identify_payloads, **untyped options) -> untyped
21
25
 
22
26
  def alias: (String distinct_id, String new_user_id, **untyped options) -> untyped
27
+ | (::Hash[Symbol | String, untyped] alias_payload, **untyped options) -> untyped
28
+ | (::Array[::Hash[Symbol | String, untyped]] alias_payloads, **untyped options) -> untyped
23
29
 
24
30
  private
25
31
 
26
32
  def select_adapter: (Symbol? name, ::Hash[Symbol, untyped] options) -> untyped
27
33
  def try_require: (String gem_name) -> bool
28
- def post: (String path, ::Hash[Symbol | String, untyped] payload) -> untyped
34
+ def post: (String path, ::Hash[Symbol | String, untyped] | ::Array[::Hash[Symbol | String, untyped]] payload) -> untyped
29
35
  def handle_response: (untyped res) -> untyped
30
36
  def handle_error: (Exception error) -> untyped
31
37
  end
data/sig/altertable.rbs CHANGED
@@ -4,10 +4,16 @@ module Altertable
4
4
  def self.init: (String api_key, ?::Hash[Symbol, untyped] options) -> Client
5
5
 
6
6
  def self.track: (String event, String distinct_id, **untyped options) -> untyped
7
+ | (::Hash[Symbol | String, untyped] event_payload, **untyped options) -> untyped
8
+ | (::Array[::Hash[Symbol | String, untyped]] event_payloads, **untyped options) -> untyped
7
9
 
8
10
  def self.identify: (String user_id, **untyped options) -> untyped
11
+ | (::Hash[Symbol | String, untyped] identify_payload, **untyped options) -> untyped
12
+ | (::Array[::Hash[Symbol | String, untyped]] identify_payloads, **untyped options) -> untyped
9
13
 
10
14
  def self.alias: (String distinct_id, String new_user_id, **untyped options) -> untyped
15
+ | (::Hash[Symbol | String, untyped] alias_payload, **untyped options) -> untyped
16
+ | (::Array[::Hash[Symbol | String, untyped]] alias_payloads, **untyped options) -> untyped
11
17
 
12
18
  def self.client: () -> Client
13
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: altertable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Altertable
@@ -170,8 +170,10 @@ executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
+ - ".github/FUNDING.yml"
173
174
  - ".github/ISSUE_TEMPLATE/bug_report.yml"
174
175
  - ".github/ISSUE_TEMPLATE/feature_request.yml"
176
+ - ".github/PULL_REQUEST_TEMPLATE.md"
175
177
  - ".github/workflows/ci.yml"
176
178
  - ".github/workflows/release-please.yml"
177
179
  - ".github/workflows/semantic-pull-request.yml"