Class: InplayAi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/inplay_ai.rb

Constant Summary collapse

DEFAULT_API_URL =
"https://api.inplay.ai"
RETRYABLE_ERRORS =

A reused keep-alive connection can be closed by the API or load balancer between requests; the next request then fails on a stale socket. These are safe to reconnect and retry once because every endpoint is an idempotent upsert.

[ HTTP::ConnectionError, EOFError, Errno::ECONNRESET, Errno::EPIPE ].freeze
MAX_ATTEMPTS =
2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, api_url: nil, connect_timeout: 2, write_timeout: 5, read_timeout: 5) ⇒ Client

Returns a new instance of Client.

Raises:



20
21
22
23
24
25
26
27
28
29
# File 'lib/inplay_ai.rb', line 20

def initialize(api_key: nil, api_url: nil, connect_timeout: 2, write_timeout: 5, read_timeout: 5)
  @api_key = api_key || ENV["INPLAY_API_KEY"]
  raise Error, "API key must be provided via api_key or INPLAY_API_KEY environment variable" unless @api_key
  raw_url = api_url || ENV["INPLAY_API_URL"]
  @api_url = (raw_url ? raw_url.sub(/\/$/, "") : DEFAULT_API_URL)
  @connect_timeout = connect_timeout
  @write_timeout = write_timeout
  @read_timeout = read_timeout
  @http = build_connection
end

Class Method Details

.instanceObject

Thread-safe per-thread singleton instance



67
68
69
# File 'lib/inplay_ai.rb', line 67

def self.instance
  Thread.current[:inplay_ai_client] ||= new
end

Instance Method Details

#event(data) ⇒ Object



58
59
60
# File 'lib/inplay_ai.rb', line 58

def event(data)
  post("/v1/metadata/event", data)
end

#market(data) ⇒ Object

DEPRECATED: Use markets() instead.



49
50
51
52
# File 'lib/inplay_ai.rb', line 49

def market(data)
  warn "market() is deprecated. Use markets() with an array instead."
  post("/v1/metadata/markets", [data])
end

#markets(data) ⇒ Object

Create or update multiple markets in batch.



44
45
46
# File 'lib/inplay_ai.rb', line 44

def markets(data)
  post("/v1/metadata/markets", data)
end

#screen(data) ⇒ Object



62
63
64
# File 'lib/inplay_ai.rb', line 62

def screen(data)
  post("/v1/ai/screen", data)
end

#settlement(data) ⇒ Object



35
36
37
# File 'lib/inplay_ai.rb', line 35

def settlement(data)
  post("/v1/events/settlement", data)
end

#target(data) ⇒ Object



54
55
56
# File 'lib/inplay_ai.rb', line 54

def target(data)
  post("/v1/metadata/target", data)
end

#user(data) ⇒ Object



39
40
41
# File 'lib/inplay_ai.rb', line 39

def user(data)
  post("/v1/metadata/user", data)
end

#wager(data) ⇒ Object



31
32
33
# File 'lib/inplay_ai.rb', line 31

def wager(data)
  post("/v1/events/wager", data)
end