incognia_api 3.0.0 → 3.1.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: 823c5ab4bca2a8fd1d856482906971073d95a1f55e378c6d812da69d205f689e
4
- data.tar.gz: 26e4f368b891e14cab04a69b1de02342bf48e2b5f0eea474a1947bf5103fd773
3
+ metadata.gz: 8b71c411cba337dac4e3ad7e0f16199ee99bc3ce6dc47858ee4b396a6e75b303
4
+ data.tar.gz: 68abfb412d0db671e1a98542f6179537745fbd395ec4b21b605b109133c91a42
5
5
  SHA512:
6
- metadata.gz: 3e34fe28af027501b6e4f907d4c9973c930fc86b2ce3ae565fce72979c3a55098a0c3700b91f62d00d7c8ab2d350440e89caf11b0a716c053d6e5f7f89ca2731
7
- data.tar.gz: 07ece7a29b0fe8dcb88b1e7df6817d83ab13c42c751bdcb83877912df9f4c94c54d401368c549e0f4cce3e28ffcdfb19a28df5abb27823d9f012ecd6a0f8ec2b
6
+ metadata.gz: 2aa64e0525e09a97cca4dab86a0e2156822766884b0dda0905cc98806bc9ab3cfd761c612ecdd681cda460ced463f46694befe18b3fff49d12fc31062b2e3ade
7
+ data.tar.gz: f36e80da9184b5d65f72a2d2e0446fe3d383e6f90f791db041dc6ea56d6c81edcc4fd8009f5f82cd7c8084d1acb3531008cb8b97670448b83a1e6a294be161ae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [3.1.0] - 2026-04-17
4
+ - Add optional `keep_alive` support with configurable `max_connections` for persistent HTTP connections.
5
+ - Add `X-Incognia-Latency` support by sending the previous successful request latency on subsequent API calls.
6
+ - Refresh locked dependencies, including `faraday` 2.14.1 and `json` 2.15.2.1.
7
+
3
8
  ## [3.0.0] - 2025-09-22
4
9
  - Update `faraday` dependency to version 2.13.4
5
10
  - Remove `faraday_middleware` dependency
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incognia_api (3.0.0)
4
+ incognia_api (3.1.0)
5
5
  faraday (~> 2.13)
6
+ faraday-net_http_persistent (~> 2.3)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -10,21 +11,27 @@ GEM
10
11
  addressable (2.8.0)
11
12
  public_suffix (>= 2.0.2, < 5.0)
12
13
  coderay (1.1.3)
14
+ connection_pool (3.0.2)
13
15
  crack (0.4.5)
14
16
  rexml
15
17
  diff-lcs (1.4.4)
16
- faraday (2.13.4)
18
+ faraday (2.14.1)
17
19
  faraday-net_http (>= 2.0, < 3.5)
18
20
  json
19
21
  logger
20
- faraday-net_http (3.4.1)
21
- net-http (>= 0.5.0)
22
+ faraday-net_http (3.4.2)
23
+ net-http (~> 0.5)
24
+ faraday-net_http_persistent (2.3.1)
25
+ faraday (~> 2.5)
26
+ net-http-persistent (>= 4.0.4, < 5)
22
27
  hashdiff (1.0.1)
23
- json (2.14.0)
28
+ json (2.15.2.1)
24
29
  logger (1.7.0)
25
30
  method_source (1.0.0)
26
- net-http (0.6.0)
27
- uri
31
+ net-http (0.9.1)
32
+ uri (>= 0.11.1)
33
+ net-http-persistent (4.0.8)
34
+ connection_pool (>= 2.2.4, < 4)
28
35
  pry (0.14.2)
29
36
  coderay (~> 1.1)
30
37
  method_source (~> 1.0)
@@ -45,15 +52,16 @@ GEM
45
52
  rspec-support (~> 3.10.0)
46
53
  rspec-support (3.10.2)
47
54
  timecop (0.9.4)
48
- uri (1.0.3)
55
+ uri (1.1.1)
49
56
  webmock (3.14.0)
50
57
  addressable (>= 2.8.0)
51
58
  crack (>= 0.3.2)
52
59
  hashdiff (>= 0.4.0, < 2.0.0)
53
60
 
54
61
  PLATFORMS
55
- ruby
62
+ arm64-darwin-24
56
63
  x86_64-darwin-20
64
+ x86_64-linux-gnu
57
65
 
58
66
  DEPENDENCIES
59
67
  incognia_api!
data/README.md CHANGED
@@ -39,9 +39,23 @@ Before using the API client, you must configure it using credentials obtained
39
39
  from the [Incognia dashboard](https://dash.incognia.com/):
40
40
 
41
41
  ```ruby
42
- Incognia.configure(client_id: ENV['INCOGNIA_CLIENT_ID'], client_secret: ENV['INCOGNIA_CLIENT_SECRET'])
42
+ Incognia.configure(
43
+ client_id: ENV['INCOGNIA_CLIENT_ID'],
44
+ client_secret: ENV['INCOGNIA_CLIENT_SECRET']
45
+ )
46
+ ```
47
+
48
+ To reuse HTTP connections between requests, enable `keep_alive`. When enabled,
49
+ `max_connections` sets the maximum number of concurrent persistent
50
+ connections used by the client.
43
51
 
44
- # Incognia.configure(client_id: "your-client-id", client_secret: "your-client-secret")
52
+ ```ruby
53
+ Incognia.configure(
54
+ client_id: ENV['INCOGNIA_CLIENT_ID'],
55
+ client_secret: ENV['INCOGNIA_CLIENT_SECRET'],
56
+ keep_alive: true,
57
+ max_connections: 5
58
+ )
45
59
  ```
46
60
 
47
61
  For sandbox credentials, refer to the [API testing guide](https://developer.incognia.com/).
data/incognia_api.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  # Uncomment to register a new dependency of your gem
30
30
  # spec.add_dependency "example-gem", "~> 1.0"
31
31
  spec.add_dependency('faraday', '~> 2.13')
32
+ spec.add_dependency('faraday-net_http_persistent', '~> 2.3')
32
33
 
33
34
  # For more information and examples about making a new gem, checkout our
34
35
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,21 +1,34 @@
1
1
  require "time"
2
2
  require "singleton"
3
+ require "faraday/net_http_persistent"
3
4
 
4
5
  module Incognia
5
6
  class Client
6
7
  include Singleton
8
+ LATENCY_HEADER = "X-Incognia-Latency".freeze
9
+
7
10
  # TODO:
8
11
  # (ok) http/adapter specific code
9
12
  # (ok) raises network/authentication errors
10
13
  # (ok) handles token refreshing ok
11
14
  # future: handles retrying
12
15
 
16
+ def initialize
17
+ @last_latency_ms = nil
18
+ @last_latency_mutex = Mutex.new
19
+ end
20
+
13
21
  def request(method, endpoint = nil, data = nil, headers = {})
14
22
  json_data = JSON.generate(data) if data
23
+ request_headers = Faraday::Utils::Headers.new.update(headers)
24
+ request_headers[Faraday::Request::Authorization::KEY] ||= "Bearer #{credentials.access_token}"
25
+ request_headers[LATENCY_HEADER] = last_latency_ms&.to_s
15
26
 
16
- connection.send(method, endpoint, json_data, headers) do |r|
17
- r.headers[Faraday::Request::Authorization::KEY] ||= "Bearer #{credentials.access_token}"
18
- end
27
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
28
+ response = connection.send(method, endpoint, json_data, request_headers.compact)
29
+ store_last_latency(Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - start) if response.success?
30
+
31
+ response
19
32
  rescue Faraday::ClientError, Faraday::ServerError => e
20
33
  raise APIError.new(e.to_s, e.response)
21
34
  rescue Faraday::Error => e
@@ -28,6 +41,12 @@ module Incognia
28
41
  @credentials
29
42
  end
30
43
 
44
+ def reset!
45
+ @connection&.close
46
+ @connection = nil
47
+ @credentials = nil
48
+ end
49
+
31
50
  def connection
32
51
  return @connection if @connection
33
52
 
@@ -41,7 +60,15 @@ module Incognia
41
60
  faraday.response :json, content_type: /\bjson$/
42
61
  faraday.response :raise_error
43
62
 
44
- faraday.adapter Faraday.default_adapter
63
+ if Incognia.config.keep_alive
64
+ adapter_options = {
65
+ pool_size: Incognia.config.max_connections
66
+ }.compact
67
+
68
+ faraday.adapter :net_http_persistent, **adapter_options
69
+ else
70
+ faraday.adapter Faraday.default_adapter
71
+ end
45
72
  end
46
73
  end
47
74
 
@@ -73,5 +100,13 @@ module Incognia
73
100
  Credentials.from_hash(properties)
74
101
  end
75
102
 
103
+ def last_latency_ms
104
+ @last_latency_mutex.synchronize { @last_latency_ms }
105
+ end
106
+
107
+ def store_last_latency(latency_ms)
108
+ @last_latency_mutex.synchronize { @last_latency_ms = latency_ms }
109
+ end
110
+
76
111
  end
77
112
  end
@@ -4,14 +4,27 @@ module Incognia
4
4
  class Configuration
5
5
  include Singleton
6
6
 
7
- attr_accessor :client_id, :client_secret, :host
7
+ attr_accessor :client_id, :client_secret, :host, :keep_alive, :max_connections
8
+
9
+ def configure(client_id:, client_secret:, host: nil, keep_alive: false, max_connections: nil)
10
+ validate_connection_settings!(keep_alive: keep_alive, max_connections: max_connections)
8
11
 
9
- def configure(client_id:, client_secret:, host: nil)
10
12
  @client_id = client_id
11
13
  @client_secret = client_secret
12
14
  @host = host || 'https://api.incognia.com/api'
15
+ @keep_alive = keep_alive
16
+ @max_connections = max_connections
13
17
 
14
18
  self
15
19
  end
20
+
21
+ private
22
+
23
+ def validate_connection_settings!(keep_alive:, max_connections:)
24
+ return if max_connections.nil?
25
+
26
+ raise ArgumentError, 'max_connections requires keep_alive: true' unless keep_alive
27
+ raise ArgumentError, 'max_connections must be a positive Integer' unless max_connections.is_a?(Integer) && max_connections.positive?
28
+ end
16
29
  end
17
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Incognia
4
- VERSION = "3.0.0"
4
+ VERSION = "3.1.0"
5
5
  end
data/lib/incognia_api.rb CHANGED
@@ -19,7 +19,7 @@ require_relative "incognia_api/constants/feedback_event"
19
19
 
20
20
  module Incognia
21
21
  def self.configure(**args)
22
- config.configure(**args)
22
+ config.configure(**args).tap { Client.instance.reset! }
23
23
  end
24
24
 
25
25
  def self.config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incognia_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Cavalcanti
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-22 00:00:00.000000000 Z
11
+ date: 2026-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-net_http_persistent
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
27
41
  description: Official Ruby lib for communicating with Incognia API
28
42
  email:
29
43
  - guiocavalcanti@gmail.com