incognia_api 2.2.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: 485a9d5fcf16b98a5ca942d1d4fe47e876f25f60a70193d7bcb70110aebd725a
4
- data.tar.gz: 97a539a4a8a7a7d30ab63e12f6969b34580386fa76e93dee106ffd9a8371f253
3
+ metadata.gz: 8b71c411cba337dac4e3ad7e0f16199ee99bc3ce6dc47858ee4b396a6e75b303
4
+ data.tar.gz: 68abfb412d0db671e1a98542f6179537745fbd395ec4b21b605b109133c91a42
5
5
  SHA512:
6
- metadata.gz: f282bbcc8499cbc2bcae7ad4aaa151dc785a7c1e86e40ebeabe91de440ba51b28d9de06c2e4db9a9870381d3ba6fc6ebbd4e71e9dfdd61c821b085a18fd6cf2e
7
- data.tar.gz: bffdaf58ca5335190f1a7b4a11ad1a2e0254f47a75366a60b54f3e6697b58c79f2ba531e49f0195068c768327e205b06016120b38369da35cbf77db1bbbf763f
6
+ metadata.gz: 2aa64e0525e09a97cca4dab86a0e2156822766884b0dda0905cc98806bc9ab3cfd761c612ecdd681cda460ced463f46694befe18b3fff49d12fc31062b2e3ade
7
+ data.tar.gz: f36e80da9184b5d65f72a2d2e0446fe3d383e6f90f791db041dc6ea56d6c81edcc4fd8009f5f82cd7c8084d1acb3531008cb8b97670448b83a1e6a294be161ae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
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
+
8
+ ## [3.0.0] - 2025-09-22
9
+ - Update `faraday` dependency to version 2.13.4
10
+ - Remove `faraday_middleware` dependency
11
+
3
12
  ## [2.2.0] - 2025-09-16
4
13
 
5
14
  - Add support for passing an optional person_id parameter to HTTP request helpers
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incognia_api (2.2.0)
5
- faraday (~> 1.10)
6
- faraday_middleware (~> 1.2)
4
+ incognia_api (3.1.0)
5
+ faraday (~> 2.13)
6
+ faraday-net_http_persistent (~> 2.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -11,37 +11,27 @@ GEM
11
11
  addressable (2.8.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
13
  coderay (1.1.3)
14
+ connection_pool (3.0.2)
14
15
  crack (0.4.5)
15
16
  rexml
16
17
  diff-lcs (1.4.4)
17
- faraday (1.10.3)
18
- faraday-em_http (~> 1.0)
19
- faraday-em_synchrony (~> 1.0)
20
- faraday-excon (~> 1.1)
21
- faraday-httpclient (~> 1.0)
22
- faraday-multipart (~> 1.0)
23
- faraday-net_http (~> 1.0)
24
- faraday-net_http_persistent (~> 1.0)
25
- faraday-patron (~> 1.0)
26
- faraday-rack (~> 1.0)
27
- faraday-retry (~> 1.0)
28
- ruby2_keywords (>= 0.0.4)
29
- faraday-em_http (1.0.0)
30
- faraday-em_synchrony (1.0.0)
31
- faraday-excon (1.1.0)
32
- faraday-httpclient (1.0.1)
33
- faraday-multipart (1.0.4)
34
- multipart-post (~> 2)
35
- faraday-net_http (1.0.1)
36
- faraday-net_http_persistent (1.2.0)
37
- faraday-patron (1.0.0)
38
- faraday-rack (1.0.0)
39
- faraday-retry (1.0.3)
40
- faraday_middleware (1.2.0)
41
- faraday (~> 1.0)
18
+ faraday (2.14.1)
19
+ faraday-net_http (>= 2.0, < 3.5)
20
+ json
21
+ logger
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)
42
27
  hashdiff (1.0.1)
28
+ json (2.15.2.1)
29
+ logger (1.7.0)
43
30
  method_source (1.0.0)
44
- multipart-post (2.3.0)
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)
45
35
  pry (0.14.2)
46
36
  coderay (~> 1.1)
47
37
  method_source (~> 1.0)
@@ -61,16 +51,17 @@ GEM
61
51
  diff-lcs (>= 1.2.0, < 2.0)
62
52
  rspec-support (~> 3.10.0)
63
53
  rspec-support (3.10.2)
64
- ruby2_keywords (0.0.5)
65
54
  timecop (0.9.4)
55
+ uri (1.1.1)
66
56
  webmock (3.14.0)
67
57
  addressable (>= 2.8.0)
68
58
  crack (>= 0.3.2)
69
59
  hashdiff (>= 0.4.0, < 2.0.0)
70
60
 
71
61
  PLATFORMS
72
- ruby
62
+ arm64-darwin-24
73
63
  x86_64-darwin-20
64
+ x86_64-linux-gnu
74
65
 
75
66
  DEPENDENCIES
76
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/).
@@ -8,7 +8,7 @@ http_interactions:
8
8
  string: ''
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v1.4.2
11
+ - Faraday v2.13.4
12
12
  Authorization:
13
13
  - Basic R1BXSzFMQ1paSW8xRkxPQ0NuTExNcU44UWkxSHYzazQ6RUxHOV8yazU5T0hkMUdiVXhIaGRTdGtqZUI3TXlQZ21vRjhlR2YxM0xBMU1scmZRZ1Q1bkhFMmFIaVNobVc0WA==
14
14
  Content-Type:
@@ -58,7 +58,7 @@ http_interactions:
58
58
  string: '{"installation_id":"xyz"}'
59
59
  headers:
60
60
  User-Agent:
61
- - Faraday v1.4.2
61
+ - Faraday v2.13.4
62
62
  Authorization:
63
63
  - Bearer access_token
64
64
  Content-Type:
data/incognia_api.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Official Ruby lib for communicating with Incognia API"
12
12
  spec.description = "Official Ruby lib for communicating with Incognia API"
13
13
  spec.homepage = "https://github.com/inloco/incognia-ruby"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/inloco/incognia-ruby"
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  # Uncomment to register a new dependency of your gem
30
30
  # spec.add_dependency "example-gem", "~> 1.0"
31
- spec.add_dependency('faraday', '~> 1.10')
32
- spec.add_dependency('faraday_middleware', '~> 1.2')
31
+ spec.add_dependency('faraday', '~> 2.13')
32
+ spec.add_dependency('faraday-net_http_persistent', '~> 2.3')
33
33
 
34
34
  # For more information and examples about making a new gem, checkout our
35
35
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,7 +1,6 @@
1
1
  require "faraday"
2
2
  require "json"
3
3
  require "logger"
4
- require 'faraday_middleware'
5
4
 
6
5
  module Incognia
7
6
  class Api
@@ -1,23 +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] ||= Faraday::Request
18
- .lookup_middleware(:authorization)
19
- .header(:Bearer, credentials.access_token)
20
- 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
21
32
  rescue Faraday::ClientError, Faraday::ServerError => e
22
33
  raise APIError.new(e.to_s, e.response)
23
34
  rescue Faraday::Error => e
@@ -30,6 +41,12 @@ module Incognia
30
41
  @credentials
31
42
  end
32
43
 
44
+ def reset!
45
+ @connection&.close
46
+ @connection = nil
47
+ @credentials = nil
48
+ end
49
+
33
50
  def connection
34
51
  return @connection if @connection
35
52
 
@@ -43,16 +60,23 @@ module Incognia
43
60
  faraday.response :json, content_type: /\bjson$/
44
61
  faraday.response :raise_error
45
62
 
46
- 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
47
72
  end
48
73
  end
49
74
 
50
75
  protected
51
76
 
52
77
  def request_credentials
53
- basic_auth = Faraday::Request
54
- .lookup_middleware(:basic_auth)
55
- .header(Incognia.config.client_id, Incognia.config.client_secret)
78
+ basic_auth = Faraday::Utils
79
+ .basic_header_from(Incognia.config.client_id, Incognia.config.client_secret)
56
80
 
57
81
  response = connection.send(:post, 'v2/token') do |r|
58
82
  r.headers[Faraday::Request::Authorization::KEY] = basic_auth
@@ -76,5 +100,13 @@ module Incognia
76
100
  Credentials.from_hash(properties)
77
101
  end
78
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
+
79
111
  end
80
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 = "2.2.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: 2.2.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-16 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
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.13'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '2.13'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
28
+ name: faraday-net_http_persistent
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: '2.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.2'
40
+ version: '2.3'
41
41
  description: Official Ruby lib for communicating with Incognia API
42
42
  email:
43
43
  - guiocavalcanti@gmail.com
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: 2.4.0
91
+ version: 3.0.0
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="