Class: Vangrail::ScoreProviders::Endpoint

Inherits:
Transport
  • Object
show all
Defined in:
lib/vangrail/score_provider.rb

Overview

JSON endpoint transport using a caller-configured stdlib HTTP client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http:, path: '/score', **options) ⇒ Endpoint

Returns a new instance of Endpoint.

Raises:

  • (ArgumentError)


247
248
249
250
251
252
253
254
# File 'lib/vangrail/score_provider.rb', line 247

def initialize(http:, path: '/score', **options)
  super(**options)
  raise ArgumentError, 'http must respond to post_json' unless http.respond_to?(:post_json)

  @http = http
  @path = path.to_s.freeze
  raise ArgumentError, 'path is required' if @path.empty?
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



245
246
247
# File 'lib/vangrail/score_provider.rb', line 245

def http
  @http
end

#pathObject (readonly)

Returns the value of attribute path.



245
246
247
# File 'lib/vangrail/score_provider.rb', line 245

def path
  @path
end

Instance Method Details

#score(text, side:, **context) ⇒ Object



256
257
258
259
# File 'lib/vangrail/score_provider.rb', line 256

def score(text, side:, **context)
  payload, = request_payload(text, side, context)
  response_payload(http.post_json(path, payload))
end