inplay_ai 0.1.6 → 0.1.7

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: 35c8d35b3b133ad10262cad807444dfd1ed802fe79a8c053f1e40cf3776e9c9d
4
- data.tar.gz: ab4701e0eff0c6d280b0fd274f613db1277a6e4e8d233622823d5b9a7dfaa61b
3
+ metadata.gz: 6c0008d3e99ac765eeba37b2e291e0fd6a1db14e431340e00d3578e58d4a0065
4
+ data.tar.gz: 6b19f870c745c4f6451964163e8b042ba5c625a6735af3dbfc81e6e8b210efa0
5
5
  SHA512:
6
- metadata.gz: b77866a32f808f2a2f2e497d0ee2465820277f4526f03ab9f117a036ed5bfa96571de6b0fddcec3dbac94d2496a57ae9c11a4500c945cb2283a6a2f5446898c1
7
- data.tar.gz: d6a5f93cb788788c4cb510deaba13ac6352c01342e87e9928b815b1da1c5af101e472aa3eff4c1cc860e0beca8e344ea8396e24123dc4365bf7fd56e81115f16
6
+ metadata.gz: fbe0b07fff7cd3ac766dedb80b386e275e0441c92fda403f019029315203762b3c9fee4175e5c6d2f588b8349609fdee7094ac1bc6c924d26e354f17cb26c519
7
+ data.tar.gz: 451d3832b0a5996e0ff0b3b179b3f838fee01f0e78e6484b32ace87ab2b8a97ffadef15447e75aff58b6f2b34e3b32d184a144e8029e4d940e210778f756acb2
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InplayAi
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/inplay_ai.rb CHANGED
@@ -10,15 +10,22 @@ module InplayAi
10
10
  class Client
11
11
  DEFAULT_API_URL = "https://api.inplay.ai"
12
12
 
13
+ # A reused keep-alive connection can be closed by the API or load balancer
14
+ # between requests; the next request then fails on a stale socket. These are
15
+ # safe to reconnect and retry once because every endpoint is an idempotent
16
+ # upsert.
17
+ RETRYABLE_ERRORS = [ HTTP::ConnectionError, EOFError, Errno::ECONNRESET, Errno::EPIPE ].freeze
18
+ MAX_ATTEMPTS = 2
19
+
13
20
  def initialize(api_key: nil, api_url: nil, connect_timeout: 2, write_timeout: 5, read_timeout: 5)
14
21
  @api_key = api_key || ENV["INPLAY_API_KEY"]
15
22
  raise Error, "API key must be provided via api_key or INPLAY_API_KEY environment variable" unless @api_key
16
23
  raw_url = api_url || ENV["INPLAY_API_URL"]
17
24
  @api_url = (raw_url ? raw_url.sub(/\/$/, "") : DEFAULT_API_URL)
18
- @http = HTTP.timeout(connect: connect_timeout, write: write_timeout, read: read_timeout).headers(
19
- "x-api-key" => @api_key,
20
- "Content-Type" => "application/json"
21
- )
25
+ @connect_timeout = connect_timeout
26
+ @write_timeout = write_timeout
27
+ @read_timeout = read_timeout
28
+ @http = build_connection
22
29
  end
23
30
 
24
31
  def wager(data)
@@ -63,17 +70,39 @@ module InplayAi
63
70
 
64
71
  private
65
72
 
73
+ # Persistent (keep-alive) connection bounded by timeouts. Persistence
74
+ # amortizes the TCP+TLS handshake across the high volume of metadata calls;
75
+ # the timeouts ensure a dead socket fails fast instead of hanging forever.
76
+ def build_connection
77
+ HTTP.persistent(@api_url)
78
+ .timeout(connect: @connect_timeout, write: @write_timeout, read: @read_timeout)
79
+ .headers(
80
+ "x-api-key" => @api_key,
81
+ "Content-Type" => "application/json"
82
+ )
83
+ end
84
+
66
85
  def post(path, data)
67
- res = @http.post("#{@api_url}#{path}", json: data)
68
- if res.status >= 400
69
- begin
70
- err = JSON.parse(res.body.to_s)
71
- rescue JSON::ParserError
72
- err = res.body.to_s
86
+ attempts = 0
87
+ begin
88
+ attempts += 1
89
+ res = @http.post("#{@api_url}#{path}", json: data)
90
+ if res.status >= 400
91
+ begin
92
+ err = JSON.parse(res.body.to_s)
93
+ rescue JSON::ParserError
94
+ err = res.body.to_s
95
+ end
96
+ raise Error, err
73
97
  end
74
- raise Error, err
98
+ JSON.parse(res.body.to_s)
99
+ rescue *RETRYABLE_ERRORS
100
+ # Stale keep-alive socket: discard the connection and retry once.
101
+ raise if attempts >= MAX_ATTEMPTS
102
+
103
+ @http = build_connection
104
+ retry
75
105
  end
76
- JSON.parse(res.body.to_s)
77
106
  end
78
107
  end
79
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inplay_ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - InPlay AI
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-03-28 00:00:00.000000000 Z
11
+ date: 2026-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -41,7 +41,7 @@ licenses:
41
41
  metadata:
42
42
  allowed_push_host: https://rubygems.org
43
43
  homepage_uri: https://inplay.ai
44
- post_install_message:
44
+ post_install_message:
45
45
  rdoc_options: []
46
46
  require_paths:
47
47
  - lib
@@ -56,8 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.0.3.1
60
- signing_key:
59
+ rubygems_version: 3.4.19
60
+ signing_key:
61
61
  specification_version: 4
62
62
  summary: InPlay AI SDK for Ruby
63
63
  test_files: []