Class: Vangrail::ScoreProviders::Endpoint
- Defined in:
- lib/vangrail/score_provider.rb
Overview
JSON endpoint transport using a caller-configured stdlib HTTP client.
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(http:, path: '/score', **options) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #score(text, side:, **context) ⇒ Object
Constructor Details
#initialize(http:, path: '/score', **options) ⇒ Endpoint
Returns a new instance of Endpoint.
247 248 249 250 251 252 253 254 |
# File 'lib/vangrail/score_provider.rb', line 247 def initialize(http:, path: '/score', **) super(**) 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
#http ⇒ Object (readonly)
Returns the value of attribute http.
245 246 247 |
# File 'lib/vangrail/score_provider.rb', line 245 def http @http end |
#path ⇒ Object (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 |