trustid_sdk 0.2.0 → 0.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: 301c57a0d10d984e3596a83163bac369d92daee4cc785a90553c0f6d958f3be7
4
- data.tar.gz: 87e4f7fa237313d37ecc7b640239bebfe9353355e4e3f7e5cd338364637baf07
3
+ metadata.gz: 1784174ed6fda6a0941467202249c83025bb1f33b1eb1da298f310987c21b3ea
4
+ data.tar.gz: bcbfaec98385fba2cac95392d1f8c1df26e92de4fac3e41d52bc6434ab8de037
5
5
  SHA512:
6
- metadata.gz: '09df2387ca97b8753e74c36fe72fddd3cb929bd1e02114e89151cb278e68471157e03d506d72c7ec4b23329c9446f2045f84117067ee5c7f81f6c6de7b22de4b'
7
- data.tar.gz: c493a5aea56b14f9d85dfd30b6f11e8026bc82f976e524824977263e42da19fc738e224fb1dd92ee352b9ba825f95a7fa9e2245ded1e003041a2895c2982285e
6
+ metadata.gz: 65d30c498e8f91a5a98fdee954360d23ff5d30344cef36e22483e454e8b5be7ee7e073be74cd3a6ea638e8744934a0353d7aab68431ce9ece28c5c3990e89e99
7
+ data.tar.gz: 22395cea2bbb3864c402979af7bc33d80fdaf05845c8f7e193ad59417a0d71eee61abc6a67fa816aad32b37112d589eb9b2d0046dc73b7ae4f151c0981d52a18
data/README.md CHANGED
@@ -35,9 +35,11 @@ end
35
35
 
36
36
  ### Device ID
37
37
 
38
- `device_id` can be a string or a proc (or any object that responds to `call`). When it is a proc, it is invoked each time the SDK needs the device ID (e.g. for requests and reports), and the returned value is used.
38
+ `device_id` can be a string or a proc (or any object that responds to `call`). When it is a proc, it is invoked **once when the client is created** (at login), and that value is used for the lifetime of the client. The device ID is then static for all requests made with that client.
39
39
 
40
- This is particularly useful for **parallel usage**: if you run multiple clients or workers, each needs a distinct device ID and session. If you reuse the same device ID, the next login for that device invalidates the previous session. Setting `device_id` to a proc that returns a new value per client (e.g. `-> { "prefix-#{SecureRandom.uuid}" }`) ensures each logical “device” gets a unique ID and its own session.
40
+ This is particularly useful for **parallel usage**: if you run multiple clients or workers, each needs a distinct device ID and session. If you reuse the same device ID, the next login for that device invalidates the previous session. Setting `device_id` to a proc that returns a new value per client (e.g. `-> { "prefix-#{SecureRandom.uuid}" }`) ensures each client gets a unique ID and its own session, while keeping the same device ID for every request within that process.
41
+
42
+ The SDK stores the current `TrustID::Client` on **`TrustID.client`**, which is **thread-local**. Each Ruby thread has its own client slot, so multi-threaded servers can run separate TrustID sessions in parallel without cross-thread session mix-ups.
41
43
 
42
44
  ```ruby
43
45
  require 'securerandom'
@@ -2,20 +2,16 @@
2
2
 
3
3
  module TrustID
4
4
  class Client
5
- attr_reader :server_url
5
+ attr_reader :device_id, :server_url
6
6
  attr_accessor :session_id
7
7
 
8
8
  def initialize
9
9
  config = TrustID.config
10
- @device_id = config.device_id
10
+ raw = config.device_id
11
+ @device_id = raw.respond_to?(:call) ? raw.call : raw
11
12
  @server_url = config.server_url
12
13
  TrustID.client = self
13
14
  Services::Authentication.new(config.username, config.password).login
14
15
  end
15
-
16
- def device_id
17
- value = @device_id
18
- value.respond_to?(:call) ? value.call : value
19
- end
20
16
  end
21
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrustID
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/trustid_sdk.rb CHANGED
@@ -17,7 +17,19 @@ Dir[File.join(__dir__, 'trustid_sdk/models/**/*.rb')].each { |f| require_relativ
17
17
  Dir[File.join(__dir__, 'trustid_sdk/services/**/*.rb')].each { |f| require_relative f.sub("#{__dir__}/", '') }
18
18
 
19
19
  module TrustID
20
+ # Isolates the active client per Ruby thread so concurrent TrustID::Client instances
21
+ # (e.g. Puma / Sidekiq threads) do not overwrite each other's session and device pair.
22
+ CLIENT_THREAD_KEY = :trustid_sdk_client
23
+
20
24
  class << self
21
- attr_accessor :client, :debug_mode
25
+ attr_accessor :debug_mode
26
+
27
+ def client
28
+ Thread.current[CLIENT_THREAD_KEY]
29
+ end
30
+
31
+ def client=(instance)
32
+ Thread.current[CLIENT_THREAD_KEY] = instance
33
+ end
22
34
  end
23
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trustid_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomislav Simnett