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 +4 -4
- data/lib/inplay_ai/version.rb +1 -1
- data/lib/inplay_ai.rb +41 -12
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c0008d3e99ac765eeba37b2e291e0fd6a1db14e431340e00d3578e58d4a0065
|
|
4
|
+
data.tar.gz: 6b19f870c745c4f6451964163e8b042ba5c625a6735af3dbfc81e6e8b210efa0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbe0b07fff7cd3ac766dedb80b386e275e0441c92fda403f019029315203762b3c9fee4175e5c6d2f588b8349609fdee7094ac1bc6c924d26e354f17cb26c519
|
|
7
|
+
data.tar.gz: 451d3832b0a5996e0ff0b3b179b3f838fee01f0e78e6484b32ace87ab2b8a97ffadef15447e75aff58b6f2b34e3b32d184a144e8029e4d940e210778f756acb2
|
data/lib/inplay_ai/version.rb
CHANGED
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
|
-
@
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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.
|
|
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-
|
|
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.
|
|
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: []
|