Class: Space::Architect::ConversationsClient
- Inherits:
-
Object
- Object
- Space::Architect::ConversationsClient
- Defined in:
- lib/space_architect/conversations_client.rb
Overview
HTTP client for the space-server conversations upload API, modeled on JobsClient: Bearer auth, injectable async-http client. Unlike JobsClient, a non-2xx response is returned to the caller (not raised) — SessionSync needs to distinguish created/updated/failed per file without aborting the whole run on one bad upload.
Instance Method Summary collapse
-
#initialize(host, token, client: nil, op_resolver: nil) ⇒ ConversationsClient
constructor
A new instance of ConversationsClient.
-
#upload(path:, session_id:) ⇒ Object
POST /conversations — multipart per the frozen wire contract: conversation (the file), conversation.
Constructor Details
#initialize(host, token, client: nil, op_resolver: nil) ⇒ ConversationsClient
Returns a new instance of ConversationsClient.
15 16 17 18 19 20 21 |
# File 'lib/space_architect/conversations_client.rb', line 15 def initialize(host, token, client: nil, op_resolver: nil) @host = host.chomp("/") @token = token @client = client @op_resolver = op_resolver || SessionSync.method(:resolve_token) @resolved_token = nil end |
Instance Method Details
#upload(path:, session_id:) ⇒ Object
POST /conversations — multipart per the frozen wire contract: conversation (the file), conversation. Returns conversation_id:, action:, errors:.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/space_architect/conversations_client.rb', line 26 def upload(path:, session_id:) Sync do with_client do |c| boundary = "ArchitectBoundary#{SecureRandom.hex(8)}" body = build_multipart(boundary, path, session_id) response = c.post("/conversations", headers: headers(boundary), body: body) status = response.status parsed = begin JSON.parse(response.read || "{}") rescue JSON::ParserError {} end {status: status, conversation_id: parsed["conversation_id"], action: parsed["action"], errors: parsed["errors"]} end end end |