Class: PlaypathRails::Client
- Inherits:
-
Object
- Object
- PlaypathRails::Client
- Defined in:
- lib/playpath_rails/client.rb
Overview
HTTP client for PlayPath.io API
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#chat(message:, history: []) ⇒ Object
Send a message to the RAG assistant.
-
#create_item(title:, url: nil, text: nil, tags: []) ⇒ Object
Create a new item.
-
#delete_item(id) ⇒ Object
Delete an item.
-
#get_item(id) ⇒ Object
Get a specific item by ID.
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
-
#list_items ⇒ Object
List all items.
-
#update_item(id, title: nil, url: nil, text: nil, tags: nil) ⇒ Object
Update an existing item.
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/playpath_rails/client.rb', line 12 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/playpath_rails/client.rb', line 10 def configuration @configuration end |
Instance Method Details
#chat(message:, history: []) ⇒ Object
Send a message to the RAG assistant
57 58 59 60 61 62 |
# File 'lib/playpath_rails/client.rb', line 57 def chat(message:, history: []) body = { message: } body[:history] = history if history&.any? request(:post, '/api/rag/chat', body: body, endpoint_type: :rag) end |
#create_item(title:, url: nil, text: nil, tags: []) ⇒ Object
Create a new item
29 30 31 32 33 34 35 36 |
# File 'lib/playpath_rails/client.rb', line 29 def create_item(title:, url: nil, text: nil, tags: []) body = { title: title } body[:url] = url if url body[:text] = text if text body[:tags] = if &.any? request(:post, '/api/items', body: body) end |
#delete_item(id) ⇒ Object
Delete an item
50 51 52 |
# File 'lib/playpath_rails/client.rb', line 50 def delete_item(id) request(:delete, "/api/items/#{id}") end |
#get_item(id) ⇒ Object
Get a specific item by ID
24 25 26 |
# File 'lib/playpath_rails/client.rb', line 24 def get_item(id) request(:get, "/api/items/#{id}") end |
#list_items ⇒ Object
List all items
19 20 21 |
# File 'lib/playpath_rails/client.rb', line 19 def list_items request(:get, '/api/items') end |
#update_item(id, title: nil, url: nil, text: nil, tags: nil) ⇒ Object
Update an existing item
39 40 41 42 43 44 45 46 47 |
# File 'lib/playpath_rails/client.rb', line 39 def update_item(id, title: nil, url: nil, text: nil, tags: nil) body = {} body[:title] = title if title body[:url] = url if url body[:text] = text if text body[:tags] = if request(:patch, "/api/items/#{id}", body: body) end |