Class: PlaypathRails::Client

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

Overview

HTTP client for PlayPath.io API

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configurationObject (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: 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] = tags if tags&.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_itemsObject

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] = tags if tags

  request(:patch, "/api/items/#{id}", body: body)
end