inplay_ai 0.1.2 → 0.1.4

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: e971e67dd7f067239f057db765d673bd37e4ff015adfe631192492e080c63123
4
- data.tar.gz: f61bed16f6334741835b8857b420f2e72b1a6068bee934e7389b5503debcaa22
3
+ metadata.gz: edf671763a4145a3c948adc274b6fc241e0b0290dd592f6eb48af443823ac837
4
+ data.tar.gz: b355cb0e5e9179ef7e7ea84dc80effec8179e1a8f76e80d67813eaa11b6da2e1
5
5
  SHA512:
6
- metadata.gz: 306ee52155dca1c6c1d39f9a92683a3e2823f32724b276d89fed98ee8292cad5d4e2cfc1b1d413ee311ca7e367b38c36954e5bb6d4a0c2221964cc14507056a4
7
- data.tar.gz: 6936651a57251283b980b1169eee62e429980518962a4f5e39f25f3884cd53d8ca0db67147f7e72fba69deb1bb0be4efd26509fb73bc47a7a0ac223273ac23dd
6
+ metadata.gz: 82920e7bd3cbfd68c5905bb5a0afc0742d7def4d68dadae140e8874a12318cc6b91182ab8248d666b465372c7b5acea764fbcf3d7d2ec8818ce39cf7e5567473
7
+ data.tar.gz: 5bbc86b044613a5d5d5e63e99fecf6e8557fefb2369b8c9ac36a9aca557cbb093af7caad0d0ef951a5ac6cad7b91c83708ea3ee9045e838a795f6cdf40dd7990
data/README.md CHANGED
@@ -21,10 +21,8 @@ gem install inplay_ai
21
21
  ```ruby
22
22
  require 'inplay_ai'
23
23
 
24
- client = InplayAi::Client.new(
25
- api_key: 'your-api-key',
26
- api_url: 'https://api.inplay.ai' # or your API base URL
27
- )
24
+ # Use the singleton client for efficient connection reuse
25
+ client = InplayAi::Client.instance
28
26
 
29
27
  # Send a wager event
30
28
  client.wager({
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InplayAi
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/inplay_ai.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "inplay_ai/version"
4
- require "net/http"
5
- require "uri"
4
+ require "http"
6
5
  require "json"
7
6
 
8
7
  module InplayAi
@@ -16,6 +15,10 @@ module InplayAi
16
15
  raise Error, "API key must be provided via api_key or INPLAY_API_KEY environment variable" unless @api_key
17
16
  raw_url = api_url || ENV["INPLAY_API_URL"]
18
17
  @api_url = (raw_url ? raw_url.sub(/\/$/, "") : DEFAULT_API_URL)
18
+ @http = HTTP.persistent(@api_url).headers(
19
+ "x-api-key" => @api_key,
20
+ "Content-Type" => "application/json"
21
+ )
19
22
  end
20
23
 
21
24
  def wager(data)
@@ -42,26 +45,24 @@ module InplayAi
42
45
  post("/v1/metadata/event", data)
43
46
  end
44
47
 
48
+ # Thread-safe per-thread singleton instance
49
+ def self.instance
50
+ Thread.current[:inplay_ai_client] ||= new
51
+ end
52
+
45
53
  private
46
54
 
47
55
  def post(path, data)
48
- uri = URI.join(@api_url, path)
49
- http = Net::HTTP.new(uri.host, uri.port)
50
- http.use_ssl = uri.scheme == "https"
51
- req = Net::HTTP::Post.new(uri)
52
- req["x-api-key"] = @api_key
53
- req["Content-Type"] = "application/json"
54
- req.body = data.to_json
55
- res = http.request(req)
56
- if res.code.to_i >= 400
56
+ res = @http.post(path, json: data)
57
+ if res.status >= 400
57
58
  begin
58
- err = JSON.parse(res.body)
59
+ err = JSON.parse(res.body.to_s)
59
60
  rescue JSON::ParserError
60
- err = res.body
61
+ err = res.body.to_s
61
62
  end
62
63
  raise Error, err
63
64
  end
64
- JSON.parse(res.body)
65
+ JSON.parse(res.body.to_s)
65
66
  end
66
67
  end
67
68
  end
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inplay_ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - InPlay AI
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 2025-06-24 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: http
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  description: InPlay AI SDK for Ruby
13
27
  email:
14
28
  - team@inplay.ai